From: "jeremyevans0 (Jeremy Evans)" Date: 2022-03-10T18:05:01+00:00 Subject: [ruby-core:107840] [Ruby master Bug#18620] Not possible to partially curry lambda or proc's `call` method Issue #18620 has been updated by jeremyevans0 (Jeremy Evans). This likely comes from the fact that `lambda{|x|}.arity => 1`, but `lambda{|x|}.method(:call).arity => -1`. I think if we could set the correct arity for `lambda{|x|}.method(:call)`, that would fix this problem. This problem is not specific to `call`, it happens with any method whose arity is -1. ---------------------------------------- Bug #18620: Not possible to partially curry lambda or proc's `call` method https://bugs.ruby-lang.org/issues/18620#change-96770 * Author: waiting_for_dev (Marc Busqu��) * Status: Open * Priority: Normal * ruby -v: ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux] * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- You can curry the call method of a regular object: ``` ruby class Foo def foo(a, b) a + b end end Foo.new.method(:foo).curry[1][2] # => 3 ``` You can also curry a lambda: ```ruby lambda { |a, b| a + b }.curry[1][2] # => 3 ``` Same for a proc: ```ruby proc { |a, b| a + b }.curry[1][2] # => 3 ``` However, currying a lambda or proc's `call` method doesn't work as expected if not enough arguments are given. Returned error differs in each case: ```ruby lambda { |a, b| a + b }.method(:call).curry[1][2] # => `block in ': wrong number of arguments (given 1, expected 2) (ArgumentError) ``` ```ruby proc { |a, b| a + b }.method(:call).curry[1][2] # => `+': nil can't be coerced into Integer (TypeError) ``` You can however totally apply the function: ```ruby lambda { |a, b| a + b }.method(:call).curry[1, 2] # => 3 ``` ```ruby proc { |a, b| a + b }.method(:call).curry[1, 2] # => 3 ``` It prevents using callable objects (responding to `#call`) and lambda/procs in a polymorphic way in regards to currying. -- https://bugs.ruby-lang.org/ Unsubscribe: