Witchcraft v1.0.0-beta Witchcraft.Semigroupoid View Source

A semigroupoid describes some way of composing morphisms on between some collection of objects.

Type Class

An instance of Witchcraft.Semigroupoid must define Witchcraft.Semigroupoid.compose/2.

Semigroupoid  [compose/2]

Link to this section Summary

Functions

Composition operator “the math way”

Composition operator “the pipe way”

Express how to apply a function to actual arguments, or “run the morphism”

Take some value and return it again

Pipe some data through a morphism

Compose, but with the arguments flipped (same direction as |>)

Link to this section Types

Link to this section Functions

Composition operator “the math way”

Examples

iex> times_ten_plus_one =
...>       fn x -> x + 1  end
...>   <|> fn y -> y * 10 end
...>
...> times_ten_plus_one.(5)
51

Composition operator “the pipe way”

Examples

iex> times_ten_plus_one =
...>       fn y -> y * 10 end
...>   <~> fn x -> x + 1  end
...>
...> times_ten_plus_one.(5)
51

Express how to apply a function to actual arguments, or “run the morphism”

Examples

iex> Witchcraft.Semigroupoid.apply(&inspect/1, [42])
"42"

Take some value and return it again

Examples

iex> times_ten_plus_one = compose(fn x -> x + 1 end, fn y -> y * 10 end)
...> times_ten_plus_one.(5)
51

Pipe some data through a morphism.

Similar to apply/2, but with a single argument, not needing to wrap the argument in a list.

Examples

iex> pipe(42, &(&1 + 1))
43
Link to this function pipe_compose(b, a) View Source
pipe_compose(t, t) :: t

Compose, but with the arguments flipped (same direction as |>)

Examples

iex> times_ten_plus_one = pipe_compose(fn y -> y * 10 end, fn x -> x + 1 end)
...> times_ten_plus_one.(5)
51