jastrachan | 1 Feb 10:59 2005
Picon

Re: [groovy-dev] Diff of Java and Groovy grammars

On 1 Feb 2005, at 09:40, Russel Winder wrote:
> On Tue, 2005-02-01 at 09:26 +0000, jastrachan@... wrote:
>
>> value = [1, 2, 3].collect { it * 2 }
>> assert value == [2, 4, 6]
>
> Isn't this called map in functional programming?  OK so map is a map 
> and
> so would be a bad name for map :-)

We started off using 'map' but then folks thought it'd make a map, so I 
changed it to 'collect' which matches the Smalltalk and Ruby naming 
convention.

> collect doesn't seem an intuitive
> name for this operation to me; collect seems more like grabbing things
> into a data structure.  apply might be better for this operation --
> apply the closure to each element.

Thats what each() does.

The difference is collect(), collects the values of the blocks into a 
list.

James
-------
http://radio.weblogs.com/0112098/


Gmane