Issue #16341 has been updated by Nondv (Dmitry Non).


Well, to be fair, this change is just nice-to-have sugar. I don't expect it to become a thing.

I guess for now the best way to do that is:

```ruby
pets.count { |x| dogs.include?(x) }
# or
pets.count(&dogs.method(:include?))
```

They both are "more clear than value-object-suddenly-becoming-procs". But having implicit conversion would be just a nice feature to make code more compact and expressive (MHO).
Clojure treats sets as functions, btw:

```clojure
(def dogs #{:labrador :husky :bullterrier :corgi})

(count (filter dogs [:parrot :labrador :goldfish :husky :labrador :turtle]))
```

----------------------------------------
Feature #16341: Proposal: Set#to_proc
https://bugs.ruby-lang.org/issues/16341#change-82615

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