Haskell’s Prelude has a useful function that swaps a function’s arguments: http://zvon.org/other/haskell/Outputprelude/flip_f.html
I need to do the same in Ruby. Instead of just defining a custom method, I would like to monkey patch the Proc class so that I could use flip alongside Proc#curry. Something like
f = lambda {|x, y| [x, y]}
g = f.flip.curry.(2)
to supply a value for y.
I do not know how to reopen Proc class to do that.
1 Answer