Trait Map

Source
pub trait Map<S: Scope, C: DrainContainer> {
    // Required method
    fn flat_map<C2, I, L>(&self, logic: L) -> StreamCore<S, C2>
       where I: IntoIterator,
             C2: Container + SizableContainer + PushInto<I::Item>,
             L: FnMut(C::Item<'_>) -> I + 'static;

    // Provided methods
    fn map<C2, D2, L>(&self, logic: L) -> StreamCore<S, C2>
       where C2: Container + SizableContainer + PushInto<D2>,
             L: FnMut(C::Item<'_>) -> D2 + 'static { ... }
    fn flat_map_builder<'t, I, L>(
        &'t self,
        logic: L,
    ) -> FlatMapBuilder<'t, Self, C, L, I>
       where C: Clone + 'static,
             L: for<'a> Fn(C::Item<'a>) -> I,
             Self: Sized { ... }
}
Expand description

Extension trait for Stream.

Required Methods§

Source

fn flat_map<C2, I, L>(&self, logic: L) -> StreamCore<S, C2>
where I: IntoIterator, C2: Container + SizableContainer + PushInto<I::Item>, L: FnMut(C::Item<'_>) -> I + 'static,

Consumes each element of the stream and yields some number of new elements.

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

timely::example(|scope| {
    (0..10).to_stream(scope)
           .flat_map(|x| (0..x))
           .container::<Vec<_>>()
           .inspect(|x| println!("seen: {:?}", x));
});

Provided Methods§

Source

fn map<C2, D2, L>(&self, logic: L) -> StreamCore<S, C2>
where C2: Container + SizableContainer + PushInto<D2>, L: FnMut(C::Item<'_>) -> D2 + 'static,

Consumes each element of the stream and yields a new element.

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

timely::example(|scope| {
    (0..10).to_stream(scope)
           .map(|x| x + 1)
           .container::<Vec<_>>()
           .inspect(|x| println!("seen: {:?}", x));
});
Source

fn flat_map_builder<'t, I, L>( &'t self, logic: L, ) -> FlatMapBuilder<'t, Self, C, L, I>
where C: Clone + 'static, L: for<'a> Fn(C::Item<'a>) -> I, Self: Sized,

Creates a FlatMapBuilder, which allows chaining of iterator logic before finalization into a stream.

This pattern exists to make it easier to provide the ergonomics of iterator combinators without the overhead of multiple dataflow operators. The resulting single operator will internally use compiled iterators to go record-by-record, and unlike a chain of operators will not need to stage the records of intermediate stages.

§Examples
use timely::dataflow::operators::{Capture, ToStream, core::Map};
use timely::dataflow::operators::capture::Extract;

let data = timely::example(|scope| {
    (0..10i32)
        .to_stream(scope)
        .flat_map_builder(|x| x + 1)
        .map(|x| x + 1)
        .map(|x| x + 1)
        .map(|x| x + 1)
        .map(Some)
        .into_stream::<_,Vec<i32>>()
        .capture()
});

assert_eq!((4..14).collect::<Vec<_>>(), data.extract()[0].1);

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, C: Container + DrainContainer> Map<S, C> for StreamCore<S, C>