[ruby-core:95804] [Ruby master Feature#16341] Proposal: Set#to_proc
From:
shevegen@...
Date:
2019-11-11 23:43:36 UTC
List:
ruby-core #95804
Issue #16341 has been updated by shevegen (Robert A. Heiler).
> this change is just nice-to-have sugar. I don't expect it to
> become a thing.
The ruby core team often points out that having good use cases may
help a proposal; and of course avoiding other problems such as
backwards-incompatibility or such.
Your initial comment is quite sparse, so zverok sort of got you to
explain more lateron. ;)
I am not really using ruby in a functional-centric manner nor do I
know clojure (aside from superficial glances), but to me personally
I am not completely sure if the use case has been explained. Unless
it was only syntactic sugar of course.
----------------------------------------
Feature #16341: Proposal: Set#to_proc
https://bugs.ruby-lang.org/issues/16341#change-82626
* Author: Nondv (Dmitry Non)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
``` ruby
class Set
def to_proc
-> (x) { include?(x) } # or method(:include?).to_proc
end
end
```
Usage:
```ruby
require 'set'
banned_numbers = Set[0, 5, 7, 9]
(1..10).reject(&banned_numbers) # ===> [1, 2, 3, 4, 6, 8, 10]
```
--
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>