[ruby-core:105827] [Ruby master Feature#16252] Hash#partition should return hashes
From:
"Dan0042 (Daniel DeLorme)" <noreply@...>
Date:
2021-10-27 14:07:11 UTC
List:
ruby-core #105827
Issue #16252 has been updated by Dan0042 (Daniel DeLorme).
I think it's ok that we don't have some particular rules for Enumerables to return their own class. Rather than consistently follow a decision, I think it's good to evaluate each case on its own merits. That said, I can certainly imagine Set#select/reject/partition returning Sets. But that would have to be a separate proposal, maybe related to #16989.
Hash#reject has returned a Hash since at least 1.8. Making Hash#select return a Hash has indeed been quite useful, and it would also be useful if #partition did the same. It's a bit surprising that `hash.select(&b) != hash.partition(&b).first`
----------------------------------------
Feature #16252: Hash#partition should return hashes
https://bugs.ruby-lang.org/issues/16252#change-94350
* Author: Dan0042 (Daniel DeLorme)
* Status: Open
* Priority: Normal
----------------------------------------
Hash#partition is implemented by Enumerable so it just returns two arrays of arrays
```ruby
{1=>2,3=>4}.partition{|k,|k==1} #=> [[[1, 2]], [[3, 4]]]
```
But I think it would make more sense to behave similarly to Hash#select and Hash#reject
```ruby
{1=>2,3=>4}.partition{|k,|k==1} #=> [{1=>2}, {3=>4}]
```
--
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>