Realm v0.1.0 Realm.Arrow.Algebra View Source

Link to this section Summary

Functions

Target the first element of a tuple.

The identity function lifted into an arrow of the correct type.

Compose an arrow (left) with a function (right) to produce a new arrow.

Compose a function (left) with an arrow (right) to produce a new arrow.

Switch the associativity of a nested tuple. Helpful since many arrows act on a subset of a tuple, and you may want to move portions in and out of that stream.

Target the second element of a tuple.

Copy a single value into both positions of a 2-tuple. This is useful is you want to run functions on the input separately.

Swap positions of elements in a tuple.

Merge two tuple values with a combining function.

Link to this section Functions

Target the first element of a tuple.

Examples

iex> import Realm.Arrow.Algebra
...> first(fn x -> x * 50 end).({1, 1})
{50, 1}

The identity function lifted into an arrow of the correct type.

Examples

iex> id_arrow(fn -> nil end).(99)
99
Link to this function

postcompose(arrow, fun)

View Source
postcompose(Realm.Arrow.t(), (... -> any())) :: Realm.Arrow.t()

Compose an arrow (left) with a function (right) to produce a new arrow.

Examples

iex> import Realm.Apply.Algebra
...> f = postcompose(
...>   Arrow.arrowize(fn _ -> nil end, fn x -> x + 1 end),
...>   fn y -> y * 10 end
...> )
...> f.(42)
430
Link to this function

precompose(fun, arrow)

View Source
precompose((... -> any()), Realm.Arrow.t()) :: Realm.Arrow.t()

Compose a function (left) with an arrow (right) to produce a new arrow.

Examples

iex> import Realm.Apply.Algebra
...> f = precompose(
...>   fn x -> x + 1 end,
...>   Arrow.arrowize(fn _ -> nil end, fn y -> y * 10 end)
...> )
...> f.(42)
430
Link to this function

reassociate(arg)

View Source
reassociate({any(), {any(), any()}} | {{any(), any()}, any()}) ::
  {{any(), any()}, any()} | {any(), {any(), any()}}

Switch the associativity of a nested tuple. Helpful since many arrows act on a subset of a tuple, and you may want to move portions in and out of that stream.

Examples

iex> import Realm.Apply.Algebra
...> reassociate({1, {2, 3}})
{{1, 2}, 3}
iex> import Realm.Apply.Algebra
...> reassociate({{1, 2}, 3})
{1, {2, 3}}

Target the second element of a tuple.

Examples

iex> import Realm.Arrow.Algebra
...> second(fn x -> x * 50 end).({1, 1})
{1, 50}
Link to this function

split(x)

View Source
split(any()) :: {any(), any()}

Copy a single value into both positions of a 2-tuple. This is useful is you want to run functions on the input separately.

Examples

iex> import Realm.Arrow.Algebra
...> split(42)
{42, 42}
iex> import Realm.Arrow.Algebra
...> 5
...> |> split()
...> |> (second(fn x -> x - 2 end)
...> <~> first(fn y -> y * 10 end)
...> <~> second(&inspect/1)).()
{50, "3"}
iex> import Realm.Arrow.Algebra
...> import Realm.Semigroupoid.Algebra
...> 5
...> |> split()
...> |> pipe(second(fn x -> x - 2 end))
...> |> pipe(first(fn y -> y * 10 end))
...> |> pipe(second(&inspect/1))
{50, "3"}
Link to this function

swap(arg)

View Source
swap({any(), any()}) :: {any(), any()}

Swap positions of elements in a tuple.

Examples

iex> swap({1, 2})
{2, 1}
Link to this function

unsplit(arg, fun)

View Source
unsplit({any(), any()}, (any(), any() -> any())) :: any()

Merge two tuple values with a combining function.

Examples

iex> import Realm.Apply.Algebra
...> unsplit({1, 2}, &+/2)
3