forked from java8/Java8InAction
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLetter.java
More file actions
28 lines (20 loc) · 774 Bytes
/
Letter.java
File metadata and controls
28 lines (20 loc) · 774 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
package lambdasinaction.chap9;
import java.util.function.Function;
public class Letter{
public static String addHeader(String text){
return "From Raoul, Mario and Alan:" + text;
}
public static String addFooter(String text){
return text + "Kind regards";
}
public static String checkSpelling(String text){
return text.replaceAll("C\\+\\+", "**Censored**");
}
public static void main(String...args){
Function<String, String> addHeader = Letter::addHeader;
Function<String, String> transformationPipeline
= addHeader.andThen(Letter::checkSpelling)
.andThen(Letter::addFooter);
System.out.println(transformationPipeline.apply("C++ stay away from me!"));
}
}