pub struct FreeAlt<F, A>where
F: HKT + 'static,
A: 'static,{ /* private fields */ }Expand description
Free Alternative Functor — build alternative computations as data.
FreeAlt<F, A> represents a choice among zero or more applicative
computations, each built from FreeAp<F, A>. This gives a free
Alternative instance for any functor F.
FreeAlt f a ≅ [FreeAp f a]An empty list represents zero (failure), a single element is a
single computation, and multiple elements represent alt (choice).
§Interpretation
retract collapses the structure into F’s own Alternative,
combining branches with F::alt and handling empty lists with
F::zero.
Implementations§
Source§impl<F, A> FreeAlt<F, A>where
F: HKT + 'static,
A: 'static,
impl<F, A> FreeAlt<F, A>where
F: HKT + 'static,
A: 'static,
Sourcepub fn lift_f(fa: <F as HKT>::Of<A>) -> FreeAlt<F, A>
pub fn lift_f(fa: <F as HKT>::Of<A>) -> FreeAlt<F, A>
Lift a single effect into the free alternative.
Sourcepub fn fmap<B>(self, f: impl Fn(A) -> B + 'static) -> FreeAlt<F, B>where
B: 'static,
pub fn fmap<B>(self, f: impl Fn(A) -> B + 'static) -> FreeAlt<F, B>where
B: 'static,
Map a function over all branches.
Sourcepub fn retract(self) -> <F as HKT>::Of<A>where
F: Alternative,
pub fn retract(self) -> <F as HKT>::Of<A>where
F: Alternative,
Interpret by collapsing into F’s own Alternative.
Requires F: Alternative.
Sourcepub fn count_alternatives(&self) -> usize
pub fn count_alternatives(&self) -> usize
Count the total number of alternative branches.
Sourcepub fn count_effects(&self) -> usize
pub fn count_effects(&self) -> usize
Count the total number of effects across all branches.
Auto Trait Implementations§
impl<F, A> !RefUnwindSafe for FreeAlt<F, A>
impl<F, A> !Send for FreeAlt<F, A>
impl<F, A> !Sync for FreeAlt<F, A>
impl<F, A> !UnwindSafe for FreeAlt<F, A>
impl<F, A> Freeze for FreeAlt<F, A>
impl<F, A> Unpin for FreeAlt<F, A>where
A: Unpin,
impl<F, A> UnsafeUnpin for FreeAlt<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