# Witchcraft.Semigroupoid(Witchcraft v1.0.4) 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". Alias for `compose/2`.

Composition operator "the pipe way". Alias for `pipe_compose/2`.

Express how to apply arguments to the very end of a semigroupoid, or "run the morphism". This should not be used to inject values part way though a composition chain.

Take two morphisms and return their composition "the math way". That is, `(b -> c) -> (a -> b) -> (a -> c)`.

Pipe some data through a morphism.

`compose/2`, but with the arguments flipped (same direction as `|>`).

# t()

View Source

## Specs

`t() :: any()`

# g <|> f

View Source

## Specs

`t() <|> any() :: t()`

Composition operator "the math way". Alias for `compose/2`.

## Examples

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

# f <~> g

View Source

## Specs

`t() <~> any() :: t()`

Composition operator "the pipe way". Alias for `pipe_compose/2`.

## Examples

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

# apply(morphism, arguments)

View Source

## Specs

`apply(t(), [any()]) :: t() | any()`

Express how to apply arguments to the very end of a semigroupoid, or "run the morphism". This should not be used to inject values part way though a composition chain.

It is provided here to remain idiomatic with Elixir, and to make prop testing possible.

## Examples

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

# compose(morphism_a, morphism_b)

View Source

## Specs

`compose(t(), t()) :: t()`

Take two morphisms and return their composition "the math way". That is, `(b -> c) -> (a -> b) -> (a -> c)`.

## Examples

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

# pipe(data, fun)

View Source

## Specs

`pipe(any(), t()) :: any()`

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``````

# pipe_compose(b, a)

View Source

## Specs

`pipe_compose(t(), t()) :: t()`

`compose/2`, 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``````