From: kachick1@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:93128] [Ruby trunk Feature#15922] Enumerable#partition(pattern)
Date: Fri, 14 Jun 2019 03:40:26 +0000 (UTC) [thread overview]
Message-ID: <redmine.issue-15922.20190614034026.2386d0ab26080b82@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15922.20190614034026@ruby-lang.org
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/
parent reply other threads:[~2019-06-14 3:40 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <redmine.issue-15922.20190614034026@ruby-lang.org>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.issue-15922.20190614034026.2386d0ab26080b82@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).