title: Grouping by and map value
body: <p>I'm trying to do grouping by (to map) and then transform list of values to different list.</p>
  
  <p>I have List of DistrictDocuments:</p>
  
  <pre><code>List&lt;DistrictDocument&gt; docs = new ArrayList&lt;&gt;();
  </code></pre>
  
  <p>Then I'm streaming over it and grouping it by city:</p>
  
  <pre><code>Map&lt;String, List&lt;DistrictDocument&gt;&gt; collect = docs.stream()
                  .collect(Collectors.groupingBy(DistrictDocument::getCity));
  </code></pre>
  
  <p>I also have a method which takes DistrictDocument and creates Slugable out of it:</p>
  
  <pre><code>private Fizz createFizz(DistrictDocument doc) {
      return new Fizz().name(doc.getName()).fizz(doc.getFizz());
  }
  </code></pre>
  
  <p>Is there a way to put that method into my stream above so I get <code>Map&lt;String, List&lt;Fizz&gt;&gt;</code> ?
  I tried adding 2nd argument to groupingBy but couldn't find a proper way and been always getting compilation errors.</p>
  
  <p>Edit:
  What if my createFizz returns <code>List&lt;Fizz&gt;</code> ? Is there an option to flat this list in Collectors.mapping becasue I still want to have <code>Map&lt;String, List&lt;Fizz&gt;&gt;</code> instead of <code>Map&lt;String, List&lt;List&lt;Fizz&gt;&gt;&gt;</code></p>