Issue #13606 has been updated by glebm (Gleb Mazovetskiy).


MSP-Greg (Greg L) wrote:
> Could be helpful, but some `Enumerators` are not ordered.  So how would `==` work for 'hash like' objects (assuming they're not based on a hash, which has an `==` operator)?
> 
> I suppose it could be considered 'restricted' to ordered collections...

Equal objects should produce equal results when used.
From this perspective on equality, enumerators that yield in different order should not be considered equal, even if they internally yield elements from an unordered collection.

If the enumerator yields in a different order every time it's called, then the comparison is not guaranteed to return the same result every time. This is a rare edge case though.

----------------------------------------
Feature #13606: Enumerator equality and comparison
https://bugs.ruby-lang.org/issues/13606#change-65145

* Author: glebm (Gleb Mazovetskiy)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
In Ruby, most objects are compared by value. What do you think about `Enumerator`s following the same pattern? I think this would greatly increase the expressiveness of Ruby.

Proposal:

Two `Enumerator`s should be considered equal (`==`) if they yield the same number of elements and these elements are equal (`==`).
If both of the `Enumerator`s are infinite, the equality operator never terminates.
`<=>` should be handled similarly.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>