UNPKG

decurry

Version:

decurry is the 'reverse' of curry: given a composed function `fn(arg1)(arg2)(arg3)` it returns a function that can be called as `fn(arg1, arg2, arg3)` or `fn(arg1, arg2)(arg3) etc.`

36 lines (32 loc) 1.13 kB
/** * decurry http://github.com/anodynos/decurry/ * * decurry is the 'reverse' of curry: given a composed function `fn(arg1)(arg2)(arg3)` it returns a function that can be called as `fn(arg1, arg2, arg3)` or `fn(arg1, arg2)(arg3) etc.` * Version 2.0.1 - Compiled on 2017-12-05 00:18:39 * Repository git://github.com/anodynos/decurry * Copyright(c) 2017 Angelos Pikoulas <agelos.pikoulas@gmail.com> * License MIT */ // Generated by uRequire v0.7.0-beta.29 target: 'lib' template: 'nodejs' var decurry, slice = [].slice; module.exports = decurry = function (arity, curriedFunction) { if (typeof arity !== "number") { throw new Error("decurry(arity, curriedFunction): arity was not a number"); } return function () { var arg, args, i, j, len, result; args = 1 <= arguments.length ? slice.call(arguments, 0) : []; result = curriedFunction; for (i = j = 0, len = args.length; j < len; i = ++j) { arg = args[i]; if (i < arity) { result = result(arg); } } if (args.length < arity) { result = decurry(arity - args.length, result); } return result; }; }; ;