What is the best way to functionally compose a java Function
and a Consumer
?
For example given some Function<Object, String> f
and some Consumer<String> c
then doing f.andThen(c)
would feel natural, however that is not how the interfaces work.
The two options I see are either replace Consumer<String> c
with Function<String, Void> c
or change Consumer<String> c
to BiConsumer<Function<Object, String>, String> c
and do
accept(Function<Object, String> f, Object o) {
String thing = f.apply(o);
//do something with thing
}
Is one of these better than the other? Is there a better way?