title: java 8 list grouping with value mapping function producing list
body: <p>I have a following <strong>Person</strong> class</p>
  
  <pre><code>public class Person {
  
      public String name;
  
      public List&lt;Brand&gt; brands;
  
      //Getters
  }
  </code></pre>
  
  <p>and a <code>List&lt;Person&gt; persons</code>(possibly with same names). I need to group in a map of <code>&lt;String, List&lt;Brand&gt;&gt;</code> with Person's <code>name</code> as Keys and lists of accumulated <code>Brands</code> as values.</p>
  
  <p>Something like this</p>
  
  <pre><code> Map&lt;String, List&lt;List&lt;String&gt;&gt;&gt; collect = list.stream().collect(
          groupingBy(Person::getName, mapping(Person::getBrands, toList()))
   );
  </code></pre>
  
  <p>produces undesired result and I know why. If the values could be somehow flatten during grouping? Is there a way to do it right there with Streams api?</p>