aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrett Snyder <bsnyder788@gmail.com>2019-05-10 11:26:59 -0500
committerLouis Pilfold <louis@lpil.uk>2019-05-10 17:26:59 +0100
commit83525b26f33d906284c1d5637aafe578d32704ba (patch)
treeffe908218a8dc1723f0e064ce3fdd91011036ec0 /src
parentd2823c67e674358a1610f24afa584ddf5f31874d (diff)
downloadgleam_stdlib-83525b26f33d906284c1d5637aafe578d32704ba.tar.gz
gleam_stdlib-83525b26f33d906284c1d5637aafe578d32704ba.zip
list:strict_zip (#167)
Diffstat (limited to 'src')
-rw-r--r--src/list.gleam10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/list.gleam b/src/list.gleam
index dd8fb8a..288d971 100644
--- a/src/list.gleam
+++ b/src/list.gleam
@@ -7,6 +7,9 @@ pub enum Empty =
pub enum NotFound =
| NotFound
+pub enum LengthMismatch =
+ | LengthMismatch
+
// Using the Erlang C BIF implementation.
//
pub external fn length(List(a)) -> Int = "erlang" "length"
@@ -192,6 +195,13 @@ pub fn zip(l1, l2) {
}
}
+pub fn strict_zip(l1, l2) {
+ case length(l1) == length(l2) {
+ | True -> Ok(zip(l1, l2))
+ | False -> Error(LengthMismatch)
+ }
+}
+
pub fn intersperse(list, elem) {
case list {
| [] -> []