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
|
-module(gleam@tuple).
-compile(no_auto_import).
-export([new/2, first/1, second/1, swap/1, fetch/2]).
new(A, B) ->
{A, B}.
first(Tup) ->
{A, _} = Tup,
A.
second(Tup) ->
{_, A} = Tup,
A.
swap(Tup) ->
{A, B} = Tup,
{B, A}.
fetch(Haystack, Needle) ->
gleam@list:find(Haystack, fun(Tuple) -> case first(Tuple) =:= Needle of
true ->
{ok, second(Tuple)};
false ->
{error, []}
end end).
|