Similar to this question Composing a Java Function and Consumer. What is the best way to functionally compose a java BiFunction and a Consumer? For example given some BiFunction<String, String,String> f and some Consumer c then doing f.andThen(c) ?
BiFunction<String, String, String> a = (a,b)->{return a+b;}
Consumer<String> b = x -> System.out.println(x);
Consumer<String> composed = a.andThen(b);
You can only compose
BiFunctions withFunctions. Then you may create aFunctionreturningVoidand get with a composition aBiFunctionin return:which will give you:
Function<...,Void>are slightly tricky as Java generics can only be instanciated with classes, not with primitive types asvoidis. You then need to return aVoidobject reference, but this type cannot be instanciated and the only value you can use isnull.At the end if you need a
BiConsumeryou can build it like this: