title: Java 8 peek vs map
body: <p>I have following case: there is a list of objects - ProductData which contains several fields:</p>
  
  <pre><code>public class ProductData
  {
  ....
    private String name;
    private String xref;
  
    //getters
    //setters
  }
  </code></pre>
  
  <p>and there is API which returns list of following objects:</p>
  
  <pre><code>public class RatingTableRow
  {
    private String planName;
    private String planXref;
    private int fromAge;
    private int toAge;
    private int ratingRegion;
  
   //constructor
   //getters
   //setters
  
  }
  </code></pre>
  
  <p>but it returns objects with empty plan name field because it's not allowed during extraction of this object. I need to link product data with RatingTableRow by the xref in order to set plan name into the RatingTableRow because I need to use this object later so I created following code to do that:</p>
  
  <pre><code>Map&lt;String, ProductData&gt; productByXref = plans.stream()
          .collect(toMap(ProductData::getInternalCode, Function.identity()));
  
  return getRatingTableRows(...).stream
          .filter(ratingRow -&gt; productByXref.containsKey(ratingRow.getPlanXref()))
          .peek(row -&gt; {
                  ProductData product = productByXref.get(row.getPlanXref());
                  row.setPlanName(product.getName());
          })....;
  </code></pre>
  
  <p>I know that java docs say that <code>peek</code> doesn't fit these needs but want to get your suggestions on how to make this task in more correct way.</p>