Issue #9548 has been updated by Sam Rawlins.


Firstly, Proc has a #curry, though not as flexible as you would like: http://rubydoc.info/stdlib/core/Proc#curry-instance_method

Secondly, to implement such flexibility is not too hard in pure Ruby. Here is an implementation of arbitrary currying for Procs:

    def curry(prc, *args)
      Proc.new { |*remaining| prc.call(*args.map { |arg| arg || remaining.shift }) }
    end

and one for Methods:

    def curry_m(m, n, *args)
      define_method(m, curry(method(n), *args))
    end

Thusly, you can do:

    power = ->(a,b){ "#{a}**#{b} is #{a**b}" }
    square = curry power, nil, 2
    pow2   = curry power, 2, nil

    puts "3 squared is #{square.call(3)}"  #=> 3 squared is 9
    puts "two to the 3 is #{pow2.call(3)}" #=> two to the 3 is 8

    list = ->(a,b,c,d) { "#{a}, #{b}, #{c}, #{d}" }
    static_a   = curry list, :hi, nil, nil, nil
    static_b_c = curry list, nil, :sam, :adam, nil

    puts "static_a: #{static_a.call(:b, :c, :d)}" #=> static_a: hi, b, c, d
    puts "static_b_c: #{static_b_c.call(:a, :d)}" #=> static_b,c: a, sam, adam, d

    def power_m(a,b); a**b; end
    curry_m(:square_m, :power_m, nil, 2)
    curry_m(:pow2_m, :power_m, 2, nil)

    puts "3 squared is #{square_m(3)}"  #=> 3 squared is 9
    puts "two to the 3 is #{pow2_m(3)}" #=> two to the 3 is 8

gist: https://gist.github.com/srawlins/9146528

----------------------------------------
Feature #9548: Module curry
https://bugs.ruby-lang.org/issues/9548#change-45355

* Author: Boris Stitnicky
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
I would like to beg for either `Module#curry` method with syntax

```ruby
module Foo
  curry( :sym2, :sym1, 0 => 42, 1 => 43, 3 => 44, foo: "bar" )
end
```

or `curry` directive similar to the existing `alias` directive

```ruby
module Foo
  curry sym2 sym1( 42, 43, *, 44, foo: "bar )
end
```

Example usage:

```ruby
module MyMath
  def power a, b
    a ** b
  end

  curry square power( *, 2 )
  curry square_root power( *, 0.5 )
  curry cube( *, 3 )
  curry pow2 power( 2, * )
  curry pow_e power( Math::E, * )
  curry pow10 power( 10, * )
end
```




-- 
http://bugs.ruby-lang.org/