[ruby-core:120914] [Ruby master Bug#21124] Enumerable#find called without block returns Enumerator without size

Issue #21124 has been reported by andrykonchin (Andrew Konchin). ---------------------------------------- Bug #21124: Enumerable#find called without block returns Enumerator without size https://bugs.ruby-lang.org/issues/21124 * Author: andrykonchin (Andrew Konchin) * Status: Open * ruby -v: 3.4.1 * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- 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: ```ruby [1, 2, 3].find.size # => nil ``` 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): ```ruby [1, 2, 3].each_entry.size # => 3 ``` -- https://bugs.ruby-lang.org/

Issue #21124 has been updated by mame (Yusuke Endoh). 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. ```ruby 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? ---------------------------------------- Bug #21124: Enumerable#find called without a block returns Enumerator without size https://bugs.ruby-lang.org/issues/21124#change-111804 * Author: andrykonchin (Andrew Konchin) * Status: Open * ruby -v: 3.4.1 * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- 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: ```ruby [1, 2, 3].find.size # => nil ``` 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): ```ruby [1, 2, 3].each_entry.size # => 3 ``` -- https://bugs.ruby-lang.org/

Issue #21124 has been updated by andrykonchin (Andrew Konchin). Yes, indeed. You are right. My bad. I was confused by result of `#to_a` called on such Enumerator: ```ruby [1, 2, 3].find.to_a # => [1, 2, 3] ``` ---------------------------------------- Bug #21124: Enumerable#find called without a block returns Enumerator without size https://bugs.ruby-lang.org/issues/21124#change-111824 * Author: andrykonchin (Andrew Konchin) * Status: Feedback * ruby -v: 3.4.1 * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- 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: ```ruby [1, 2, 3].find.size # => nil ``` 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): ```ruby [1, 2, 3].each_entry.size # => 3 ``` -- https://bugs.ruby-lang.org/

Issue #21124 has been updated by mame (Yusuke Endoh). Status changed from Feedback to Rejected Thanks for your confirmation. Closing. ---------------------------------------- Bug #21124: Enumerable#find called without a block returns Enumerator without size https://bugs.ruby-lang.org/issues/21124#change-111828 * Author: andrykonchin (Andrew Konchin) * Status: Rejected * ruby -v: 3.4.1 * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- 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: ```ruby [1, 2, 3].find.size # => nil ``` 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): ```ruby [1, 2, 3].each_entry.size # => 3 ``` -- https://bugs.ruby-lang.org/
participants (2)
-
andrykonchin (Andrew Konchin)
-
mame (Yusuke Endoh)