Created
April 11, 2012 22:36
-
-
Save FunctionalFirst/2363222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let groupsOf n (items: seq<_>) = | |
use e = items.GetEnumerator() | |
let rec loop i acc = | |
seq { | |
match i, acc, e.MoveNext() with | |
| 0, [], _ | _, [], false -> () | |
| _, _, false -> | |
yield seq (List.rev acc) | |
| 0, _, true -> | |
yield seq (List.rev acc) | |
yield! loop (n - 1) [e.Current] | |
| _, _, true -> | |
yield! loop (i - 1) (e.Current::acc) | |
} | |
loop n [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment