aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam/list.gleam11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index 06e5a33..c82db2e 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -623,6 +623,17 @@ pub fn strict_zip(
}
}
+fn do_unzip(input, xs, ys) {
+ case input {
+ [] -> tuple(reverse(xs), reverse(ys))
+ [tuple(x, y), ..rest] -> do_unzip(rest, [x, ..xs], [y, ..ys])
+ }
+}
+
+pub fn unzip(input: List(tuple(a, b))) -> tuple(List(a), List(b)) {
+ do_unzip(input, [], [])
+}
+
/// Insert a given value between each existing element in a given list.
///
/// This function runs in linear time and copies the list.