From fdf7145a92a4be1e9780372b8de5c4770ee06d33 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 14 Aug 2020 08:50:36 +0100 Subject: test and implement unzip --- src/gleam/list.gleam | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') 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. -- cgit v1.2.3