title: Aggregate functions in Seq module
body: <p>I am trying to add some additional aggregate functions to the Seq module. I was looking at the implementation of some of the functions listed here:</p>
  
  <p><a href="https://github.com/fsharp/fsharp/blob/master/src/fsharp/FSharp.Core/seq.fs" rel="nofollow">https://github.com/fsharp/fsharp/blob/master/src/fsharp/FSharp.Core/seq.fs</a></p>
  
  <p>One of the disclaimers there is "This function returns a sequence that digests the whole initial sequence as soon as that sequence is iterated. As a result this function should not be used with large or infinite sequences." 
  This is true of many functions, such as the GroupBy.</p>
  
  <ul>
  <li><p>First question: are there methods to write aggregate functions that can handle large sequences efficiently?  I know "Large" is subjective; I'm just looking for general patterns to write such functions.</p></li>
  <li><p>Second question: how do I ensure that the collections such as Dictionary(that are defined within the aggregate functions) are garbage collected efficiently? I understand Dictionaries should be collected when they go out of scope, but is there a way to indicate that explicitly? Given that the dictionary is scoped to remain within the function, I cant call .Clear() on that either right?</p></li>
  </ul>