D
David A. Black
Hi --
This reminds me of the early 1.9.0 thing, where you could do:
array = [1,2,3,4]
enum = array.enum_formap, &lambda {|x| x * x })
enum.next # 1
enum.next # 4
etc. (That's ruby 1.9.0 (2008-03-01 revision 15660)
[i686-darwin9.2.0].) To be honest, when that disappeared, it seemed to
me to do away with a great deal of the usefulness of enumerators.
Given that you can no longer attach a block to an enumerator when you
create the enumerator, I don't think there are any actual use cases
for the fact that map returns an enumerator (or at least very, very
few). You can't do this, for example (following the above example):
enum.select {|x| x > 1 } # [4, 9, 16]
David
--
The Ruby training with D. Black, G. Brown, J.McAnally
Compleat Jan 22-23, 2010, Tampa, FL
Rubyist http://www.thecompleatrubyist.com
David A. Black/Ruby Power and Light, LLC (http://www.rubypal.com)
The OP was asking whether mapfoo) should return an Array or an
Enumerator. I was trying to say that if you're ambivalent about this,
one logical conclusion (or extreme viewpoint) is that you could always
return an Enumerator, even for
map { |x| x*x }
I wasn't saying that Ruby does anything like this, and it's a tangent to
the original thrust of mapfoo).
This reminds me of the early 1.9.0 thing, where you could do:
array = [1,2,3,4]
enum = array.enum_formap, &lambda {|x| x * x })
enum.next # 1
enum.next # 4
etc. (That's ruby 1.9.0 (2008-03-01 revision 15660)
[i686-darwin9.2.0].) To be honest, when that disappeared, it seemed to
me to do away with a great deal of the usefulness of enumerators.
Given that you can no longer attach a block to an enumerator when you
create the enumerator, I don't think there are any actual use cases
for the fact that map returns an enumerator (or at least very, very
few). You can't do this, for example (following the above example):
enum.select {|x| x > 1 } # [4, 9, 16]
David
--
The Ruby training with D. Black, G. Brown, J.McAnally
Compleat Jan 22-23, 2010, Tampa, FL
Rubyist http://www.thecompleatrubyist.com
David A. Black/Ruby Power and Light, LLC (http://www.rubypal.com)