Slide 21
Slide 21 text
Stream Gatherers(Preview)
●
WIth Stream, it was not possible to write processed that reference
other data
●
like sliding window
●
Stream Gatherer makes it possible
●
Gatherers like Collectors for `collect`
jshell> IntStream.range(0, 10).boxed()
.gather(Gatherers.windowFixed(3))
.toList()
$1 ==> [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
jshell> IntStream.range(0, 10).boxed()
.gather(Gatherers.windowSliding(3))
.toList()
$2 ==> [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5],
[4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9]]
windowFixed windowSliding