aboutsummaryrefslogtreecommitdiff
path: root/src/list.gleam
diff options
context:
space:
mode:
Diffstat (limited to 'src/list.gleam')
-rw-r--r--src/list.gleam15
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, [])
+}