I’m a Python programmer and I’m trying Ruby now. I love Smalltalk and
Ruby’s “OO-ness” and likeness to Smalltalk gives me warm feelings. I’m
really excited about Ruby, enough to consider switching to it from
Python.
However, I was messing around yesterday with Ruby and looked
everywhere for some functionality close to the map() function on
python, but couldn’t find it anywhere. For those that don’t know the
function, here’s a raw example:
a = [1,2,3]
b = [4,5,6]
map(None, a, b) --> [[1,4],[2,5],[3,6]]
The first parameter above can be any function taking 2 parameters and
returning a tuple. A ruby equivalent would be something of the form:
map(a,b) {|i,j| i,j}
I thought about taking the arrays on the argument, generate iterators
for each of them, and then calling the iterators, splicing the result
into a resulting array, but could some real Ruby programmer post
some solution here?
Best regards,
Roberto “Wolfox” Amorim
Software Developer - Brazil
I thought about taking the arrays on the argument, generate iterators
for each of them, and then calling the iterators, splicing the result
into a resulting array, but could some *real* Ruby programmer post
some solution here?
I’m a Python programmer and I’m trying Ruby now. I love Smalltalk and
Ruby’s “OO-ness” and likeness to Smalltalk gives me warm feelings. I’m
really excited about Ruby, enough to consider switching to it from
Python.
However, I was messing around yesterday with Ruby and looked
everywhere for some functionality close to the map() function on
python, but couldn’t find it anywhere. For those that don’t know the
function, here’s a raw example:
a = [1,2,3]
b = [4,5,6]
map(None, a, b) → [[1,4],[2,5],[3,6]]
Hmmm… this seems to be what the proposed ‘zip’ method on Array would do.
It’s not included yet, but apparently has been approved.
…
However, I was messing around yesterday with Ruby and looked
everywhere for some functionality close to the map() function on
python, but couldn’t find it anywhere. For those that don’t know the
function, here’s a raw example:
a = [1,2,3]
b = [4,5,6]
map(None, a, b) → [[1,4],[2,5],[3,6]]
The better way to do this in Python is with “zip”. map() is better for
applying a function to one or more lists. If zip had been invented when
map was invented, map probably wouldn’t even have this map(None) feature.
I’m a Python programmer and I’m trying Ruby now. I love Smalltalk and
Ruby’s “OO-ness” and likeness to Smalltalk gives me warm feelings. I’m
really excited about Ruby, enough to consider switching to it from
Python.
However, I was messing around yesterday with Ruby and looked
everywhere for some functionality close to the map() function on
python, but couldn’t find it anywhere. For those that don’t know the
function, here’s a raw example:
a = [1,2,3]
b = [4,5,6]
map(None, a, b) → [[1,4],[2,5],[3,6]]
Hmmm… this seems to be what the proposed ‘zip’ method on Array would do.
It’s not included yet, but apparently has been approved.