From: "Dan0042 (Daniel DeLorme)" <noreply@...>
Date: 2021-11-18T15:54:00+00:00
Subject: [ruby-core:106149] [Ruby master Feature#16252] Hash#partition should return hashes

Issue #16252 has been updated by Dan0042 (Daniel DeLorme).


knu (Akinori MUSHA) wrote in #note-6:
> I only wish `partition` had been changed this way along with `select`/`reject`...

If most people agree "it should have been this way" then why not bite the bullet and fix to the behavior that "should have been". Better late than never.

I agree it's hard to estimate the damage. Based on the code search above my best guess is "reasonable". But isn't that what release candidates are for? In the past matz has often said "let's try it" and revert if it causes too many problems, like freezing Symbol#to_s. I think this is one of those times.

I get the feeling that a new method like `partition_h` would only be making this problem (mere annoyance?) worse.

----------------------------------------
Feature #16252: Hash#partition should return hashes
https://bugs.ruby-lang.org/issues/16252#change-94750

* 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>