Skip to content

Consider adding support for chaining converters #22381

Closed
@jzheaux

Description

@jzheaux

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: supersededAn issue that has been superseded by anothertype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions