Comonad
public protocol Comonad : Functor
A Comonad is the dual of a Monad
. It provides capabilities to compose functions that extract values from their context.
Implementations of this instance must obey the following laws:
extract(duplicate(fa)) == fa
map(fa, f) == coflatMap(fa, { a in f(extract(a)) }
coflatMap(fa, extract) == fa
extract(coflatMap(fa, f)) == f(fa)
-
Applies a value in the context implementing this instance to a function that takes a value in a context, and returns a normal value.
This function is the dual of
Monad.flatMap
.Declaration
Parameters
fa
Value in the context implementing this instance.
f
Extracting function.
Return Value
The result of extracting and transforming the value, in the context implementing this instance.
-
Extracts the value contained in the context implementing this instance.
This function is the dual of
Monad.pure
(viaApplicative
).Declaration
Swift
static func extract<A>(_ fa: Kind<Self, A>) -> A
Parameters
fa
A value in the context implementing this instance.
Return Value
A normal value.
-
pair()
Extension method
-
duplicate(_:)
Extension method