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
faValue in the context implementing this instance.
fExtracting 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>) -> AParameters
faA value in the context implementing this instance.
Return Value
A normal value.
-
pair()Extension method
-
duplicate(_:)Extension method
Install in Dash
Comonad Protocol Reference