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}
id_arrow(sample)
View Sourceid_arrow(Realm.Arrow.t()) :: (any() -> Realm.Arrow.t())
The identity function lifted into an arrow of the correct type.
Examples
iex> id_arrow(fn -> nil end).(99)
99
postcompose(arrow, fun)
View Sourcepostcompose(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
precompose(fun, arrow)
View Sourceprecompose((... -> 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
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}
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"}
Swap positions of elements in a tuple.
Examples
iex> swap({1, 2})
{2, 1}
Merge two tuple values with a combining function.
Examples
iex> import Realm.Apply.Algebra
...> unsplit({1, 2}, &+/2)
3