Currying: Difference between revisions

→‎{{header|Ruby}}: Added Ruby sample
(→‎{{header|J}}: J polynomials are little-endian)
(→‎{{header|Ruby}}: Added Ruby sample)
Line 352:
</lang>
 
=={{header|Ruby}}==
The curry method was added in Ruby 1.9.1. (examples taken from the documentation).
<lang ruby>
b = proc {|x, y, z| (x||0) + (y||0) + (z||0) }
p b.curry[1][2][3] #=> 6
p b.curry[1, 2][3, 4] #=> 6
p b.curry(5)[1][2][3][4][5] #=> 6
p b.curry(5)[1, 2][3, 4][5] #=> 6
p b.curry(1)[1] #=> 1
 
b = proc {|x, y, z, *w| (x||0) + (y||0) + (z||0) + w.inject(0, &:+) }
p b.curry[1][2][3] #=> 6
p b.curry[1, 2][3, 4] #=> 10
p b.curry(5)[1][2][3][4][5] #=> 15
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]]:
1,149

edits