Skip to content

Commit b3c9000

Browse files
committed
chapter 7 updates
1 parent d6dfe7c commit b3c9000

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package lambdasinaction.chap7;
2+
3+
/**
4+
* Created by raoul-gabrielurma on 16/05/2014.
5+
*/
6+
import java.util.*;
7+
8+
public class Debugging{
9+
public static void main(String[] args) {
10+
List<Point> points = Arrays.asList(new Point(12, 2), null);
11+
points.stream().map(p -> p.getX()).forEach(System.out::println);
12+
}
13+
14+
15+
private static class Point{
16+
private int x;
17+
private int y;
18+
19+
private Point(int x, int y) {
20+
this.x = x;
21+
this.y = y;
22+
}
23+
24+
public int getX() {
25+
return x;
26+
}
27+
28+
public void setX(int x) {
29+
this.x = x;
30+
}
31+
}
32+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package lambdasinaction.chap7;
2+
3+
import java.util.List;
4+
import java.util.stream.Stream;
5+
6+
import static java.util.stream.Collectors.toList;
7+
8+
/**
9+
* Created by raoul-gabrielurma on 16/05/2014.
10+
*/
11+
public class Peek {
12+
13+
public static void main(String[] args) {
14+
15+
List<Integer> result = Stream.of(2, 3, 4, 5)
16+
.peek(x -> System.out.println("taking from stream: " + x)).map(x -> x + 17)
17+
.peek(x -> System.out.println("after map: " + x)).filter(x -> x % 2 == 0)
18+
.peek(x -> System.out.println("after filter: " + x)).limit(3)
19+
.peek(x -> System.out.println("after limit: " + x)).collect(toList());
20+
}
21+
}

0 commit comments

Comments
 (0)