How should one implement a chunking (or partitioning) function for F# sequences? I'm looking for a function with this signature...
val toChunks : n:int -> sequence:seq<'T> -> seq<seq<'T>>
...which returns the items of the original sequence in groups of n
items. The input sequence may be unending.
Simple Example
[1; 2; 3; 4; 5; 6; 7; 8; 9]
|> toChunks 4
|> Seq.iter (printfn "%A")
seq [1; 2; 3; 4]
seq [5; 6; 7; 8]
seq [9]