From: Gordon Miller Date: 2002-11-27T00:28:29+09:00 Subject: Re: each_with_index & collect_with_index? > As for the second.... I recently appointed myself President of > Citizens for MWI [map_with_indices], Inc. (See > ). You may join the organization, > free of charge :-) Anyway, there's been a lot of talk of this at > various points; if you search for map_with_index and map_with_indices > on the ruby-talk archive, you'll see most of it. Matz has recently > indicated that he doesn't think there's a demand or need for it. I'm > still trying to keep the dream alive :-) > > Doing numerically oriented algorithms I find myself frequently doing something like the following: z = (1..5).to_a a = (0..5).to_a b = (0..5).to_a c = z.collect_with_index { |el, i| f(el, a[i], b[i]) } where f is some arbitrary function. For the most part I have to create c as an empty array and push elements on to the array as I'm doing z.each_index. The use of some sort of list comprehension-ish type of thing would be suitable as well, maybe something along the lines of a zip. z = a = as before b = c = zip (z, a, b).collect { |el| f(el[0], el[1], el[2]) } Though I think this was the discussion in another thread. -- Gordon James Miller Bit Twiddlers, Inc Software Architecture Architect gmiller@bittwiddlers.com (571)330-9012