It exposes chain, which allows to have a
value in a context (F<A>) and then feed that into a function that
takes a normal value and returns a value in a context
(A => F<B>).
One motivation for separating this out from Monad is that there are
situations where we can implement chain but not of. For example,
we can implement map or chain that transforms the values of a
Map<K, ?> type, but we can't implement of (because we wouldn't
know what key to use when instantiating the new Map).
In addition to Apply's laws, Chain instances must obey these laws:
The
Chaintype-class is a lightweight Monad.It exposes chain, which allows to have a value in a context (
F<A>) and then feed that into a function that takes a normal value and returns a value in a context (A => F<B>).One motivation for separating this out from
Monadis that there are situations where we can implementchainbut notof. For example, we can implementmaporchainthat transforms the values of aMap<K, ?>type, but we can't implementof(because we wouldn't know what key to use when instantiating the newMap).In addition to
Apply's laws,Chaininstances must obey these laws:F.chain(g, F.chain(f, fa)) <-> F.chain(x => F.chain(g, f(x)), fa)apcan be derived:(ff, fa) => F.chain(f => F.map(f, fa), ff)Equivalent with the
Chaintype-class in the static-land specification.