forked from adamldavis/hellojava8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.java
More file actions
40 lines (29 loc) · 1.08 KB
/
Functions.java
File metadata and controls
40 lines (29 loc) · 1.08 KB
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
35
36
37
38
39
40
import java.util.function.*;
import java.util.stream.*;
import static java.util.stream.Collectors.*;
import java.time.*;
public class Functions {
public static void main(String...args) {
Function<Integer,String> f = Function.<Integer>identity()
.andThen(i -> 2*i).andThen(i -> "str" + i);
System.out.println(
Stream.iterate(1, i -> i + 1)
.limit(10)
.map(f)
.collect(joining(","))
);
Function<LocalDate,LocalDateTime> plusTwoM = Function.<LocalDate>identity()
.andThen(dateTimeFunction(d -> d.plusMonths(2)));
System.out.println(
Stream.iterate(LocalDate.now(), d -> d.plusDays(1))
.limit(10)
.map(plusTwoM)
.map(Object::toString)
.collect(joining(", "))
);
}
public static Function<LocalDate,LocalDateTime> dateTimeFunction(
final Function<LocalDate,LocalDate> f) {
return f.andThen(d -> d.atTime(2, 2));
}
}