View Source Witchcraft.Comonad (Witchcraft v1.0.6-doma)

The dual of monads, Comonad brings an unwrapping function to Extendable 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

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.

Link to this section Types

Link to this section Functions

@spec extract(t()) :: any()

Extract a value out of some context / data structure. This is the opposite of Witchcraft.Applicative.of/2.

examples

Examples

iex> extract({1, 2})
2

extract(%Id{id: 42})
#=> 42
@spec unwrap(t()) :: any()

Alias for extract/1

examples

Examples

iex> unwrap({1, 2})
2

unwrap(%Id{id: 42})
#=> 42