Witchcraft v1.0.0-beta.2 Witchcraft.Applicative 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 [ap/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
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
of(Witchcraft.Applicative.t) :: (any -> Witchcraft.Applicative.t)
Partially apply of/2
, generally as a way to bring many values into the same context
Examples
iex> to_tuple = of({"very example", "much wow"})
...> [to_tuple.(42), to_tuple.("hello"), to_tuple.([1, 2, 3])]
[{"", 42}, {"", "hello"}, {"", [1, 2, 3]}]
of(Witchcraft.Applicative.t, any) :: Witchcraft.Applicative.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)
...> |> curried_ap([1, 2, 3])
...> |> ap(of([], 42))
[43, 44, 45]
pure(Witchcraft.Applicative.t, any) :: Witchcraft.Applicative.t
Alias for of/2
, for cases that this helps legibility or style
Example
iex> pure({"ohai", "thar"}, 42)
{"", 42}
iex> [] |> pure(42)
[42]
unit(Witchcraft.Applicative.t, any) :: Witchcraft.Applicative.t
Alias for of/2
, for cases that this helps legibility or style
Example
iex> unit({":)", ":("}, 42)
{"", 42}
iex> [] |> unit(42)
[42]
wrap(Witchcraft.Applicative.t, any) :: Witchcraft.Applicative.t
Alias for of/2
, for cases that this helps legibility or style
Example
iex> wrap({":|", "^.~"}, 42)
{"", 42}
iex> [] |> wrap(42)
[42]