Currying: Difference between revisions

→‎{{header|D}}: add crystal version with two different methods
No edit summary
(→‎{{header|D}}: add crystal version with two different methods)
Line 238:
20
</lang>
 
=={{header|Crystal}}==
Crystal allows currying procs with either <code>Proc#partial</code> or by manually creating closures:
 
<lang ruby>add_things = ->(x1 : Int32, x2 : Int32, x3 : Int32) { x1 + x2 + x3 }
add_curried = add_things.partial(2, 3)
add_curried.call(4) #=> 9
 
def add_two_things(x1)
return ->(x2 : Int32) {
->(x3 : Int32) { x1 + x2 + x3 }
}
end
add13 = add_two_things(3).call(10)
add13.call(5) #=> 18</lang>
 
=={{header|D}}==
Line 254 ⟶ 269:
<pre>Add 2 to 3: 5
Add 2 to 3 (curried): 5</pre>
 
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
Anonymous user