repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

pi/skill-library/java/java-stream-gatherers/examples/jep-485.md

Raw

JEP 485 examples

Source: https://openjdk.org/jeps/485

List<List<Integer>> windows = Stream.iterate(0, i -> i + 1)
    .gather(Gatherers.windowFixed(3))
    .limit(2)
    .toList();
// [[0, 1, 2], [3, 4, 5]]
List<Integer> prefixSums = Stream.of(1, 2, 3, 4)
    .gather(Gatherers.scan(() -> 0, Integer::sum))
    .toList();
Markdown source
File outline
# [JEP 485](https://openjdk.org/jeps/485) examples

Source: https://openjdk.org/jeps/485

```java
List<List<Integer>> windows = Stream.iterate(0, i -> i + 1)
    .gather(Gatherers.windowFixed(3))
    .limit(2)
    .toList();
// [[0, 1, 2], [3, 4, 5]]
```

```java
List<Integer> prefixSums = Stream.of(1, 2, 3, 4)
    .gather(Gatherers.scan(() -> 0, Integer::sum))
    .toList();
```