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§
sourcefn branch_when(&self, condition: impl Fn(&T) -> bool + 'static) -> (Self, Self)
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));
});