Actions
Bug #21124
closedEnumerable#find called without a block returns Enumerator without size
Bug #21124:
Enumerable#find called without a block returns Enumerator without size
Description
When a collection's size is known then enumerator that iterates it usually has size (that's #size returns a collection size).
But an enumerator returned by Enumerable#find called without a block doesn't have size:
Expected result here is 3.
Usually similar methods in the Enumerable module return enumerators with size (when these enumerators for instance iterate the collection itself):
Updated by andrykonchin (Andrew Konchin) over 1 year ago
- Subject changed from Enumerable#find called without block returns Enumerator without size to Enumerable#find called without a block returns Enumerator without size
Updated by mame (Yusuke Endoh) over 1 year ago
I really don't understand what the "size" of the Enumerator returned by find means, but I guess it returns nil, which means "unknown size", because the number of calls depends on the return value of the block.
i = 0; [1, 2, 3].find.each {|x| i += 1; true }; p i #=> 1
i = 0; [1, 2, 3].find.each {|x| i += 1; false }; p i #=> 3
Why did you expect 3?
Updated by nobu (Nobuyoshi Nakada) over 1 year ago
- Status changed from Open to Feedback
Updated by andrykonchin (Andrew Konchin) over 1 year ago
Updated by mame (Yusuke Endoh) over 1 year ago
- Status changed from Feedback to Rejected
Thanks for your confirmation. Closing.
Actions