title: How to groupBy an iterator without converting it to list in scala?
body: <p>Suppose I want to <code>groupBy</code> on a iterator, compiler asks to "<code>value groupBy is not a member of Iterator[Int]</code>". One way would be to convert iterator to list which I want to avoid. I want to do the <code>groupBy</code> such that the input is <code>Iterator[A]</code> and output is <code>Map[B, Iterator[A]]</code>. Such that the part of the iterator is loaded only when that part of element is accessed and not loading the whole list into memory. I also know the possible set of keys, so I can say whether a particular key exists.</p>
  
  <pre><code>def groupBy(iter: Iterator[A], f: fun(A)-&gt;B): Map[B, Iterator[A]] = {
      .........
  }
  </code></pre>