Collectors update (original) (raw)

Kevin Bourrillion kevinb at google.com
Thu Jan 31 14:24:20 PST 2013


Just throwing this out there: Have we already strongly considered the heretical idea of just naming it reduce()?

It's distinguished from the others by the type it takes (and that's not a lambda-able type so no worries on that front).

It may not be implemented functionally, as 'reduce' usually is (to those users already familiar with the term), but other than that... it's conceptually very similar.

If we were uncomfortable calling the type accepted Reducer, perhaps there's... MutatingReducer. Bleh.

Of the others, I think aggregate(Aggregator) should be on the table. I also think collect(Collector) is still on the table. I don't think it's * too* bad, but "collect with a collector to get a collection" is pretty overloaded...

On Wed, Jan 30, 2013 at 12:42 PM, Raab, Donald <Donald.Raab at gs.com> wrote:

In my opinion, collect should return a collection. It should not reduce to any result. In the interest of time, here's a stab at an alternative list I came up with using the powers of thesaurus yesterday:

into gather assemble summarize The functionality currently called collect feels more like injectInto/inject in Smalltalk/Ruby/Groovy, but nothing is being injected into the method collect directly, but by the Collector (the R in makeResult()). InjectInto/inject is the equivalent of foldLeft. I would be less concerned over using injectInto or inject than collect, as at least it seems similar enough in that it can return any value, determined by the injector (currently called Collector). But folks here might consider injectInto and foldLeft too cryptic, so I decided to just shorten to into in the above list.

http://groovy.codehaus.org/groovy-jdk/java/util/Collection.html#inject(groovy.lang.Closure) In the binary release I have (not sure if this is different in current source), two of the overloaded versions of the method collect create a FoldOp today (a hint), and the Collector interface has a method called accumulate and combine and is called MutableReducer in the javadoc. The methods named reduce also create FoldOp instances. This makes reduce and collect seem eerily similar. I find this a little confusing, but I have tried my best anyway to name that which by any other name seems to be more like injectInto/mapReduce/foldL/aggregate/etc. to me. Thoughts? > > I will do > > my best and find an alternative that everyone else here likes. > > Thanks. > > -Doug

-- Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb at google.com



More information about the lambda-libs-spec-observers mailing list