How do you curry any javascript function of arbitrary arity?

前端 未结 5 1946
天命终不由人
天命终不由人 2020-12-19 04:19

Let\'s say I have some function:

function g(a,b,c){ return a + b + c }

And I\'d like to turn it into its \"curried\" form (in quotations si

5条回答
  •  情深已故
    2020-12-19 04:45

    Please check the curry library.

    It can turn any function into curry no matter how many arguments are there.

    Example:

    > var curry = require('curry');
    undefined
    > var add = curry(function(a, b, c, d, e) { return a + b + c + d + e; });
    undefined
    > add(1)
    [Function]
    > add(1,2,3,4,5)
    15
    > add(1,2)(3,4)(5)
    15
    >
    

提交回复
热议问题