From: "Ara.T.Howard" Date: 2005-05-22T23:51:20+09:00 Subject: Re: join not in Enumerable On Sun, 22 May 2005, David A. Black wrote: > I see it the other way. "Index" means different things to different > enumerables. I don't like the idea of having Enumerable define index as > consecutive integers slapped onto the elements. I'd rather defer that to > the classes -- as, indeed, it is, with the strange exception of > each_with_index. hmm. i don't really see any possible implication with orderedness or index confustion within enumerable methods - i guess it's because i think of enumerable as, and only as, countable. because of that - no orderedness is implied : eg. in what order would you count a dozen eggs? doesn't much matter really, so long as you start at 0 and end at 11. [ ;-) ] - which brings me to the second point. the notion of index is, and always is, with enumerable methods, the notion of my index in the the current count. again, with the eggs example, if i'm counting a dozen eggs then, at any point, i can tell you which egg i'm on : the 3rd, the 8th, etc. this is obviously my index into the count. > In general, I think the design is a good one: Enumerable contains the most > common methods (plus each_with_index :-) and specialized behavior is left to > the classes. Arrays provide a kind of normalized representation through > which some of those behaviors can be achieved -- i.e., with #to_a you can > hook into a lot of them. Finer granularity would certainly be possible; > there's been discussion, for example, of separating Iterable (or something > like that) out of Enumerable. so i guess we are on the same page here except i'd call Iterable Countable and then the each_with_index method fits right back in ;-) i can understand someone seeing it an not entirely orthogonal, why not simply track your own 'index'?, yet the notion seems no natural when wants to do something like def sample collection ret = [] collection.each_with_index{|x,i| (i >= 42 ? break ; (ret << x))} ret end kind regards. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso ===============================================================================