From 169d6453aa370e6167d1d340cfa058fa4363944d Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Thu, 16 May 2019 11:25:54 -0300 Subject: [PATCH] Checking if `andThen` creates a function with the input of the first Function and the output of the second --- Compo.java | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) 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); + } + } }