Created
November 3, 2010 15:50
-
-
Save dgfitch/661247 to your computer and use it in GitHub Desktop.
F# splitting a list into a list of lists
This file contains hidden or 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
// there have got to be better ways to do this? | |
let splitList (f:'a -> bool) (list:'a list) = | |
let op (nested:'a list list) (thing: 'a) = | |
if f thing then | |
[] :: nested | |
else | |
match nested with | |
| [] -> [[thing]] | |
| headlist::rest -> (thing :: headlist) :: rest | |
let result = List.fold op [] list | |
result |> List.map List.rev |> List.rev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment