From: Nicholas Milkovits Date: 2007-04-02T23:00:14+09:00 Subject: Re: Map Or Collect Redux Enumerable#select is certainly what I was thinking of. Certainly having both collect and map would make it easier for developers coming from other languages to pick up ruby but often times I see code where these methods are both used. Ruby reads very nice and I prefer to use map just because it semantically makes more sense to me if I am performing some sort of transformation on the array elements. (Plus it is shorter to type : ) ). When I think of collecting elements I think of gathering or *selecting* certain elements, collect just does not seem to imply that the elements will be changed in any way to me. On 4/2/07, Robert Klemme wrote: > On 02.04.2007 15:17, Nicholas Milkovits wrote: > > I think the aliases are there for a good syntactic reason. It seems > > to me that if you are just filtering out items which meet a certain > > criteria from one array to be put into a new one (say all elements > > which are even numbers) then you are collecting. > > No, you are actually *selecting*. > > > If you're actually > > performing a transformation on the elements then you are mapping one > > array space onto another. > > #map and #collect behave identical. They are just there to make people > coming from different programming languages feel at home with Ruby faster. > > > example > > > > arr = [1, 2, 3, 4, 5] > > arr.collect { |x| if x%2 == 0 then x end }.compact > > => [2, 4] > > # Seems like maybe it should be .filter instead of .collect > > No, use #select - much more efficient and it does exactly what you are > trying to accomplish above. > > Regards > > robert > > > PS: for the record, I use #map as it is shorter to type and I am laz > >