chain -> andThen?

Ali Ebrahimi ali.ebrahimi1781 at
Fri Jun 28 09:25:38 PDT 2013

Hi, good catch.
I think chain would be better name for Function's compose method.
chain works based on stack model and fog in Math(fog(x) = f(g(x))). LIFO
=> push
andThen works based on queue model. FIFO  => enqueue

On Fri, Jun 28, 2013 at 7:39 PM, Brian Goetz <brian.goetz at> 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-observers mailing list