List of usage examples for java.util.function Function compose
default <V> Function<V, R> compose(Function<? super V, ? extends T> before)
From source file:Main.java
public static void main(String[] args) { Function<Integer, Integer> incrementer = (n) -> n + 1; Function<Integer, Integer> before = (n) -> n * 2; System.out.println(incrementer.compose(before).apply(2)); }
From source file:Main.java
public static void main(String[] args) { Function<Integer, String> converter = (i) -> Integer.toString(i); Function<String, Integer> reverse = (s) -> Integer.parseInt(s); System.out.println(converter.apply(3).length()); System.out.println(converter.compose(reverse).apply("30").length()); }
From source file:Main.java
public static void main(String[] args) { Function<Double, Double> square = number -> number * number; Function<Double, Double> half = number -> number * 2; List<Double> numbers = Arrays.asList(10D, 4D, 12D); // pay attention to the order System.out.println(mapIt(numbers, square.compose(half))); System.out.println(mapIt(numbers, half.compose(square))); // you can chain them System.out.println(mapIt(numbers, half.andThen(square))); }