Logo

Programming-Idioms

History of Idiom 37 > diff from v17 to v18

Edit summary for version 18 by :
New Lua implementation by user [Nepta]

Version 17

2016-03-21, 17:01:50

Version 18

2016-04-07, 07:40:28

Idiom #37 Currying

Technique of transforming a function that takes multiple arguments and returning a function for which some of the arguments are preset.

Idiom #37 Currying

Technique of transforming a function that takes multiple arguments and returning a function for which some of the arguments are preset.

Code
function curry2(f)
   return function(a)
      return function(b)
         return f(a,b)
      end
   end
end

function add(a,b)
   return a + b
end

local curryAdd = curry2(add)
local add2 = curryAdd(2)
Demo URL
http://codepad.org/ehx2wgVf