Skip to content

Instantly share code, notes, and snippets.

@SteveGilham
Last active May 5, 2017 16:11
Show Gist options
  • Save SteveGilham/f1db5bc38de112bb645fc5b0a8e69220 to your computer and use it in GitHub Desktop.
Save SteveGilham/f1db5bc38de112bb645fc5b0a8e69220 to your computer and use it in GitHub Desktop.
let chunk n (source : seq<'a>) =
let makechunk (source : System.Collections.Generic.IEnumerator<'a>) n =
seq { yield source.Current
let mutable i = 0
while (i < n) && source.MoveNext() do
yield source.Current
i <- i + 1
}
seq { use enumerator = source.GetEnumerator()
while enumerator.MoveNext() do
yield makechunk enumerator (n-1)
};;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment