Enum plumbum::ConduitM [] [src]

pub enum ConduitM<'a, I, O, A> {
    Pure(Box<A>),
    Defer(Kleisli<'a, (), I, O, A>),
    Flush(Kleisli<'a, (), I, O, A>),
    Await(Kleisli<'a, Chunk<Vec<I>>, I, O, A>),
    Yield(Vec<O>, Kleisli<'a, (), I, O, A>),
    Leftover(Vec<I>, Kleisli<'a, (), I, O, A>),
}

Represents a conduit, i.e. a sequence of await/yield actions.

Variants

Pure

The case Pure(a) means that the conduit contains no further actions and just returns the result a.

Defer

The case Defer(k) means that the conduit needs another iteration to make progress, and the remaining (suspended) program is given by the kleisli arrow k

Flush

The case Flush(k) means that the conduit instructs the downstream to flush, and the remaining (suspended) program is given by the kleisli arrow k

Await

The case Await(k) means that the conduit waits for a value of type I, and the remaining (suspended) program is given by the kleisli arrow k.

Yield

The case Yield(o, k) means that the conduit yields a value of type O, and the remaining (suspended) program is given by the kleisli arrow k.

Leftover

The case Leftover(i, k) means that the conduit has a leftover value of type I, and the remaining (suspended) program is given by the kleisli arrow k.

Methods

impl<'a, O> ConduitM<'a, Void, O, ()>

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

Generalize a Source by universally quantifying the input type.

fn connect<A>(self, sink: Sink<'a, O, A>) -> A where O: 'static

Pulls data from the source and pushes it into the sink.

Example

use std::iter::FromIterator;
use plumbum::{Source, Sink, produce};

let src = Source::from_iter(vec![42, 43]);
let sink = Sink::fold(0, |x, y| x + y);

assert_eq!(src.connect(sink), 85);

impl<'a, I, O> ConduitM<'a, I, O, ()>

fn fuse<P, A>(self, other: ConduitM<'a, O, P, A>) -> ConduitM<'a, I, P, A> where I: 'static, O: 'static, P: 'static, A: 'a

Combines two conduits together into a new conduit.

Example

use std::iter::FromIterator;
use plumbum::{Conduit, Source, Sink};

let src = Source::from_iter(vec![42, 43]);
let conduit = Conduit::transform(|x| 1 + x);
let sink = Sink::fold(0, |x, y| x + y);

assert_eq!(src.fuse(conduit).connect(sink), 87);

fn transform<F>(f: F) -> Self where I: 'a, O: 'a, F: 'a + Fn(I) -> O

Apply a transformation to all values in a stream.

impl<'a, I, A> ConduitM<'a, I, Void, A>

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

Generalize a Sink by universally quantifying the output type.

fn fold<F>(a: A, f: F) -> Self where I: 'a, A: 'a, F: 'a + Fn(A, I) -> A

Fold all values from upstream into a final value.

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

fn and_then<B, F>(self, js: F) -> ConduitM<'a, I, O, B> where F: 'a + FnOnce(A) -> ConduitM<'a, I, O, B>

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

fn and<B: 'a>(self, other: ConduitM<'a, I, O, B>) -> ConduitM<'a, I, O, B> where I: 'a, O: 'a

Appends two conduits together, which means, it returns a new conduit that executes both conduits sequentially, and forwards the return value of the second.

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

Zips two conduits together, which means, it returns a new conduit that executes both conduits sequentially, and forwards both return values.

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

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

Trait Implementations

impl<'a, I, O: 'a> Extend<O> for ConduitM<'a, I, O, ()>

fn extend<T: IntoIterator<Item=O>>(&mut self, iterator: T) where I: 'a, T::IntoIter: 'a

impl<'a, I, O: 'a> FromIterator<O> for ConduitM<'a, I, O, ()>

fn from_iter<T: IntoIterator<Item=O>>(iterator: T) -> Self where I: 'a, T::IntoIter: 'a

impl<'a, I, O, A: PartialEq> PartialEq for ConduitM<'a, I, O, A>

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

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

impl<'a, I, O, A: Debug> Debug for ConduitM<'a, I, O, A>

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

impl<'a, I, O, A> From<A> for ConduitM<'a, I, O, A>

fn from(a: A) -> ConduitM<'a, I, O, A>