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§
sourcefn branch(
&self,
condition: impl Fn(&S::Timestamp, &D) -> bool + 'static,
) -> (Stream<S, D>, Stream<S, D>)
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));
});
Object Safety§
This trait is not object safe.