chain -> andThen?
Brian Goetz
brian.goetz at oracle.com
Fri Jun 28 13:20:56 PDT 2013
A related issue with chain/andThen for Consumers is whether it should do:
{ a.accept(v); b.accept(v); }
or
{ try { a.accept(v); } finally { b.accept(v); } }
On 6/28/2013 11:09 AM, Brian Goetz wrote:
> Working my way slowly through the API looking for rough edges...
>
> We eventually settled on "andThen" as the composition method for
> function-like things. This was chosen because it made the order
> explicit; "do my thing, and then this other thing." This method shows
> up on Comparator, XxxFunction, XxxOperator.
>
> There's a similar method on Consumer, called "chain", which means "let
> me have the argument, then pass it to some other Consumer". I think it
> makes sense to rename this to "andThen" as well.
>
> Consumer<String> logIt = s -> logger.log(s);
> Consumer<String> printIt = s -> System.out.println(s);
> Consumer<String> logAndPrint = logIt.andThen(printIt);
>
> instead of
>
> Consumer<String> logAndPrint = logIt.chain(printIt);
>
More information about the lambda-libs-spec-experts
mailing list