<div dir="ltr">In Groovy, collect() is sometimes used like map() and sometimes like toCollection().<div><br></div><div style>I don&#39;t know why they didn&#39;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&#39;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">&lt;<a href="mailto:Donald.Raab@gs.com" target="_blank">Donald.Raab@gs.com</a>&gt;</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:&quot;Calibri&quot;,&quot;sans-serif&quot;;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:&quot;Calibri&quot;,&quot;sans-serif&quot;;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:&quot;Calibri&quot;,&quot;sans-serif&quot;;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:&quot;Calibri&quot;,&quot;sans-serif&quot;;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:&quot;Calibri&quot;,&quot;sans-serif&quot;;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:&quot;Calibri&quot;,&quot;sans-serif&quot;;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:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;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:&quot;Calibri&quot;,&quot;sans-serif&quot;;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:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> 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&#39;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&#39;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 &lt;<a href="mailto:Donald.Raab@gs.com" target="_blank">Donald.Raab@gs.com</a>&gt; wrote:<u></u><u></u></p><p class="MsoNormal">Having the method name &quot;collect&quot; 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 &quot;collect&quot; 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&#39;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&#39;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&#39;d like to propose &quot;aggregate&quot; as an alternative.<br><br>stream.aggregate(groupingBy(Foo::getBar))<u></u><u></u></p><div><div><p class="MsoNormal"><br><br>&gt; -----Original Message-----<br>&gt; 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>
&gt; <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>&gt; Sent: Tuesday, January 29, 2013 5:35 PM<br>&gt; To: <a href="mailto:lambda-libs-spec-experts@openjdk.java.net" target="_blank">lambda-libs-spec-experts@openjdk.java.net</a><br>
&gt; Subject: Collectors update<br>&gt;<br>&gt; I&#39;ve done some refactoring in Collectors to address some issues,<br>&gt; including approachability issues that were raised by Kevin.  See if you<br>&gt; like them.<br>&gt;<br>
&gt; 1.  Rename to more verby names.  We now have<br>&gt;    groupingBy<br>&gt;    groupingReduce<br>&gt;    joiningWith<br>&gt;    partitioningBy<br>&gt;<br>&gt; instead of groupBy/mappedTo/partition.  This is designed to make it<br>
&gt; more clear what is going on when you read code like:<br>&gt;<br>&gt;    stream.collect(groupingBy(Foo::getBar))<br>&gt;<br>&gt; by making it clear that groupingBy is not an action but a way of<br>&gt; describing the desired collecting.<br>
&gt;<br>&gt; 2.  Break groupBy into two groups, groupingBy and groupingReduce.<br>&gt; While the distinction is somewhat arbitrary since groupBy *is* a<br>&gt; reduce, it is now more consistent with the method naming on Stream.<br>
&gt;<br>&gt; 3.  Rename mappedTo(T-&gt;U) to joiningWith.<br>&gt;<br>&gt; 4.  Rejigger Partition to return an array again, with an explicit<br>&gt; lambda (which will likely be an array ctor ref) to make the array.<br>&gt; Eliminated the silly Partition class.<br>
&gt;<br>&gt; 5.  Add more tests -- we now have full test coverage on groupingXxx but<br>&gt; 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>