groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Dawson <>
Subject Re: [GEP] Concatenative Method Calls
Date Sun, 25 Feb 2018 14:33:53 GMT

I conceptually like this a lot, its a very dataflow style approach to the

Conceptually, its similar to

[1,2,3].map { it * 2 }.each { println it }

Or in a unix shell

cat file | grep x | echo

Or perhaps something more reactive streams ish.

In any case, its re-arranging the function call order to visually be in the
order that it actually happens, rather than inside out, as is "normal"

You could imagine the above chained method calls (which is given to us by
extension methods on groovy collections) as something more generic using
this form.  Imagine that we have a new collection type, not implementing
the java collections api (like one of the dodgy SAX libraries or
something). You can't do the method chaining transformation above.  What
you want to do is to arrange a pipeline of function calls.

Instead of having to do something contrived like


You could do something more like

[1,2,3] => timesTwo => printIt

So, with "generic" methods, unattached to any types via extension methods,
you gain much of the same benefit as method chained transforms on
Collections, but *everywhere*.

So, I'm certainly a fan of *something* like this, even if the fat arrow
syntax might not be the best/ one I'd choose necessarily.

Personally, I'd like a " | ", if it can be made to fit in somehow, as thats
a very familiar syntax for the concept from the shell world


On 25 February 2018 at 14:17, mg <> wrote:

> Intuitively the => arrow-operators point in the wrong direction, since I
> feel foo gets applied to x, etc...
> How would additional arguments to an intermediate function be handled in
> this syntax ?
> -------- Urspr√ľngliche Nachricht --------
> Von: "Daniel.Sun" <>
> Datum: 25.02.18 14:38 (GMT+01:00)
> An:
> Betreff: [GEP] Concatenative Method Calls
> Hi all,
>      I propose to introduce Concatenative Method Calls to Groovy. It can
> make code more readable, for example:
> Currently we write method calls like:
> y = foo(x)
> z = bar(y)
> w = baz(z)
> OR
> w = baz(bar(foo(x)))
> Concatenative Method Calls(inspired by [1]):
> w = x => foo => bar => baz
>       Any thoughts?
> Cheers,
> Daniel.Sun
> [1]
> --
> Sent from:

View raw message