chain -> andThen?

Remi Forax forax at univ-mlv.fr
Sat Jun 29 02:18:38 PDT 2013


On 06/28/2013 10:20 PM, 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 later is weird, no ?

Rémi

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