Last active
April 10, 2022 18:47
-
-
Save neftaly/b77455b3df9a8b50bf8b to your computer and use it in GitHub Desktop.
Revisions
-
neftaly revised this gist
Sep 16, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ const curry = (fn, ...oldArgs) => (...newArgs) => { const args = [...oldArgs, ...newArgs]; return (args.length < fn.length) ? curry(fn, ...args) : fn(...args); }; -
neftaly revised this gist
Sep 16, 2015 . 1 changed file with 2 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,4 @@ const curry = (fn, preArgs = []) => (...postArgs) => { const args = [...preArgs, ...postArgs]; return (args.length < fn.length) ? curry(fn, args) : fn(...args); }; -
neftaly revised this gist
Sep 16, 2015 . 1 changed file with 20 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ const curryN = (arity, fn) => { // Take old arguments, and an array of new arguments const receiver = oldArgs => (...newArgs) => { const args = [...oldArgs, ...newArgs]; // Combine old and new arguments if (args.length >= arity) { // Have enough arguments have been received? return fn(...args); // Run fn with argument list } return receiver(args); // Recurse, and await further arguments }; return receiver([]); // Start with an empty array of prior arguments }; const curry = fn => curryN(fn.length, fn); -
neftaly revised this gist
Jul 3, 2015 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ const curryN = (arity, fn) => { const receiver = preArgs => (...postArgs) => { const args = [...preArgs, ...postArgs]; return (args.length < arity) ? receiver(args) : fn(...args); } return receiver([]); } const curry = fn => curryN(fn.length, fn); -
neftaly revised this gist
Jul 3, 2015 . 2 changed files with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ const curry = (fn, preArgs = []) => (...postArgs) => { const args = [...preArgs, ...postArgs]; // Combine old and new arguments if (args.length < fn.length) { // Check ig enough arguments received return curry(fn, args); // Recurse to emit an argument receiver fn } return fn(...args); // Finished; Apply arguments to fn and return result }; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ const add3 = function (a, b, c) { return a + b + c; }; const x = curry(add3); -
neftaly created this gist
Jul 3, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ const curry = (fn, preArgs = []) => (...postArgs) => { const args = [...preArgs, ...postArgs]; // Combine old and new arguments if (args.length < fn.length) { // Check ig enough arguments received return curry(fn, args); // Recurse to emit an argument receiver fn } return fn(...args); // Finished; Apply arguments to fn and return result }; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ const add3 = function (a, b, c) { return a + b + c; }; const x = curry(add3); x(1)(1)(1); //=> 3 x(1, 1)(1); //=> 3 x(1, 1, 1); //=> 3