forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
36 lines (25 loc) · 892 Bytes
/
Copy pathMain.java
File metadata and controls
36 lines (25 loc) · 892 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
35
36
package modern.challenge;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) {
}
@SuppressWarnings("unchecked")
public static Function<String, String> reduceStrings(Function<String, String>... functions) {
Function<String, String> function = Stream.of(functions)
.reduce(Function.identity(), Function::andThen);
return function;
}
public static List<String> replace(List<String> list, Replacer<String> r) {
if (list == null || r == null) {
throw new IllegalArgumentException("List/replacer cannot be null");
}
List<String> result = new ArrayList<>();
for (String s : list) {
result.add(r.replace(s));
}
return result;
}
}