Witchcraft.Comonad (Witchcraft v1.0.4) View Source
The dual of monads, Comonad
brings an unwrapping function to Extend
able data.
Note that the unwrapping function (extract
) must return a value, and is not
available on many data structres that have an empty element. For example,
there is no Comonad
instance for List
because we cannot pull a value
out of []
.
Type Class
An instance of Witchcraft.Comonad
must also implement Witchcraft.Extend
,
and define Witchcraft.Comonad.extract/1
.
Functor [map/2]
↓
Extend [nest/1]
↓
Comonad [extract/1]
Link to this section Summary
Functions
Extract a value out of some context / data structure. This is the opposite
of Witchcraft.Applicative.of/2
.
Alias for extract/1
Link to this section Types
Specs
t() :: any()
Link to this section Functions
Specs
Extract a value out of some context / data structure. This is the opposite
of Witchcraft.Applicative.of/2
.
Examples
iex> extract({1, 2})
2
extract(%Id{id: 42})
#=> 42
Specs
Alias for extract/1
Examples
iex> unwrap({1, 2})
2
unwrap(%Id{id: 42})
#=> 42