From: Robert Klemme Date: 2005-07-08T22:35:47+09:00 Subject: Re: accessing index inside map Michael Campbell wrote: > On 7/8/05, David A. Black wrote: >> Hi -- > >> I'd still like to see #man_with_index added to Enumerable. > > "index" implies an ordering, which maps by definition don't have. > Shouldn't that be something along the lines of "#map_with_key"? > > But point taken; it seems a natural thing, regardless of actual name, > to be in Enumerable. Key is ambiguous with Hashes... Apart from that: I'm not really sure whether I like that idea. The basic property of an Enumerable is that it can be enumerated with each. There are no guarantees about order etc. each_with_index is really only there to simplify counting. If you want map_with_index then you'd probably have to provide inject_with_index, find_with_index etc. Personally I think that map_with_index is rarely used to justify adding this to the std lib. Just my 0.02 EUR of course. Btw, another variant for mapping with index: enum.inject([]) {|ar,el| ar << ([0,3].include?(ar.size) ? el : el*2) } Kind regards robert