Teaching old java Streams new tricks
Implement the Gatherer
Stream interface, so you can do:
Some useful gatheres provided by native Java:
- fold
- scan
- windowFixed
- windowSliding
- mapConffurent
Stream Anatomy:
- Source
- Intermediate operation
- Terminal Operation
- Pipeline: the whole operation, from source to terminal operation
What features do we need?
- consume: produce ratios (1:1, 1:N, N:1, N:M)
- finite or infinite
- infinite requires incremental operation
- finite benefits from incremental operation
- stateful or stateless
- some operations are inherently stateless / stateful
- frugal or greedy
- frugal requires incremental operation
- greedy benefits from incremental operation
- sequential or parallellizable
- some operations are trivially parallelizable
- some operations can only run sequentially
- finishing touches or not
- some operations can only work when they know that there are no more input elements
Stream.gather(Gatherer)
: an extensible API for intermediate operations:
Some included Gatherer
in java:
Gatherers.fold()
: stateful, inherently ordered, N:1 operation
Gatherers.scan()
: stateful, inherently ordered, 1:1 operation
Gatheres.windowFixed(...)
: stateful, inherently ordered, N:M operation
Gatheres.windowSliding(...)
: stateful, inherently ordered, N:M operation
Gatheres.mapConcurrent(...)
: stateful, inherently ordered, 1:! operation