On 2014-06-24 04:34, John Carter wrote:
So in Ruby and R and Scheme and... I have happily used map / collect for
years and years.

Lovely thing.

So I did the dumb obvious of

    string[] stringList = map!...;

And D barfed, wrong type, some evil voldemort thing again.

So..

    auto stringList = map!....;

and we're good..

and happily use it as
    foreach( s; stringList)....

Suddenly the words in the map! documentation made sense to me... unlike
Ruby, map doesn't allocate and populate an array. It just returns a lazy
range.

No array is allocated (unless I ask for one), it just does the lambda
when I want it in the foreach!

Cool! Very very cunning. Very light on resources.

I wished Ruby behaved that way quite often, especially when chaning multiple functions. In Ruby 2.0 there are lazy "map" and similar functions but I've heard they are slower than the eager ones.

--
/Jacob Carlborg

Reply via email to