title: Kotlin: groupBy and convert to other object
body: <p>I have a list of objects</p>
  
  <pre><code>data class OldFormat(ShiftId: Int, NozzleValue: Int, NozzleId: Int , UserId: Int)
  </code></pre>
  
  <p>which I want to group by two of fields "shiftId and userId" and then subtract the maximum value of each group from the minimum value of  the same group and then
  sum the result and then convert it to a new object with this class:</p>
  
  <pre><code>data class NewFormat(ShiftId: Int, NozzleValue: Int, UserId: Int)
  </code></pre>
  
  <p>The process would be like this:</p>
  
  <pre><code>listOfOldFormat -&gt; groupby(shiftId, userId) -&gt; sum(maximumValue-minimumValue) -&gt; listOfNewFormat
  </code></pre>