aboutsummaryrefslogtreecommitdiff
path: root/gen/src/std@tuple.erl
blob: 0c9e89db4f6fa91be8c255fd9856876bd3e028b8 (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
-module(std@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) ->
    std@list:find(Haystack, fun(Tuple) -> case first(Tuple) =:= Needle of
                          true ->
                              {ok, second(Tuple)};

                          false ->
                              {error, []}
                      end end).