title: Java 8 stream group by min and max
body: <p>Suppose you run an SQL query against an employees table:</p>
  
  <pre><code>SELECT department, team, MIN(salary), MAX(salary)
    FROM employees
   GROUP BY department, team
  </code></pre>
  
  <p>And in the java client you map the result set to a list of <code>Aggregate</code> instances by making a DAO call like below:</p>
  
  <pre><code>List&lt;Aggregate&gt; deptTeamAggregates = employeeDao.getMinMaxSalariesByDeptAndTeam()
  </code></pre>
  
  <p>And 'Aggregate' has getter methods for department, team, minSalary, maxSalary and there is a <code>Pair&lt;T, T&gt;</code> tuple </p>
  
  <p>What would be the clearest and possible the most optimal way to map the result set into the two maps below:</p>
  
  <pre><code>Map&lt;String, Pair&lt;Integer, Integer&gt;&gt; byDepartmentMinMax = ...
  Map&lt;Pair&lt;String, String&gt;, Pair&lt;Integer, Integer&gt;&gt; byDepartmentAndTeamMinMax  = ...
  </code></pre>
  
  <p>I know I could map my result set in a different way and/or make two trips to the database and achieve the same thing in an easier way but I am more about understanding the java 8 capabilities.</p>
  
  <p>Thank you in advance for your inputs.</p>