Project

General

Profile

Actions

Bug #18620

closed

Not possible to partially curry lambda or proc's `call` method

Added by waiting_for_dev (Marc Busqué) over 2 years ago. Updated over 2 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux]
[ruby-core:107820]

Description

You can curry the call method of a regular object:

class Foo
  def foo(a, b)
    a + b
  end
end
Foo.new.method(:foo).curry[1][2] # => 3

You can also curry a lambda:

lambda { |a, b| a + b }.curry[1][2] # => 3

Same for a proc:

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:

lambda { |a, b| a + b }.method(:call).curry[1][2] # => `block in <top (required)>': wrong number of arguments (given 1, expected 2) (ArgumentError)
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:

lambda { |a, b| a + b }.method(:call).curry[1, 2] # => 3
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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0