FunFunc v0.2.0 FunFunc.Tuple

Functions for Tuple. These functions accept a arbitaly length tuple.

Link to this section Summary

Functions

Takes the first value in the tuple

Maps the value in the tuple. The index is zero-index

Maps the first value in the tuple

Maps the value in the tuple. The index is zero-index

Takes the second value in the tuple

Swaps first two elements

Swaps values in the tuple. The index is zero-index

Link to this section Functions

Link to this function fst(tuple)
fst(tuple()) :: any()

Takes the first value in the tuple.

Examples

iex> FunFunc.Tuple.fst({1, 2})
1
iex> FunFunc.Tuple.fst({1, 2, 3})
1
Link to this function map(tuple, index, f)
map(tuple(), integer(), (... -> any())) :: tuple()

Maps the value in the tuple. The index is zero-index.

Examples

iex> FunFunc.Tuple.map({1, 2}, 0, &Integer.to_string/1)
{"1", 2}
iex> FunFunc.Tuple.map({1, 2, 3}, 2, &Integer.to_string/1)
{1, 2, "3"}
Link to this function map_fst(tuple, f)
map_fst(tuple(), (... -> any())) :: tuple()

Maps the first value in the tuple.

Examples

iex> FunFunc.Tuple.map_fst({1, 2}, &Integer.to_string/1)
{"1", 2}
iex> FunFunc.Tuple.map_fst({1, 2, 3}, &Integer.to_string/1)
{"1", 2, 3}
Link to this function map_snd(tuple, f)
map_snd(tuple(), (... -> any())) :: tuple()

Maps the value in the tuple. The index is zero-index.

Examples

iex> FunFunc.Tuple.map_snd({1, 2}, &Integer.to_string/1)
{1, "2"}
iex> FunFunc.Tuple.map_snd({1, 2, 3}, &Integer.to_string/1)
{1, "2", 3}
Link to this function snd(tuple)
snd(tuple()) :: any()

Takes the second value in the tuple.

Examples

iex> FunFunc.Tuple.snd({1, 2})
2
iex> FunFunc.Tuple.snd({1, 2, 3})
2
Link to this function swap(tuple)
swap(tuple()) :: tuple()

Swaps first two elements.

Examples

iex> FunFunc.Tuple.swap({1, 2})
{2, 1}
iex> FunFunc.Tuple.swap({1, 2, 3})
{2, 1, 3}
Link to this function swap(tuple, i, j)
swap(tuple(), integer(), integer()) :: tuple()

Swaps values in the tuple. The index is zero-index.

Examples

iex> FunFunc.Tuple.swap({1, 2}, 0, 1)
{2, 1}
iex> FunFunc.Tuple.swap({1, 2, 3}, 1, 2)
{1, 3, 2}