From: "Eregon (Benoit Daloze)" Date: 2022-03-10T20:39:16+00:00 Subject: [ruby-core:107842] [Ruby master Bug#18620] Not possible to partially curry lambda or proc's `call` method Issue #18620 has been updated by Eregon (Benoit Daloze). `.arity` is normally fixed for a given method definition (e.g., `Proc#call`) so I'm not sure supporting this is a good idea, and it would bring some inconsistency. IMHO the use case is too niche to be worth the added complexity and inconsistency. ---------------------------------------- Bug #18620: Not possible to partially curry lambda or proc's `call` method https://bugs.ruby-lang.org/issues/18620#change-96774 * 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: