| 5 | import java.util.function.*; |
| 6 | |
| 7 | public class FunctionComposition { |
| 8 | static Function<String, String> |
| 9 | f1 = s -> { |
| 10 | System.out.println(s); |
| 11 | return s.replace('A', '_'); |
| 12 | }, |
| 13 | f2 = s -> s.substring(3), |
| 14 | f3 = s -> s.toLowerCase(), |
| 15 | f4 = f1.compose(f2).andThen(f3); |
| 16 | public static void main(String[] args) { |
| 17 | System.out.println( |
| 18 | f4.apply("GO AFTER ALL AMBULANCES")); |
| 19 | } |
| 20 | } |
| 21 | /* Output: |
| 22 | AFTER ALL AMBULANCES |
| 23 | _fter _ll _mbul_nces |