Skip to content

Instantly share code, notes, and snippets.

@nenono
Created July 14, 2015 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nenono/1ea2b0d17b3f259fad26 to your computer and use it in GitHub Desktop.
Save nenono/1ea2b0d17b3f259fad26 to your computer and use it in GitHub Desktop.
任意型リストのsplit(その2 by id:htid46)
let splitBy2 sep xs =
let a, b = List.foldBack (fun x (a, b) ->
if x = sep then (b :: a, []) else (a, x :: b)) xs ([], [])
b :: a
let test1 = splitBy2 0 [1;2;3;0;4;5;0;6] = [[1;2;3];[4;5];[6]] // -> true
let test2 = splitBy2 0 [] = [[]] // -> true
let test3 = splitBy2 0 [1;0;2;0] = [[1];[2];[]] // -> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment