There is one drawback to using compose and andThen . You must have explicit variables, so you cannot use method references, for example:
(Person::getAddress).andThen(Address::getCountry)
It will not be compiled. What a pity!
But you can define the utility function and use it happily:
public static <A, B, C> Function<A, C> compose(Function<A, B> f1, Function<B, C> f2) { return f1.andThen(f2); } compose(Person::getAddress, Address::getCountry)
Mikhail Golubtsov Sep 29 '15 at 8:09 2015-09-29 08:09
source share