Closed
Description
It would be nice to have some support for chaining converters:
public interface Converter<S, T> {
// ...
default <U> Converter<S, U> andThen(Converter<T, U> andThen) {
return source -> andThen.convert(this.convert(source));
}
}
Then, a user could more easily compose them:
Converter<A, B> aToB = ...;
Converter<B, C> bToC = ...;
Converter<A, C> aToC = aToB.andThen(bToC);
This is a modest improvement on:
Converter<A, C> aToC = source -> bToC.convert(aToB.convert(source));
in that code using andThen
will read in the correct order, e.g. "do A then B" instead of "B.do(A.do)".
I'd be happy to submit a PR, if it's agreed that it's a reasonable improvement.