diff --git a/Compo.java b/Compo.java index fe09807..501982a 100644 --- a/Compo.java +++ b/Compo.java @@ -24,6 +24,12 @@ public class Compo { .peek(printer) .collect(Collectors.toList()); System.out.println("Result: " + result); + + ToString toString = new ToString(); + ToInteger toInteger = new ToInteger(); + + Function f = toString.andThen(toInteger); + System.out.println("Conversion: " + f.apply(12L)); } private static class Doubler implements Function { @@ -42,9 +48,9 @@ public class Compo { private static class Printer implements Consumer { - Function processor; + Function processor; - public Printer(Function processor) { + public Printer(Function processor) { this.processor = processor; } @@ -53,4 +59,18 @@ public class Compo { System.out.println("Consumer: " + processor.apply(input)); } } + + private static class ToString implements Function { + @Override + public String apply(Long input) { + return input.toString(); + } + } + + private static class ToInteger implements Function { + @Override + public Integer apply(String input) { + return Integer.parseInt(input); + } + } }