groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dinko Srko─Ź <>
Subject Re: Adding map, reduce, filter as aliases for collect, inject, grep methods
Date Sun, 01 Nov 2015 14:36:47 GMT
On 1 November 2015 at 08:14, Pascal Schumacher <> wrote:
> Hi everybody,
> what about adding the more common names of map/reduce/filter for the Ruby
> inspired collect/inject/grep methods?

This has been debated before, though I don't remember the conclusion,
if there was any.

The analog of `filter` would probably be `findAll`. `grep` is something else.

There are other, similar or similarly named methods in Groovy -
collectMany, collectNested, collectEntries, findResults come to mind.
Should they be aliased as well and what would their aliases be?
`collectMany` can clearly be `flatMap`, but others may not be so

> Imho these names are more descriptive and would make it easier for
> beginners.

Not necessarily more descriptive, but certainly more common. Apart
from Smalltalk, Ruby and Groovy, I don't know of another language that
uses e.g. `inject` (though it may be that my knowledge is just not
wide enough).

> What do you think?

I currently know of exactly one case of synonyms in the Groovy stdlib:
`with` <-> `identity`. In Ruby this could be called standard practice.
I remember back in 2004 (or about), when I was learning Ruby, that
this practice had not been entirely helpful, while juggling with
different concepts that Ruby introduced upon unsuspecting newb.

There is one more point - while reading someone else's code one has to
be familiar with both variants. So, beginners might find it easier to
find what they're looking for, but it might introduce a slight
confusion as well. In the end, one would need to learn the names as
well as the aliases.


> -Pascal

View raw message