Witchcraft v0.5.0 Witchcraft.Applicative

Applicative functors provide a method of seqing a function contained in a data structure to a value of the same type. This allows you to seq and compose functions to values while avoiding repeated manual wrapping and unwrapping of those values.

Properties

Identity

seqing a lifted id to some lifted value v does not change v

seq(v, wrap(&id(&1))) == v

Composition

seq composes normally.

seq((wrap &compose(&1,&2)), (seq(u,(seq(v, w))))) == seq(u,(seq(v, w)))

Homomorphism

seqing a wrapped function to a wrapped value is the same as wrapping the result of the function on that value.

seq(wrap x, wrap f) == wrap f(x))

Interchange

The order does not matter when seqing to a wrapped value and a wrapped function.

seq(wrap y, u) == seq(u, wrap &(lift(y, &1))

Functor

Being an applicative functor, seq behaves as lift on wrapped values

lift(x, f) == seq(x, (wrap f))

Notes

Given that Elixir functons are right-associative, you can write clean looking, but much more ambiguous versions:

wrap(y) |> seq(u) == seq(u, wrap(&lift(y, &1)))
lift(x, f) == seq(x, wrap f)

However, it is strongly recommended to include the parentheses for clarity.

Summary

Functions

lift(val_1, val_2, fun)

See Witchcraft.Applicative.Function.lift/3.

lift(val_1, val_2, val_3, fun)

See Witchcraft.Applicative.Function.lift/4.

lift(val_1, val_2, val_3, val_4, fun)

See Witchcraft.Applicative.Function.lift/5.

seq(applicative, fun)

See Witchcraft.Applicative.Protocol.seq/2.

seq_first(first, second)

See Witchcraft.Applicative.Function.seq_first/2.

seq_second(first, second)

See Witchcraft.Applicative.Function.seq_second/2.

wrap(bare)

See Witchcraft.Applicative.Wrap.wrap/1.