[–] raganwald 17y ago ↗ As mentioned elsewhere, is this currying? Or partial application?Currying:lambda { |x,y| x + y }.curry => lambda { |x| lambda { |y| x + y } }Partial Applicationlambda { |x, y| x + y }.apply(2) => lambda { |y| 2 + y }And given #curry, #apply is trivial:class Proc; def apply(param); self.curry.call(param); end end...or at least, that's my understanding... [–] grandalf 17y ago ↗ i think you're right.
[–] grandalf 17y ago ↗ After learning about these concepts in Haskell, the Ruby code seems downright ugly (I never thought I'd say that)... but still probably quite useful in some cases.
4 comments
[ 2.8 ms ] story [ 22.6 ms ] threadCurrying:
lambda { |x,y| x + y }.curry => lambda { |x| lambda { |y| x + y } }
Partial Application
lambda { |x, y| x + y }.apply(2) => lambda { |y| 2 + y }
And given #curry, #apply is trivial:
class Proc; def apply(param); self.curry.call(param); end end
...or at least, that's my understanding...