Skip to main content

FreeAlt

Struct FreeAlt 

Source
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,

Source

pub fn pure(a: A) -> FreeAlt<F, A>

Wrap a pure value.

Source

pub fn lift_f(fa: <F as HKT>::Of<A>) -> FreeAlt<F, A>
where A: Clone, <F as HKT>::Of<A>: 'static,

Lift a single effect into the free alternative.

Source

pub fn zero() -> FreeAlt<F, A>

The empty alternative (zero / failure).

Source

pub fn alt(self, other: FreeAlt<F, A>) -> FreeAlt<F, A>

Combine two alternatives (choice).

Source

pub fn fmap<B>(self, f: impl Fn(A) -> B + 'static) -> FreeAlt<F, B>
where B: 'static,

Map a function over all branches.

Source

pub fn retract(self) -> <F as HKT>::Of<A>
where F: Alternative,

Interpret by collapsing into F’s own Alternative.

Requires F: Alternative.

Source

pub fn count_alternatives(&self) -> usize

Count the total number of alternative branches.

Source

pub fn count_effects(&self) -> usize

Count the total number of effects across all branches.

Auto Trait Implementations§

§

impl<F, A> Freeze for FreeAlt<F, A>

§

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> Unpin for FreeAlt<F, A>
where A: Unpin,

§

impl<F, A> UnsafeUnpin for FreeAlt<F, A>

§

impl<F, A> !UnwindSafe for FreeAlt<F, A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.