Current section

Files

Jump to
gleam_stdlib src gleam@pair.erl
Raw

src/gleam@pair.erl

-module(gleam@pair).
-compile([no_auto_import, nowarn_unused_vars]).
-export([first/1, second/1, swap/1, map_first/2, map_second/2, new/2]).
-spec first({FG, any()}) -> FG.
first(Pair) ->
{A, _} = Pair,
A.
-spec second({any(), FJ}) -> FJ.
second(Pair) ->
{_, A} = Pair,
A.
-spec swap({FK, FL}) -> {FL, FK}.
swap(Pair) ->
{A, B} = Pair,
{B, A}.
-spec map_first({FM, FN}, fun((FM) -> FO)) -> {FO, FN}.
map_first(Pair, Fun) ->
{A, B} = Pair,
{Fun(A), B}.
-spec map_second({FP, FQ}, fun((FQ) -> FR)) -> {FP, FR}.
map_second(Pair, Fun) ->
{A, B} = Pair,
{A, Fun(B)}.
-spec new(FS, FT) -> {FS, FT}.
new(First, Second) ->
{First, Second}.