[#107867] Fwd: [ruby-cvs:91197] 8f59482f5d (master): add some tests for Unicode Version 14.0.0 — Martin J. Dürst <duerst@...>
To everybody taking care of continuous integration:
3 messages
2022/03/13
[#108090] [Ruby master Bug#18666] No rule to make target 'yaml/yaml.h', needed by 'api.o' — duerst <noreply@...>
Issue #18666 has been reported by duerst (Martin D端rst).
7 messages
2022/03/28
[#108117] [Ruby master Feature#18668] Merge `io-nonblock` gems into core — "Eregon (Benoit Daloze)" <noreply@...>
Issue #18668 has been reported by Eregon (Benoit Daloze).
22 messages
2022/03/30
[ruby-core:107976] [Ruby master Feature#18644] Coerce anything callable to a Proc
From:
"Eregon (Benoit Daloze)" <noreply@...>
Date:
2022-03-18 13:14:44 UTC
List:
ruby-core #107976
Issue #18644 has been updated by Eregon (Benoit Daloze).
As background, `to_proc` already exists as a coercion protocol, it's what is used for `call(&callable)`, and there is already `Proc#to_proc`.
I think Option 1 makes sense and would be good to add, since indeed we can easily produce a Proc from a call-able object via `method(:call).to_proc` as shown (there is also `-> (*a, **kw) { call(*a, **kw) }`, but that loses arity & parameters information).
Option 2 is IMHO less good, because it wouldn't help for `call(&callable)` and doesn't simply use the existing protocol.
----------------------------------------
Feature #18644: Coerce anything callable to a Proc
https://bugs.ruby-lang.org/issues/18644#change-96926
* Author: waiting_for_dev (Marc Busqu辿)
* Status: Open
* Priority: Normal
----------------------------------------
Functional objects are increasingly popular in Ruby. Having objects that respond to `#call` makes them interchangeable with a `Proc`.
However, when you need to perform some Proc-specific operation, like currying, you have to break the abstraction and ask for the type of object. Example:
```ruby
(callable.is_a?(Proc) ? callable : callable.method(:call)).curry[value]
```
Because of https://bugs.ruby-lang.org/issues/18620, it's not possible to make them polymorphic by taking the `:call` method:
```ruby
callable.method(:call).curry[value] # won't work!
```
Consequently, I propose adding a built-in Ruby way to coerce anything callable to a proc (examples in Ruby):
### Option 1: `Object#to_proc`
```ruby
class Object
def to_proc
return method(:call).to_proc if respond_to?(:call)
raise "Needs to respond to :call"
end
end
class Proc
def to_proc
self
end
end
callable.to_proc.curry[value]
```
### Option 2. `Kernel#Proc`
```ruby
class Kernel
def Proc(value)
if value.is_a?(::Proc)
value
elsif value.respond_to?(:call)
value.method(:call).to_proc
else
raise "Needs to implement :call"
end
end
end
Proc(callable).curry[value]
```
--
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>