Demonstrate how to extend stream‘s Transform base class to create streaming filters for streamed objects.
We observe each object in the stream, pushing along any values meeting the filter’s predicate condition. In other words, we’re filtering out any values that do not meet the predicate condition.
odd = (d) -> d % 2
evens = new Filter((d) -> not odd(d))
count
.upto(11)
.pipe(evens)
.pipe(log)
Output:
2
4
6
8
10