aboutsummaryrefslogtreecommitdiff
path: root/src/std/tuple.gleam
diff options
context:
space:
mode:
Diffstat (limited to 'src/std/tuple.gleam')
-rw-r--r--src/std/tuple.gleam29
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([])
+ }
+ })
+}