gotoken / math.sci.hokudai.ac.jp (GOTO Kentaro) writes: > In message "[ruby-talk:01190] Re: Enumerable and index" > on 00/01/27, Dave Thomas <Dave / thomases.com> writes: > >I guess this is the difference between Iterable and > >Enumerable. Iterable simply implies a .each method, while Enumerable > >means that .each stops and is repeatable. So, IO would be Iterable, > >and Array would be Enumerable. I guess that Enumerable < Iterable. > > > >(And no, Iterable is most definitely _not_ a word ;-) > > :-) > > >From the other point of veiw, most methods of Enumerable requires of > finiteness while each can work for possibly infinite stream. In the > term of computer science, enumerable is referred as existence of a map > from integer to object. In this sense, I guess IO is proper > Enumerable. On the other hand, classes else IO is Finite. I guess > Finite < Enumerable. But Finite is not "-able" and most class is > finite whereas they don't have .each. If I understand your argument, then, enumerable _should_ have index and size replaced, as Enumerable maps to integers, and therefore there'll always be a value for size etc. On the other hand, if index is removed, then shouldn't max, min, sort and the like be removed too, as they also assume a finite input stream? Perhaps the real different is between Classes where .each is a pure function (like array) and one where .each has side effects (such as IO). You can call Array#each as many times as you like, but IO#each just once (in the normal case). Maybe there should be two interfaces: .each and .each!. Standard Enumerable uses .each, and therefore can't work with IO. MutatingEnumerable uses .each! (which maps to .each if otherwise undefined), allowing it to work with IO. Regards Dave