forked from java8/Java8InAction
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLaziness.java
More file actions
30 lines (23 loc) · 800 Bytes
/
Laziness.java
File metadata and controls
30 lines (23 loc) · 800 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
package lambdasinaction.chap5;
import java.util.Arrays;
import java.util.List;
import static java.util.stream.Collectors.toList;
/**
* Created by raoul-gabrielurma on 14/01/2014.
*/
public class Laziness {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8);
List<Integer> twoEvenSquares =
numbers.stream()
.filter(n -> {
System.out.println("filtering " + n); return n % 2 == 0;
})
.map(n -> {
System.out.println("mapping " + n);
return n * n;
})
.limit(2)
.collect(toList());
}
}