1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use Data;
use dataflow::channels::pact::Pipeline;
use dataflow::{Stream, Scope};
use dataflow::operators::unary::Unary;
pub trait Filter<D: Data> {
fn filter<L: Fn(&D)->bool+'static>(&self, predicate: L) -> Self;
}
impl<G: Scope, D: Data> Filter<D> for Stream<G, D> {
fn filter<L: Fn(&D)->bool+'static>(&self, predicate: L) -> Stream<G, D> {
self.unary_stream(Pipeline, "Filter", move |input, output| {
input.for_each(|time, data| {
data.retain(|x| predicate(x));
if data.len() > 0 {
output.session(&time).give_content(data);
}
});
})
}
}