From: "jeremyevans0 (Jeremy Evans)" Date: 2022-03-10T20:21:29+00:00 Subject: [ruby-core:107841] [Ruby master Bug#18620] Not possible to partially curry lambda or proc's `call` method Issue #18620 has been updated by jeremyevans0 (Jeremy Evans). Turns out that fixing `Method#arity` is not sufficient for this to work. This is because `Method#curry` does the equivalent `to_proc` on the Method, which also loses the arity. So that also needs work. I submitted a pull request to fix this, though the approach used is suboptimal: https://github.com/ruby/ruby/pull/5640 Note that I'm not sure I would consider this a bug. The pull request fixes this particular use case (Proc#method(:call)), but this curry issue occurs with all Method/Proc objects where the arity is not known. I'll add this as an issue for discussion at the next developer meeting. ---------------------------------------- Bug #18620: Not possible to partially curry lambda or proc's `call` method https://bugs.ruby-lang.org/issues/18620#change-96772 * 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: