aboutsummaryrefslogtreecommitdiff
path: root/src/std/tuple.gleam
blob: ab38a7426d44fefb4f628156c698645e7cb543f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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([])
    }
  })
}