module Seq =
/// Returns a sequence that yields chunks of length n.
/// Each chunk is returned as a list.
let batchesOf length (xs: seq<'T>) =
let rec loop xs =
seq {
yield Seq.truncate length xs
match Seq.length xs <= length with
| false -> yield! loop (Seq.skip length xs)
| true -> ()
}
loop xs
let erroringSeq =
yield 1
yield 2
yield 3
yield 4
yield 5
raise (System.ApplicationException("read too far"))
erroringSeq
|> Seq.batchesOf 2
|> printfn "%A"