<div dir="ltr">In Groovy, collect() is sometimes used like map() and sometimes like toCollection().<div><br></div><div style>I don't know why they didn't just call it map(), but oh well...</div><div style><br></div>
<div style>I would be upset if we wanted to use map() for something other than map() but I'm not bothered by our use of collect(). In my view, collect() has no standard meaning. Inconsistencies cannot be avoided.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jan 29, 2013 at 3:49 PM, Raab, Donald <span dir="ltr"><<a href="mailto:Donald.Raab@gs.com" target="_blank">Donald.Raab@gs.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Folks using GS Collections or Apache Commons can write the following:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal">collection.collect(Thing::getFoo).stream().collect(groupingBy(Foo::getBar))<u></u><u></u></p>
<p class="MsoNormal">CollectionUtils.collect(collection, Thing::getFoo).stream().collect(groupingBy(Foo::getBar))<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I’m not exactly sure how Groovy and Java 8 will mix syntax wise so can’t give an example.</span><u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I would assume that no one would like to use the name “map” here, as it would be hard to teach map, because the name would be overloaded:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal">collection.map(Thing::getFoo).stream().map(groupingBy(Foo::getBar))<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">The method “map” has a meaning in languages/libraries outside of Streams and retains more or less the same meaning inside of Streams in our case.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">In Smalltalk, Groovy, Ruby, Apache Commons Collections, GS Collections the method named “collect” is synonymous to “map” and “transform”. That’s what I believe will make it hard to teach/use here.<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Joe Bowbeer [mailto:<a href="mailto:joe.bowbeer@gmail.com" target="_blank">joe.bowbeer@gmail.com</a>] <br>
<b>Sent:</b> Tuesday, January 29, 2013 6:24 PM<br><b>To:</b> Raab, Donald [Tech]<br><b>Cc:</b> Brian Goetz; <a href="mailto:lambda-libs-spec-experts@openjdk.java.net" target="_blank">lambda-libs-spec-experts@openjdk.java.net</a>; Motlin, Craig P. [Tech]<br>
<b>Subject:</b> Re: Collectors update<u></u><u></u></span></p></div></div><div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">I like the way collect() parses. I think aggregate() is more descriptive but also less appealing.<u></u><u></u></p>
<div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">Given that collect() is a method of Stream, I don't think it will be particularly challenging to teach.<u></u><u></u></p></div><div><p class="MsoNormal">
<u></u> <u></u></p></div><div><p class="MsoNormal">I wouldn't object to aggregate() though.<u></u><u></u></p></div></div><div><p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p><div><p class="MsoNormal">
On Tue, Jan 29, 2013 at 2:55 PM, Raab, Donald <<a href="mailto:Donald.Raab@gs.com" target="_blank">Donald.Raab@gs.com</a>> wrote:<u></u><u></u></p><p class="MsoNormal">Having the method name "collect" is going to make it very hard to teach folks to use the streams API with GS Collections as it means something different than our "collect" method. It may equally cause problems for folks using Groovy, Apache Commons Collections and JRuby as well.<br>
<br><a href="http://groovy.codehaus.org/groovy-jdk/java/util/Collection.html#collect(groovy.lang.Closure)" target="_blank">http://groovy.codehaus.org/groovy-jdk/java/util/Collection.html#collect(groovy.lang.Closure)</a><br>
<a href="http://commons.apache.org/collections/api-release/org/apache/commons/collections/CollectionUtils.html" target="_blank">http://commons.apache.org/collections/api-release/org/apache/commons/collections/CollectionUtils.html</a><br>
<br>We've gone through the names accumulate, tabulate (not sure if there are others)...<br><br>I know there is a dwindling list of good names, and I'll settle when there are none better, but this particular name has 30+ years of prior art in Smalltalk influenced circles. It is one of the most commonly used methods in our library and these other languages/libraries.<br>
<br>Again, I'd like to propose "aggregate" as an alternative.<br><br>stream.aggregate(groupingBy(Foo::getBar))<u></u><u></u></p><div><div><p class="MsoNormal"><br><br>> -----Original Message-----<br>> From: <a href="mailto:lambda-libs-spec-experts-bounces@openjdk.java.net" target="_blank">lambda-libs-spec-experts-bounces@openjdk.java.net</a> [mailto:<a href="mailto:lambda-" target="_blank">lambda-</a><br>
> <a href="mailto:libs-spec-experts-bounces@openjdk.java.net" target="_blank">libs-spec-experts-bounces@openjdk.java.net</a>] On Behalf Of Brian Goetz<br>> Sent: Tuesday, January 29, 2013 5:35 PM<br>> To: <a href="mailto:lambda-libs-spec-experts@openjdk.java.net" target="_blank">lambda-libs-spec-experts@openjdk.java.net</a><br>
> Subject: Collectors update<br>><br>> I've done some refactoring in Collectors to address some issues,<br>> including approachability issues that were raised by Kevin. See if you<br>> like them.<br>><br>
> 1. Rename to more verby names. We now have<br>> groupingBy<br>> groupingReduce<br>> joiningWith<br>> partitioningBy<br>><br>> instead of groupBy/mappedTo/partition. This is designed to make it<br>
> more clear what is going on when you read code like:<br>><br>> stream.collect(groupingBy(Foo::getBar))<br>><br>> by making it clear that groupingBy is not an action but a way of<br>> describing the desired collecting.<br>
><br>> 2. Break groupBy into two groups, groupingBy and groupingReduce.<br>> While the distinction is somewhat arbitrary since groupBy *is* a<br>> reduce, it is now more consistent with the method naming on Stream.<br>
><br>> 3. Rename mappedTo(T->U) to joiningWith.<br>><br>> 4. Rejigger Partition to return an array again, with an explicit<br>> lambda (which will likely be an array ctor ref) to make the array.<br>> Eliminated the silly Partition class.<br>
><br>> 5. Add more tests -- we now have full test coverage on groupingXxx but<br>> not yet the others.<u></u><u></u></p></div></div></div><p class="MsoNormal"><u></u> <u></u></p></div></div></div></div></div></div>
</blockquote></div><br></div>