Browse Source

Checking if `andThen` creates a function with the input of the first Function and the output of the second

master
Julio Biason 5 years ago
parent
commit
169d6453aa
  1. 24
      Compo.java

24
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<Long, Integer> f = toString.andThen(toInteger);
System.out.println("Conversion: " + f.apply(12L));
}
private static class Doubler implements Function<Long, Long> {
@ -42,9 +48,9 @@ public class Compo {
private static class Printer implements Consumer<Long> {
Function processor;
Function<Long, Long> processor;
public Printer(Function processor) {
public Printer(Function<Long, Long> processor) {
this.processor = processor;
}
@ -53,4 +59,18 @@ public class Compo {
System.out.println("Consumer: " + processor.apply(input));
}
}
private static class ToString implements Function<Long, String> {
@Override
public String apply(Long input) {
return input.toString();
}
}
private static class ToInteger implements Function<String, Integer> {
@Override
public Integer apply(String input) {
return Integer.parseInt(input);
}
}
}

Loading…
Cancel
Save