pub trait OkErr<S: Scope, C: Container> {
// Required method
fn ok_err<C1, D1, C2, D2, L>(
&self,
logic: L,
) -> (StreamCore<S, C1>, StreamCore<S, C2>)
where C1: SizableContainer + PushInto<D1>,
C2: SizableContainer + PushInto<D2>,
L: FnMut(C::Item<'_>) -> Result<D1, D2> + 'static;
}
Expand description
Extension trait for Stream
.
Required Methods§
sourcefn ok_err<C1, D1, C2, D2, L>(
&self,
logic: L,
) -> (StreamCore<S, C1>, StreamCore<S, C2>)where
C1: SizableContainer + PushInto<D1>,
C2: SizableContainer + PushInto<D2>,
L: FnMut(C::Item<'_>) -> Result<D1, D2> + 'static,
fn ok_err<C1, D1, C2, D2, L>(
&self,
logic: L,
) -> (StreamCore<S, C1>, StreamCore<S, C2>)where
C1: SizableContainer + PushInto<D1>,
C2: SizableContainer + PushInto<D2>,
L: FnMut(C::Item<'_>) -> Result<D1, D2> + 'static,
Takes one input stream and splits it into two output streams.
For each record, the supplied closure is called with the data.
If it returns Ok(x)
, then x
will be sent
to the first returned stream; otherwise, if it returns Err(e)
,
then e
will be sent to the second.
§Examples
use timely::dataflow::operators::ToStream;
use timely::dataflow::operators::core::{OkErr, Inspect};
timely::example(|scope| {
let (odd, even) = (0..10)
.to_stream(scope)
.ok_err(|x| if x % 2 == 0 { Ok(x) } else { Err(x) });
even.container::<Vec<_>>().inspect(|x| println!("even: {:?}", x));
odd.container::<Vec<_>>().inspect(|x| println!("odd: {:?}", x));
});
Object Safety§
This trait is not object safe.