Concerning currying in Ruby 1.9.x, I've been using it in some places, and can be translated like basically supporting default parameters to the proc arguments:
p = proc {|x, y, z|x + y + z}
p.curry[1] #=> returns a lambda
p.curry[1, 2] #=> returns a lambda
p.curry[1, 2, 3] #=> 6
p2 = p.curry[1, 2]
p2.(2) #=> 5
p2.(4) #=> 7
very handy, right? thing is, I would like to be able to curry in reverse, that means, fill the last argument of my proc with a random value. Like this:
p = proc{|x, y| x - y }.curry[1]
p.(4)
my desired result would be 3. this returns -3.
i think there's no direct way of doing that and what you're doing is a bit dodgy, there probably is better solution to your problem than back-currying
what you could do to achieve desired result is wrap more procs around your procs:
p = proc{|x, y| x - y}
q = proc{|y, x| p[x, y]}
q.curry[1].(4)
in fact you can reorder arguments any way you want but believe me it gets messy very quickly
来源:https://stackoverflow.com/questions/13233875/ruby-reverse-currying-is-this-possible