From: "zverok (Victor Shepelev)" Date: 2021-10-27T07:03:36+00:00 Subject: [ruby-core:105818] [Ruby master Feature#16252] Hash#partition should return hashes Issue #16252 has been updated by zverok (Victor Shepelev). I am afraid we don't have some particular rules for Enumerables to return their own class: ```ruby Set[*1..8].select(&:odd?) # => [1, 3, 5, 7] -- not a Set ``` Making `Hash#select` and `#reject` return hashes was an ad-hoc decision (and quite useful at that!); maybe it would be good to consistently follow this decision for some core collections? FWIF, I once [made a gem](https://github.com/zverok/idempotent_enumerable) to do that for any collection of your liking, and while working on it, I identified lists of methods where it is probably desirable to return same class: [methods returning singular collection](https://github.com/zverok/idempotent_enumerable#methods-that-return-single-collection) and [methods returning several collections](https://github.com/zverok/idempotent_enumerable#methods-that-return-or-emit-several-collections). ---------------------------------------- Feature #16252: Hash#partition should return hashes https://bugs.ruby-lang.org/issues/16252#change-94342 * 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: