Trait BranchWhen

Source
pub trait BranchWhen<T>: Sized {
    // Required method
    fn branch_when(
        &self,
        condition: impl Fn(&T) -> bool + 'static,
    ) -> (Self, Self);
}
Expand description

Extension trait for Stream.

Required Methods§

Source

fn branch_when(&self, condition: impl Fn(&T) -> bool + 'static) -> (Self, Self)

Takes one input stream and splits it into two output streams. For each time, the supplied closure is called. If it returns true, the records for that will be sent to the second returned stream, otherwise they will be sent to the first.

§Examples
use timely::dataflow::operators::{ToStream, BranchWhen, Inspect, Delay};

timely::example(|scope| {
    let (before_five, after_five) = (0..10)
        .to_stream(scope)
        .delay(|x,t| *x) // data 0..10 at time 0..10
        .branch_when(|time| time >= &5);

    before_five.inspect(|x| println!("Times 0-4: {:?}", x));
    after_five.inspect(|x| println!("Times 5 and later: {:?}", x));
});

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§