[ruby-core:93128] [Ruby trunk Feature#15922] Enumerable#partition(pattern)
From:
kachick1@...
Date:
2019-06-14 03:40:26 UTC
List:
ruby-core #93128
Issue #15922 has been reported by kachick (Kenichi Kamiya).
----------------------------------------
Feature #15922: Enumerable#partition(pattern)
https://bugs.ruby-lang.org/issues/15922
* Author: kachick (Kenichi Kamiya)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
* `any?` `all?` `one?` `none?` already can take pattern argument. ref: https://bugs.ruby-lang.org/issues/11286
* `select` `reject` is proposed to take pattern argument. ref: https://bugs.ruby-lang.org/issues/14197
I would like to use `partition` with pattern argument for consistency.
```ruby
module Enumerable
alias_method :original_partition, :partition
def partition(*args, &block)
case args.size
when 1
pattern = args.first
original_partition do |element|
pattern === element
end
when 0
original_partition(&block)
else
raise ArgumentError
end
end
end
[1, 2, 3.3, 4, 5.5].partition(Integer)
#=> => [[1, 2, 4], [3.3, 5.5]]
```
--
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>