pub trait Comonad: Extend + Extract { }Expand description
A type class for comonads, combining Extend and Extract.
class (Extend w, Extract w) => Comonad w
Comonad is the dual of Monad. Where a Monad
lets you sequence effectful computations by injecting values (pure) and
chaining with bind, a Comonad lets you observe values (extract) and
extend local computations to global ones (extend).
§Laws
A lawful Comonad must satisfy three laws:
-
Left identity: extracting after extending recovers the function’s result.
extract(extend(f, wa)) == f(wa) -
Right identity: extending with
extractis a no-op.extend(extract, wa) == wa -
Map-extract: extracting after mapping is the same as applying the function to the extracted value.
extract(map(f, wa)) == f(extract(wa))
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.