Currying: Difference between revisions

Content deleted Content added
Steenslag (talk | contribs)
→‎{{header|Ruby}}: Added Ruby sample
Steenslag (talk | contribs)
→‎{{header|Ruby}}: Added explanation about optional argument
Line 353:
 
=={{header|Ruby}}==
The curry method was added in Ruby 1.9.1. It takes an optional arity argument, which determines the number of arguments to be passed to the proc. If that number is not reached, the curry method returns a new curried method for the rest of the arguments. (examplesExamples taken from the documentation).
<lang ruby>
b = proc {|x, y, z| (x||0) + (y||0) + (z||0) }
Line 368:
p b.curry(5)[1, 2][3, 4][5] #=> 15
p b.curry(1)[1] #=> 1
</lang>
 
=={{header|Scheme}}==
This is a simple general currying function written in [[Scheme]]: