timely::dataflow::operators::branch

Trait Branch

Source
pub trait Branch<S: Scope, D: Data> {
    // Required method
    fn branch(
        &self,
        condition: impl Fn(&S::Timestamp, &D) -> bool + 'static,
    ) -> (Stream<S, D>, Stream<S, D>);
}
Expand description

Extension trait for Stream.

Required Methods§

Source

fn branch( &self, condition: impl Fn(&S::Timestamp, &D) -> bool + 'static, ) -> (Stream<S, D>, Stream<S, D>)

Takes one input stream and splits it into two output streams. For each record, the supplied closure is called with a reference to the data and its time. If it returns true, the record will be sent to the second returned stream, otherwise it will be sent to the first.

If the result of the closure only depends on the time, not the data, branch_when should be used instead.

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

timely::example(|scope| {
    let (odd, even) = (0..10)
        .to_stream(scope)
        .branch(|_time, x| *x % 2 == 0);

    even.inspect(|x| println!("even numbers: {:?}", x));
    odd.inspect(|x| println!("odd numbers: {:?}", 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§

Source§

impl<S: Scope, D: Data> Branch<S, D> for Stream<S, D>