Enum Program

Source
pub enum Program<'a, I: Instr, A> {
    Pure(Box<A>),
    Then(Box<I>, Kleisli<'a, I, I::Return, A>),
}
Expand description

Represents a program, i.e. a sequence of instructions.

  • The instructions are given by the type I.
  • A is the return type of the program.

Variants§

§

Pure(Box<A>)

The case Pure(a) means that the program contains no instructions and just returns the result a.

§

Then(Box<I>, Kleisli<'a, I, I::Return, A>)

The case Then(instr, k) means that the first instruction is instr and the remaining program is given by the kleisli arrow k.

Implementations§

Source§

impl<'a, I: 'a + Instr, A> Program<'a, I, A>

Source

pub fn and_then<B, F>(self, js: F) -> Program<'a, I, B>
where F: 'a + Fn(A) -> Program<'a, I, B>,

Appends a continuation to a program. Which means, given a function from A to Program<I, B>, passes the return value of the program to the function, and returns the resulting program.

Equivalent to the monadic >>= operator.

Source

pub fn map<B, F>(self, f: F) -> Program<'a, I, B>
where F: 'a + Fn(A) -> B,

Modifies the return value of the program. Seen differently, it lifts a function from A to B into a function from Program<I, A> to Program<I, B>.

Equivalent to the monadic liftM.

Trait Implementations§

Source§

impl<'a, I: 'a + Instr, A: Debug> Debug for Program<'a, I, A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, I: 'a + Instr, A: PartialEq> PartialEq for Program<'a, I, A>

Source§

fn eq(&self, other: &Program<'a, I, A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<'a, I, A> Freeze for Program<'a, I, A>

§

impl<'a, I, A> !RefUnwindSafe for Program<'a, I, A>

§

impl<'a, I, A> !Send for Program<'a, I, A>

§

impl<'a, I, A> !Sync for Program<'a, I, A>

§

impl<'a, I, A> Unpin for Program<'a, I, A>
where <I as Instr>::Return: Unpin, A: Unpin,

§

impl<'a, I, A> !UnwindSafe for Program<'a, I, 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.