Witchcraft.Applicative (Witchcraft v1.0.4) View Source

Applicative extends Apply with the ability to lift value into a particular data type or "context".

This fills in the connection between regular function application and Apply

           data --------------- function ---------------> result
             |                      |                       |
 of(Container, data)    of(Container, function) of(Container, result)
                                                          
%Container<data> --- %Container<function> ---> %Container<result>

Type Class

An instance of Witchcraft.Applicative must also implement Witchcraft.Apply, and define Witchcraft.Applicative.of/2.

   Functor    [map/2]
      
    Apply     [convey/2]
      
 Applicative  [of/2]

Link to this section Summary

Functions

Partially apply of/2, generally as a way to bring many values into the same context.

Bring a value into the same data type as some sample

Alias for of/2, for cases that this helps legibility or style.

Prime a value to be brought into other data types

of/2 with arguments reversed.

Alias for of/2, for cases that this helps legibility or style

Alias for of/2, for cases that this helps legibility or style.

Link to this section Types

Link to this section Functions

Specs

of(t()) :: (any() -> t())

Partially apply of/2, generally as a way to bring many values into the same context.

Examples

iex> {"very example", "much wow"}
...> |> of()
...> |> Witchcraft.Functor.across([42, "hello", [1, 2, 3]])
[{"", 42}, {"", "hello"}, {"", [1, 2, 3]}]

Specs

of(t(), any()) :: t()

Bring a value into the same data type as some sample

Examples

iex> of([], 42)
[42]

iex> of([1, 2, 3], 42)
[42]

iex> of({"a", "b", 155}, 42)
{"", "", 42}

iex> of(fn -> nil end, 42).(55)
42

iex> of(fn(a, b, c) -> a + b - c end, 42).(55)
42

iex> import Witchcraft.Apply
...>
...> []
...> |> of(&+/2)
...> |> provide([1, 2, 3])
...> |> ap(of([], 42))
[43, 44, 45]

Specs

pure(t(), any()) :: t()

Alias for of/2, for cases that this helps legibility or style.

Example

iex> pure({"ohai", "thar"}, 42)
{"", 42}

iex> [] |> pure(42)
[42]

Specs

to(any()) :: (t() -> t())

Prime a value to be brought into other data types

Example

iex> make = to(42)
...> make.({"ohai", "thar"})
{"", 42}
...> make.([])
[42]

Specs

to(any(), t()) :: t()

of/2 with arguments reversed.

Example

iex> to(42, {"ohai", "thar"})
{"", 42}

iex> 42 |> to([])
[42]

42 |> to(%Algae.Id{})
#=> %Algae.Id{id: 42}

Specs

unit(t(), any()) :: t()

Alias for of/2, for cases that this helps legibility or style

Example

iex> unit({":)", ":("}, 42)
{"", 42}

iex> [] |> unit(42)
[42]

Specs

wrap(t(), any()) :: t()

Alias for of/2, for cases that this helps legibility or style.

Example

iex> wrap({":|", "^.~"}, 42)
{"", 42}

iex> [] |> wrap(42)
[42]