ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:93128] [Ruby trunk Feature#15922] Enumerable#partition(pattern)
       [not found] <redmine.issue-15922.20190614034026@ruby-lang.org>
@ 2019-06-14  3:40 ` kachick1
  0 siblings, 0 replies; only message in thread
From: kachick1 @ 2019-06-14  3:40 UTC (permalink / raw
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-06-14  3:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-15922.20190614034026@ruby-lang.org>
2019-06-14  3:40 ` [ruby-core:93128] [Ruby trunk Feature#15922] Enumerable#partition(pattern) kachick1

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).