module Seq = /// Returns a sequence that yields chunks of length n. /// Each chunk is returned as a list. let split length (xs: seq<'T>) = let rec loop xs = [ yield Seq.truncate length xs |> Seq.toList match Seq.length xs <= length with | false -> yield! loop (Seq.skip length xs) | true -> () ] loop xs // Demo [1 .. 20] |> Seq.split 3 |> Seq.toArray // Output // [|[1; 2; 3]; [4; 5; 6]; [7; 8; 9]; [10; 11; 12]; [13; 14; 15]; [16; 17; 18]; // [19; 20]|]