On Wed, 27 Nov 2002, Gordon Miller wrote:


[snip]
G> c = z.collect_with_index { |el, i| f(el, a[i], b[i]) }
[snip]


  c = collect %w(0 1 2), %w(zero one two) do |a, b|
	[a,b]
      end

  p c				>> [["0", "zero"], ["1", "one"], ["2", "two"]]


  c = collect_with_index %w(0 1 2), %w(zero one two) do |idx, a, b|
	[idx, a,b]
      end

  p c				>> [[0, "0", "zero"], [1, "1", "one"], [2, "2", "two"]]


imho, this syntax is cleaner.


check out :


  http://eli.fsl.noaa.gov/lib/ruby/site_ruby/1.6/enumerable.rb


for the source code.


i got the iterator class from Pit Capitain <pit / capitain.de>, it seems very
efficient.  thanks Pit!


this allowed me to write Kernel#each (*enumerables, &block), Kernel#collect
(*enumerables, &block), Kernel#collect_with_index (*enumerables, &block)
**very** easily.  you could write 'zip' if you wanted to in around 10 lines.
personally i like the Kernel# namespace for these methods but i realize this
is a religious issue.

-a


-- 

 ====================================
 | Ara Howard
 | NOAA Forecast Systems Laboratory
 | Information and Technology Services
 | Data Systems Group
 | R/FST 325 Broadway
 | Boulder, CO 80305-3328
 | Email: ahoward / fsl.noaa.gov
 | Phone:  303-497-7238
 | Fax:    303-497-7259
 ====================================