pub enum Free<F, A>where
F: HKT,{
Pure(A),
Roll(Box<<F as HKT>::Of<Free<F, A>>>),
}Expand description
Free Monad — builds a monadic computation as a data structure.
Free<F, A> represents a program where F describes the available
effects and A is the result type. Programs are built with pure
and lift_f, composed with chain, and interpreted with fold_map
using a natural transformation into any target monad.
Pure(a) — a finished computation returning a
Roll(F<Free<F, A>>) — one layer of effect wrapping a continuationVariants§
Pure(A)
A pure value — the computation is finished.
Roll(Box<<F as HKT>::Of<Free<F, A>>>)
A layer of effect F wrapping a continuation.
Implementations§
Source§impl<F, A> Free<F, A>
impl<F, A> Free<F, A>
Sourcepub fn lift_f(fa: <F as HKT>::Of<A>) -> Free<F, A>
pub fn lift_f(fa: <F as HKT>::Of<A>) -> Free<F, A>
Lift a single effect F<A> into the free monad.
Sourcepub fn fmap<B>(self, f: impl Fn(A) -> B) -> Free<F, B>
pub fn fmap<B>(self, f: impl Fn(A) -> B) -> Free<F, B>
Map a function over the result of this computation.
Sourcepub fn chain<B>(self, f: impl Fn(A) -> Free<F, B>) -> Free<F, B>
pub fn chain<B>(self, f: impl Fn(A) -> Free<F, B>) -> Free<F, B>
Monadic bind — sequence this computation with a function that produces the next computation.
Auto Trait Implementations§
impl<F, A> Freeze for Free<F, A>where
A: Freeze,
impl<F, A> RefUnwindSafe for Free<F, A>
impl<F, A> Send for Free<F, A>
impl<F, A> Sync for Free<F, A>
impl<F, A> Unpin for Free<F, A>where
A: Unpin,
impl<F, A> UnsafeUnpin for Free<F, A>where
A: UnsafeUnpin,
impl<F, A> UnwindSafe for Free<F, A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more