title: Java - groupingBy with collectingAndThen - Is there a faster / better / cleaner way?
body: <p>I have the following class (with getters):</p>
  
  <pre><code>public class AlgorithmPrediction {
      private final String algorithmName;
      private final Map&lt;BaseDatabaseProduct, Double&gt; productsToAccuracy;
  }
  </code></pre>
  
  <p>Now I want to create a map from a set filled by <code>AlgorithmPrediction</code> objects with the <code>algorithmName</code> <strong>(unique)</strong> as key and <code>productsToAccuracy</code> as value. I couldn't come up with anything less complex than this:</p>
  
  <pre><code>algorithmPredictions.stream()
  .collect(
          groupingBy(
                  AlgorithmPrediction::getAlgorithmName,
                  Collectors.collectingAndThen(
                          toSet(),
                          s -&gt; s.stream().map(AlgorithmPrediction::getProductsToAccuracy).collect(toSet())
                  )
          )
  );
  </code></pre>
  
  <p>This can't be right. What am I missing? Thank you!</p>