aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam/list.gleam18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index d9296da..4ca39f4 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -1034,3 +1034,21 @@ pub fn each(list: List(a), f: fn(a) -> b) -> Nil {
}
}
}
+
+pub fn partition(
+ list: List(a),
+ with categorise: fn(a) -> Bool,
+) -> tuple(List(a), List(a)) {
+ do_partition(list, categorise, [], [])
+}
+
+fn do_partition(list, categorise, trues, falses) {
+ case list {
+ [] -> tuple(reverse(trues), reverse(falses))
+ [x, ..xs] ->
+ case categorise(x) {
+ True -> do_partition(xs, categorise, [x, ..trues], falses)
+ False -> do_partition(xs, categorise, trues, [x, ..falses])
+ }
+ }
+}