Currying
Currying is the technique of transforming a function that takes multiple arguments (or a tuple of arguments) in such a way that it can be called as a chain of functions, each with a single argument .
For instance:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Currying in Proc of Ruby
In Ruby, Object is the first class, but we still can use it as FP.
Proc is kind of like function, Ruby provide a method named currying in Proc. This give us a easy way to currying proc like currying function.
Baisc Usage:
1 2 3 4 5 |
|
Proc#curry also can take one argument(arity) that limit the quantity of arguments.
For instance:
1 2 3 4 |
|
Note: the arity argument in Lambda#curry must equal to the number of arguments in Lambda, otherwise it will raise a ArgumentError.