chain -> andThen?

David Holmes david.holmes at oracle.com
Sun Jul 7 19:15:02 PDT 2013


On 29/06/2013 6:20 AM, Brian Goetz wrote:
> 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); } }
>

The former.

This applies on all the composite "actions" in the different interfaces.

David

>
> 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