Struct plumbum::Kleisli [] [src]

pub struct Kleisli<'a, A, I, O, B> {
    // some fields omitted
}

The Kleisli arrow from A to ConduitM<I, O, B>.

Methods

impl<'a, I, O, A> Kleisli<'a, A, I, O, A>

fn new() -> Kleisli<'a, A, I, O, A>

Creates the identity arrow.

Example

use plumbum::Kleisli;

let k: Kleisli<i32, (), (), i32> = Kleisli::new();
assert_eq!(k.run(42), 42.into());

impl<'a, I, O, A, B> Kleisli<'a, A, I, O, B>

fn from<F>(f: F) -> Kleisli<'a, A, I, O, B> where F: 'a + FnOnce(A) -> ConduitM<'a, I, O, B>

Wraps the given function into an arrow.

Example

use plumbum::Kleisli;

let k: Kleisli<i32, (), (), i32> = Kleisli::from(|x: i32| (x + 1).into());
assert_eq!(k.run(42), 43.into());

fn append<F, C>(self, f: F) -> Kleisli<'a, A, I, O, C> where F: 'a + FnOnce(B) -> ConduitM<'a, I, O, C>

Appends the given function to the tail of the arrow. This corresponds to closure composition at the codomain (post-composition).

Example

use plumbum::Kleisli;

let k: Kleisli<i32, (), (), i32> = Kleisli::from(|x: i32| (x + 1).into())
                                   .append(|x| (x * 2).into());
assert_eq!(k.run(42), 86.into());

fn run(self, a: A) -> ConduitM<'a, I, O, B> where I: 'static, O: 'static

Given an input, runs the arrow to completion and return the resulting program.