chain -> andThen?

Brian Goetz brian.goetz at oracle.com
Fri Jun 28 08:09:26 PDT 2013


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