-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJEP485StreamGatherers.java
More file actions
34 lines (30 loc) · 985 Bytes
/
JEP485StreamGatherers.java
File metadata and controls
34 lines (30 loc) · 985 Bytes
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
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Gatherers;
import java.util.stream.Stream;
public class JEP485StreamGatherers {
public static void main(String[] args) {
// Stream Gatherers (JEP 485)
// https://openjdk.java.net/jeps/485
// Custom Intermediate Operation distinctBy
/*
Stream.of("foo", "bar", "baz", "quux")
.gather(Gatherers.distinctBy(String::length))
.toList();
*/
// Creating Fixed-size Windows
/*
Stream.iterate(0, i -> i + 1)
.gather(Gatherers.windowFixed(3))
.limit(2)
.toList();
*/
// Parallel Processing with selectOne
/*
Stream.generate(() -> ThreadLocalRandom.current().nextInt())
.limit(1000)
.parallel()
.gather(Gatherers.selectOne(Math::max))
.findFirst();
*/
}
}