[#102393] [Ruby master Feature#17608] Compact and sum in one step — sawadatsuyoshi@...

Issue #17608 has been reported by sawa (Tsuyoshi Sawada).

13 messages 2021/02/04

[#102438] [Ruby master Bug#17619] if false foo=42; end creates a foo local variable set to nil — pkmuldoon@...

Issue #17619 has been reported by pkmuldoon (Phil Muldoon).

10 messages 2021/02/10

[#102631] [Ruby master Feature#17660] Expose information about which basic methods have been redefined — tenderlove@...

Issue #17660 has been reported by tenderlovemaking (Aaron Patterson).

9 messages 2021/02/27

[#102639] [Ruby master Misc#17662] The herdoc pattern used in tests does not syntax highlight correctly in many editors — eregontp@...

Issue #17662 has been reported by Eregon (Benoit Daloze).

13 messages 2021/02/27

[#102652] [Ruby master Bug#17664] Behavior of sockets changed in Ruby 3.0 to non-blocking — ciconia@...

Issue #17664 has been reported by ciconia (Sharon Rosner).

23 messages 2021/02/28

[ruby-core:102436] [Ruby master Feature#17140] Merge Enumerable#grep(_v) with Enumerable#select/reject

From: keystonelemur@...
Date: 2021-02-10 07:56:14 UTC
List: ruby-core #102436
Issue #17140 has been updated by baweaver (Brandon Weaver).


Would this feature still be of interest?

----------------------------------------
Feature #17140: Merge Enumerable#grep(_v) with Enumerable#select/reject
https://bugs.ruby-lang.org/issues/17140#change-90320

* Author: baweaver (Brandon Weaver)
* Status: Open
* Priority: Normal
----------------------------------------
In recent versions of Ruby we've gotten new behavior of some Enumerable methods like any?, all?, none?, one?, and others to support a single argument pattern that responds to `===`. This is very powerful, and very useful.

Currently Enumerable has `grep` and `grep_v` which allow this as a way to filter lists.

These names require some understanding of Unix to be familiar with, but naming aside, I feel it may make sense to implement `===` pattern arguments in `Enumerable#select` and `Enumerable#reject` as with the above.

Proposed Syntax:

```ruby
list_of_numbers.select(1..10)
words.reject({ 'and', 'the', 'of' })
```

I believe this would help with readability and would simplify syntax options by unifying on this standard.

My concern is that `Enumerable#find` already takes a single argument, `ifnone`, and may not be able to implement this behavior. I would be curious to see how many use `ifnone` but feel this would be more critically breaking to do.



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

In This Thread

Prev Next