Skip to content

Instantly share code, notes, and snippets.

@mkuklis
Last active September 7, 2021 21:39

Revisions

  1. mkuklis revised this gist Apr 5, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ var add = autocurry(function (a, b, c, d) {
    add(1)(2)(3)(4); // 10

    var one = add(1);
    one(4, 5, 6) // 16
    one(4, 5, 6); // 16


    add(2)(3, 4)(5); // 14
  2. mkuklis revised this gist Apr 5, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -25,4 +25,8 @@ var one = add(1);
    one(4, 5, 6) // 16


    add(2)(3, 4)(5); // 14




  3. mkuklis revised this gist Apr 2, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ function toArray(args) {
    function autocurry(fn) {
    var len = fn.length;
    var args = [];
    return function next () {
    return function next() {
    args = args.concat(toArray(arguments));
    return (args.length >= len) ?
    fn.apply(this, args.splice(0)) :
  4. mkuklis created this gist Apr 2, 2013.
    28 changes: 28 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    function toArray(args) {
    return [].slice.call(args);
    }

    function autocurry(fn) {
    var len = fn.length;
    var args = [];
    return function next () {
    args = args.concat(toArray(arguments));
    return (args.length >= len) ?
    fn.apply(this, args.splice(0)) :
    next;
    }
    }

    // usage

    var add = autocurry(function (a, b, c, d) {
    return a + b + c + d;
    });

    add(1)(2)(3)(4); // 10

    var one = add(1);
    one(4, 5, 6) // 16