K
Kristof Bastiaensen
Hi,
That's all nice and esoteric, but I don't see why it is a
reason against empty? or size. In fact, if that would be
important, than the other methods in Enumerable shouldn't
also be there. Take for example the following:
require "enumerator"
to_enumloop).map
There is nothing that prevents that. In fact I currently have
irb eating up slowly all the memory. Does that mean there
shouldn't be a map method? I think it is possible to find
pathological cases for the other methods in Enumerable
(I'll leave that as an exercise for the reader).
IMO the reason against size is that is not possible to implement
efficiently. As for empty?, I don't know. I find it useful,
and as shown by other people easy to implement.
Cheers,
KB
Hm, that's true. Although that argument would not stop me from advocating
#empty? Runtimes of each enumerable class differ anyway. Classes
override this method usually anyway. It's a different case with #size
which has been shown to not terminate for certain non totally esoteric
implementations.
Here's maybe another reason: emty? and size both depend on an Enumerable
with a deterministic amount of elements. This need not always be the
case:
class RandEnum
include Enumerable
def each
rand(10).times { yield rand 20 }
self
end
end
That's all nice and esoteric, but I don't see why it is a
reason against empty? or size. In fact, if that would be
important, than the other methods in Enumerable shouldn't
also be there. Take for example the following:
require "enumerator"
to_enumloop).map
There is nothing that prevents that. In fact I currently have
irb eating up slowly all the memory. Does that mean there
shouldn't be a map method? I think it is possible to find
pathological cases for the other methods in Enumerable
(I'll leave that as an exercise for the reader).
IMO the reason against size is that is not possible to implement
efficiently. As for empty?, I don't know. I find it useful,
and as shown by other people easy to implement.
Cheers,
KB