Closed marcandre closed 9 months ago
A few consequences of this:
# before
[1, 2, Set[3, 4]].join('+') # => "1+2+#<Set: {3, 4}>" (useless)
[Set[1,2]].each{|x, y| p x, y} # => prints "#<Set: {1, 2}>", "nil"
[1, 2] <=> Set[1, 2] # => nil (ok)
[1, 2] <=> Set[2, 1] # => nil
# after
Set.alias_method :to_ary, :to_a
[1, 2, Set[3, 4]].join('+') # => '1+2+3+4' (better I think)
[Set[1,2]].each{|x, y| p x, y} # => prints "1, 2" (better I think)
[1, 2] <=> Set[1, 2] # => 0 (might be problematic?)
[1, 2] <=> Set[2, 1] # => -1
In any case one can't sort a mixed array of arrays and sets currently because Set#<=>
in not specialized, but there would not be a way to define it in a way that would work with Arrays anyways.
I would much like to go this way, but this could certainly involve a potentially big incompatibility.
flatten
, flat_map
, [set1, set2, *(set3 if cond)]
, etc.
I'd like to check how it affects Rails and some popular Rails apps before moving forward.
@knu Did you have a chance to look into this?
I cannot estimate how this would cause an impact on private / in-house apps, but at the very least I want to make sure this does not break popular apps like gitlab, mastodon and discourse. What do you think?
These are good test bases 👍
I you are too worried, then we could wait until Ruby 3.0 is released, then make a separate set
gem release with this feature?
I'm closing this because of the compatibility issue.
[Fix #16990]