diff options
author | Louis Pilfold <louis@lpil.uk> | 2019-05-29 21:02:55 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-06-02 21:12:59 +0100 |
commit | 5a1f3494eb9517a7b7a332cb74dd10a6a7d32d31 (patch) | |
tree | 5d0d281c66cf71c6e3ca880e6621138a71b95e7b /src/std/tuple.gleam | |
parent | ee03f5a0465e176e220060164a5ffc408f73ed0d (diff) | |
download | gleam_stdlib-5a1f3494eb9517a7b7a332cb74dd10a6a7d32d31.tar.gz gleam_stdlib-5a1f3494eb9517a7b7a332cb74dd10a6a7d32d31.zip |
Enable namespaced modules
Diffstat (limited to 'src/std/tuple.gleam')
-rw-r--r-- | src/std/tuple.gleam | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/std/tuple.gleam b/src/std/tuple.gleam new file mode 100644 index 0000000..ab38a74 --- /dev/null +++ b/src/std/tuple.gleam @@ -0,0 +1,29 @@ +import std/list + +pub fn new(a, b) { + {a, b} +} + +pub fn first(tup) { + let {a, _} = tup + a +} + +pub fn second(tup) { + let {_, a} = tup + a +} + +pub fn swap(tup) { + let {a, b} = tup + {b, a} +} + +pub fn fetch(haystack, needle) { + list:find(haystack, fn(tuple) { + case first(tuple) == needle { + | True -> tuple |> second |> Ok + | False -> Error([]) + } + }) +} |