title: Java stream merge or reduce duplicate objects
body: <p>I need to generate a unique friend list from a list that can have duplicates by merging all duplicate entries into one object<br/> 
  <strong>Example</strong> - Friends are fetched from different social feeds and put into 1 big list<br/>
   1. Friend - [name: "Johnny Depp", dob: "1970-11-10", source: "FB", fbAttribute: ".."]<br/>
   2. Friend - [name: "Christian Bale", dob: "1970-01-01", source: "LI", liAttribute: ".."]<br/>
   3. Friend - [name: "Johnny Depp", dob: "1970-11-10", source: "Twitter", twitterAttribute: ".."]<br/>
   4. Friend - [name: "Johnny Depp", dob: "1970-11-10", source: "LinkedIn", liAttribute: ".."]<br/>
   5. Friend - [name: "Christian Bale", dob: "1970-01-01", source: "LI", liAttribute: ".."]<br/></p>
  
  <p><strong>Expected output</strong><br/>
   1. Friend - [name: "Christian Bale", dob: "1970-01-01", liAttribute: "..", fbAttribute: "..", twitterAttribute: ".."]<br/>
   2. Friend - [name: "Johnny Depp", dob: "1970-11-10", liAttribute: "..", fbAttribute: "..", twitterAttribute: ".."]<br/></p>
  
  <p><strong>Question</strong> - How can i merge without using any intermediate container? I can easily use an intermediate map and apply reduce on each value of the entry.<br/> </p>
  
  <pre><code>List&lt;Friend&gt; friends;
  Map&lt;String, List&lt;Friend&gt;&gt; uniqueFriendMap
      = friends.stream().groupingBy(Friend::uniqueFunction);
  List&lt;Friend&gt; mergedFriends = uniqueFriendMap.entrySet()
      .stream()
      .map(entry -&gt; {
             return entry.getValue()
                  .stream()
                  .reduce((a,b) -&gt; friendMergeFunction(a,b));
      })
      .filter(mergedPlace -&gt; mergedPlace.isPresent())
      .collect(Collectors.toList());
  </code></pre>
  
  <p>I like to do this without using the intermediate Map uniqueFriendMap. Any suggestions?</p>