ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:69675] [Ruby trunk - Feature #11286] [Open] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
@ 2015-06-19  7:11 ` 0x0dea+redmine
  2015-06-19  8:48 ` [ruby-core:69678] [Ruby trunk - Feature #11286] " ryand-ruby
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: 0x0dea+redmine @ 2015-06-19  7:11 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been reported by D.E. Akers.

----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:69678] [Ruby trunk - Feature #11286] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
  2015-06-19  7:11 ` [ruby-core:69675] [Ruby trunk - Feature #11286] [Open] [PATCH] Add case equality arity to Enumerable's sequence predicates 0x0dea+redmine
@ 2015-06-19  8:48 ` ryand-ruby
  2015-06-19 14:22 ` [ruby-core:69682] " ruby-core
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: ryand-ruby @ 2015-06-19  8:48 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by Ryan Davis.


I rather like this proposal. I hope it gets accepted.

----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-53047

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:69682] [Ruby trunk - Feature #11286] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
  2015-06-19  7:11 ` [ruby-core:69675] [Ruby trunk - Feature #11286] [Open] [PATCH] Add case equality arity to Enumerable's sequence predicates 0x0dea+redmine
  2015-06-19  8:48 ` [ruby-core:69678] [Ruby trunk - Feature #11286] " ryand-ruby
@ 2015-06-19 14:22 ` ruby-core
  2015-06-19 21:54 ` [ruby-core:69685] " nobu
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: ruby-core @ 2015-06-19 14:22 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by Marc-Andre Lafortune.

Assignee set to Yukihiro Matsumoto

I agree. Assigning to Matz

----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-53054

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:69685] [Ruby trunk - Feature #11286] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2015-06-19 14:22 ` [ruby-core:69682] " ruby-core
@ 2015-06-19 21:54 ` nobu
  2015-06-19 22:14 ` [ruby-core:69687] " 0x0dea+redmine
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: nobu @ 2015-06-19 21:54 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by Nobuyoshi Nakada.


> ~~~diff
> +    struct MEMO *memo = MEMO_NEW(Qtrue, *argv, 0);
> +    rb_check_arity(argc, 0, 1);

Why dereference `argv` before checking `argc`.

----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-53061

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:69687] [Ruby trunk - Feature #11286] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2015-06-19 21:54 ` [ruby-core:69685] " nobu
@ 2015-06-19 22:14 ` 0x0dea+redmine
  2015-06-20  0:12 ` [ruby-core:69688] " nobu
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: 0x0dea+redmine @ 2015-06-19 22:14 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by D.E. Akers.

File case_equality_sequence_predicates-check_argc_before_deref.patch added

Nobuyoshi Nakada wrote:
> > ~~~diff
> > +    struct MEMO *memo = MEMO_NEW(Qtrue, *argv, 0);
> > +    rb_check_arity(argc, 0, 1);
> 
> Why dereference `argv` before checking `argc`.

I assumed `*argv` would resolve to `Qnil` in the case of no arguments, but this is indeed not the case. I have attached a modified patch which takes this into account.

----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-53062

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)
case_equality_sequence_predicates-check_argc_before_deref.patch (10 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:69688] [Ruby trunk - Feature #11286] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2015-06-19 22:14 ` [ruby-core:69687] " 0x0dea+redmine
@ 2015-06-20  0:12 ` nobu
  2015-06-20  1:13 ` [ruby-core:69689] " 0x0dea+redmine
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: nobu @ 2015-06-20  0:12 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by Nobuyoshi Nakada.


D.E. Akers wrote:
> I assumed `*argv` would resolve to `Qnil` in the case of no arguments, but this is indeed not the case.

Nobody guarantees it.

And argument check should be before making a memo object, I think.

~~~diff
diff --git a/enum.c b/enum.c
index c5b9d77..d6f11e5 100644
--- a/enum.c
+++ b/enum.c
@@ -1045,6 +1045,8 @@ enum_sort_by(VALUE obj)
 
 #define ENUMFUNC(name, argc) argc ? name##_eqq : rb_block_given_p() ? name##_iter_i : name##_i
 
+#define MEMO_ENUM_NEW(v1) (rb_check_arity(argc, 0, 1), MEMO_NEW((v1), (argc ? *argv : 0), 0))
+
 #define DEFINE_ENUMFUNCS(name) \
 static VALUE enum_##name##_func(VALUE result, struct MEMO *memo); \
 \
@@ -1104,8 +1106,7 @@ DEFINE_ENUMFUNCS(all)
 static VALUE
 enum_all(int argc, VALUE *argv, VALUE obj)
 {
-    struct MEMO *memo = MEMO_NEW(Qtrue, argc ? *argv : 0, 0);
-    rb_check_arity(argc, 0, 1);
+    struct MEMO *memo = MEMO_ENUM_NEW(Qtrue);
     rb_block_call(obj, id_each, 0, 0, ENUMFUNC(all, argc), (VALUE)memo);
     return memo->v1;
 }
@@ -1145,8 +1146,7 @@ DEFINE_ENUMFUNCS(any)
 static VALUE
 enum_any(int argc, VALUE *argv, VALUE obj)
 {
-    struct MEMO *memo = MEMO_NEW(Qfalse, argc ? *argv : 0, 0);
-    rb_check_arity(argc, 0, 1);
+    struct MEMO *memo = MEMO_ENUM_NEW(Qfalse);
     rb_block_call(obj, id_each, 0, 0, ENUMFUNC(any, argc), (VALUE)memo);
     return memo->v1;
 }
@@ -1438,8 +1438,7 @@ DEFINE_ENUMFUNCS(none)
 static VALUE
 enum_none(int argc, VALUE *argv, VALUE obj)
 {
-    struct MEMO *memo = MEMO_NEW(Qtrue, argc ? *argv : 0, 0);
-    rb_check_arity(argc, 0, 1);
+    struct MEMO *memo = MEMO_ENUM_NEW(Qtrue);
     rb_block_call(obj, id_each, 0, 0, ENUMFUNC(none, argc), (VALUE)memo);
     return memo->v1;
 }
~~~

----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-53063

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)
case_equality_sequence_predicates-check_argc_before_deref.patch (10 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [ruby-core:69689] [Ruby trunk - Feature #11286] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2015-06-20  0:12 ` [ruby-core:69688] " nobu
@ 2015-06-20  1:13 ` 0x0dea+redmine
  2015-07-16 17:30 ` [ruby-core:70004] " 0x0dea+redmine
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: 0x0dea+redmine @ 2015-06-20  1:13 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by D.E. Akers.

File case_equality_sequence_predicates-all_updates.patch added

I knew the call to `rb_check_arity()` should come first, but your very nice solution to doing so without mixing declarations and code did not occur to me. The attached contains all of the improvements discussed so far, but maybe there are more to be found? Is there something cleaner than passing `argc` to `ENUMFUNC()`?

----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-53064

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)
case_equality_sequence_predicates-check_argc_before_deref.patch (10 KB)
case_equality_sequence_predicates-all_updates.patch (9.94 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:70004] [Ruby trunk - Feature #11286] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2015-06-20  1:13 ` [ruby-core:69689] " 0x0dea+redmine
@ 2015-07-16 17:30 ` 0x0dea+redmine
  2015-11-05 21:53 ` [ruby-core:71357] " shannonskipper
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: 0x0dea+redmine @ 2015-07-16 17:30 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by D.E. Akers.


matz, would you mind voicing your opinion of this proposal?

----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-53439

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)
case_equality_sequence_predicates-check_argc_before_deref.patch (10 KB)
case_equality_sequence_predicates-all_updates.patch (9.94 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:71357] [Ruby trunk - Feature #11286] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2015-07-16 17:30 ` [ruby-core:70004] " 0x0dea+redmine
@ 2015-11-05 21:53 ` shannonskipper
  2015-11-05 22:09 ` [ruby-core:71358] " 0x0dea+redmine
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: shannonskipper @ 2015-11-05 21:53 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by Shannon Skipper.


This seems quite nice. Any downsides?

----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-54722

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)
case_equality_sequence_predicates-check_argc_before_deref.patch (10 KB)
case_equality_sequence_predicates-all_updates.patch (9.94 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:71358] [Ruby trunk - Feature #11286] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2015-11-05 21:53 ` [ruby-core:71357] " shannonskipper
@ 2015-11-05 22:09 ` 0x0dea+redmine
  2016-10-06  0:22 ` [ruby-core:77492] [Ruby trunk Feature#11286] " ryand-ruby
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: 0x0dea+redmine @ 2015-11-05 22:09 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by D.E. Akers.


I've come to realize that it might not be entirely clear what is being proposed. In essence, all of the following examples feel very "Ruby" and should, in my opinion, Just Work.

```ruby
[1, 3.14, 2ri].all?(Numeric) # => true

if should_be_all_symbols.any?(String)
  ...
end

some_strings.none?(/aeiou/i)

lotto.all?(1..49) && lotto.one?(43..49)
```

----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-54723

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)
case_equality_sequence_predicates-check_argc_before_deref.patch (10 KB)
case_equality_sequence_predicates-all_updates.patch (9.94 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:77492] [Ruby trunk Feature#11286] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2015-11-05 22:09 ` [ruby-core:71358] " 0x0dea+redmine
@ 2016-10-06  0:22 ` ryand-ruby
  2016-10-06 21:28 ` [ruby-core:77508] " shevegen
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: ryand-ruby @ 2016-10-06  0:22 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by Ryan Davis.


Why is this still open a year later?

Matz? A ruling?

----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-60758

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)
case_equality_sequence_predicates-check_argc_before_deref.patch (10 KB)
case_equality_sequence_predicates-all_updates.patch (9.94 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:77508] [Ruby trunk Feature#11286] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2016-10-06  0:22 ` [ruby-core:77492] [Ruby trunk Feature#11286] " ryand-ruby
@ 2016-10-06 21:28 ` shevegen
  2016-12-21 14:56 ` [ruby-core:78785] " shyouhei
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: shevegen @ 2016-10-06 21:28 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by Robert A. Heiler.


I like this one in particular:

    some_strings.none?(/aeiou/i)

I am not so sure about:

    nums.grep(5..10)

But I have no strong feelings either way. I do disagree with the
statement "syntactic noise incurred by opening a block" though -
blocks feel very natural in ruby to me. I guess the main part I
would agree is that the .grep(range) variant is shorter to write
than the block variant. This also reminds me of other proposals
about allowing arguments to e. g. .map(&:chomp) invocations -
I use this quite a lot myself but the & there still "feels" sort
of strange.

----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-60770

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)
case_equality_sequence_predicates-check_argc_before_deref.patch (10 KB)
case_equality_sequence_predicates-all_updates.patch (9.94 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:78785] [Ruby trunk Feature#11286] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
                   ` (11 preceding siblings ...)
  2016-10-06 21:28 ` [ruby-core:77508] " shevegen
@ 2016-12-21 14:56 ` shyouhei
  2016-12-21 16:03 ` [ruby-core:78787] " matz
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: shyouhei @ 2016-12-21 14:56 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by Shyouhei Urabe.


We looked at this issue in today's developer meeting.

Attendees were positive about the proposed functionality.  But Matz wanted separate method(s) than to extend all? etc, like we have separate select and grep methods.

----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-62192

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Target version: 
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)
case_equality_sequence_predicates-check_argc_before_deref.patch (10 KB)
case_equality_sequence_predicates-all_updates.patch (9.94 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:78787] [Ruby trunk Feature#11286] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
                   ` (12 preceding siblings ...)
  2016-12-21 14:56 ` [ruby-core:78785] " shyouhei
@ 2016-12-21 16:03 ` matz
  2017-11-28  4:26 ` [ruby-core:83904] " ruby-core
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: matz @ 2016-12-21 16:03 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by Yukihiro Matsumoto.


I am positive about the idea too. But as a duty of the final decision maker, I have to consider every option before the judgment. I see a few additional options.

* takes optional argument that takes `===` (proposed)
* takes optional keyword argument, `match:` for example
* introduces another set of methods with different names

Right now, I am wandering between option 1 and 2.

Matz.


----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-62195

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Target version: 
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)
case_equality_sequence_predicates-check_argc_before_deref.patch (10 KB)
case_equality_sequence_predicates-all_updates.patch (9.94 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:83904] [Ruby trunk Feature#11286] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
                   ` (13 preceding siblings ...)
  2016-12-21 16:03 ` [ruby-core:78787] " matz
@ 2017-11-28  4:26 ` ruby-core
  2017-11-29  9:37 ` [ruby-core:83969] " matz
  2017-12-10 22:41 ` [ruby-core:84150] [Ruby trunk Feature#11286][Closed] " ruby-core
  16 siblings, 0 replies; 17+ messages in thread
From: ruby-core @ 2017-11-28  4:26 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by marcandre (Marc-Andre Lafortune).


matz (Yukihiro Matsumoto) wrote:
> I am positive about the idea too. But as a duty of the final decision maker, I have to consider every option before the judgment. I see a few additional options.
> 
> * takes optional argument that takes `===` (proposed)
> * takes optional keyword argument, `match:` for example
> * introduces another set of methods with different names
> 
> Right now, I am wandering between option 1 and 2.

I hope a decision is made on this.

While I love keyword arguments in general, I am not convinced they are needed here and I would favor solution #1.


----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-67954

* Author: 0x0dea (D.E. Akers)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)
case_equality_sequence_predicates-check_argc_before_deref.patch (10 KB)
case_equality_sequence_predicates-all_updates.patch (9.94 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:83969] [Ruby trunk Feature#11286] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
                   ` (14 preceding siblings ...)
  2017-11-28  4:26 ` [ruby-core:83904] " ruby-core
@ 2017-11-29  9:37 ` matz
  2017-12-10 22:41 ` [ruby-core:84150] [Ruby trunk Feature#11286][Closed] " ruby-core
  16 siblings, 0 replies; 17+ messages in thread
From: matz @ 2017-11-29  9:37 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by matz (Yukihiro Matsumoto).


OK, I made a decision. I took option 1 above as proposed.
We can do as following:

~~~
[1, 3.14, 2ri].all?(Numeric) # => true

if should_be_all_symbols.any?(String)
  ...
end

some_strings.none?(/aeiou/i)

~~~

Matz.

----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-68037

* Author: 0x0dea (D.E. Akers)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)
case_equality_sequence_predicates-check_argc_before_deref.patch (10 KB)
case_equality_sequence_predicates-all_updates.patch (9.94 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:84150] [Ruby trunk Feature#11286][Closed] [PATCH] Add case equality arity to Enumerable's sequence predicates.
       [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
                   ` (15 preceding siblings ...)
  2017-11-29  9:37 ` [ruby-core:83969] " matz
@ 2017-12-10 22:41 ` ruby-core
  16 siblings, 0 replies; 17+ messages in thread
From: ruby-core @ 2017-12-10 22:41 UTC (permalink / raw)
  To: ruby-core

Issue #11286 has been updated by marcandre (Marc-Andre Lafortune).

Status changed from Open to Closed
Target version set to 2.5

Thank you Matz

D.E. Akers: thanks for the patch! I adapted it for better handling of enumerables yielding multiple arguments, and also changing Hash#any? / Array#any? which have their own versions.

Merged.

----------------------------------------
Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates.
https://bugs.ruby-lang.org/issues/11286#change-68254

* Author: 0x0dea (D.E. Akers)
* Status: Closed
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.5
----------------------------------------
## Proposal
It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method.

## Rationale
`Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code:

```ruby
strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)
```

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`.

---Files--------------------------------
0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB)
case_equality_sequence_predicates-check_argc_before_deref.patch (10 KB)
case_equality_sequence_predicates-all_updates.patch (9.94 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2017-12-10 22:41 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-11286.20150619071155@ruby-lang.org>
2015-06-19  7:11 ` [ruby-core:69675] [Ruby trunk - Feature #11286] [Open] [PATCH] Add case equality arity to Enumerable's sequence predicates 0x0dea+redmine
2015-06-19  8:48 ` [ruby-core:69678] [Ruby trunk - Feature #11286] " ryand-ruby
2015-06-19 14:22 ` [ruby-core:69682] " ruby-core
2015-06-19 21:54 ` [ruby-core:69685] " nobu
2015-06-19 22:14 ` [ruby-core:69687] " 0x0dea+redmine
2015-06-20  0:12 ` [ruby-core:69688] " nobu
2015-06-20  1:13 ` [ruby-core:69689] " 0x0dea+redmine
2015-07-16 17:30 ` [ruby-core:70004] " 0x0dea+redmine
2015-11-05 21:53 ` [ruby-core:71357] " shannonskipper
2015-11-05 22:09 ` [ruby-core:71358] " 0x0dea+redmine
2016-10-06  0:22 ` [ruby-core:77492] [Ruby trunk Feature#11286] " ryand-ruby
2016-10-06 21:28 ` [ruby-core:77508] " shevegen
2016-12-21 14:56 ` [ruby-core:78785] " shyouhei
2016-12-21 16:03 ` [ruby-core:78787] " matz
2017-11-28  4:26 ` [ruby-core:83904] " ruby-core
2017-11-29  9:37 ` [ruby-core:83969] " matz
2017-12-10 22:41 ` [ruby-core:84150] [Ruby trunk Feature#11286][Closed] " ruby-core

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