How to feed the method?

consider this code

def fx, y x + y end g = lambda(&method(:f)).curry.(1) g.(2) # => 3 

the expression for g too hard to read. Can this be simplified?

+6
source share
2 answers

I think the shortest (and most readable!) You can get is

  g = method(:f).to_proc.curry[1] g[2] # => 3 
+6
source

If you are using Ruby 2.2.0 or later, you can use the # curry method :

 def f(x, y) x + y end g = method(:f).curry[1] pg[2] # => 3 
+7
source

All Articles