diff options
author | Brett Snyder <bsnyder@digitalocean.com> | 2019-05-11 14:08:45 -0500 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-05-11 20:16:06 +0100 |
commit | ae854f69b8f40609c0ee6fb1aec8957bd3eac1c2 (patch) | |
tree | 24ae4e63429c1e45ffa549254a813ef87016aa1c /src | |
parent | f7d6fe3105fbf650f0f0f95568aca801048f6d15 (diff) | |
download | gleam_stdlib-ae854f69b8f40609c0ee6fb1aec8957bd3eac1c2.tar.gz gleam_stdlib-ae854f69b8f40609c0ee6fb1aec8957bd3eac1c2.zip |
list:split_while
Diffstat (limited to 'src')
-rw-r--r-- | src/list.gleam | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/list.gleam b/src/list.gleam index 40c097e..58f36de 100644 --- a/src/list.gleam +++ b/src/list.gleam @@ -289,3 +289,18 @@ fn do_split(list, n, taken) { pub fn split(list, n) { do_split(list, n, []) } + +fn do_split_while(list, f, acc) { + case list { + | [] -> {reverse(acc), []} + | [x | xs] -> + case f(x) { + | False -> {reverse(acc), list} + | _ -> do_split_while(xs, f, [x | acc]) + } + } +} + +pub fn split_while(list, f) { + do_split_while(list, f, []) +} |