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 characters
| f2.toString = function() { | |
| return fx.toString()+'('+args.join(', ')+')'; | |
| } |
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 characters
| console.log(add) | |
| // function f1() { | |
| // var args = Array.prototype.slice.call(arguments, 0); | |
| // if (args.length >= arity) return fx.apply(null, args); | |
| // | |
| // function f2() { | |
| // return f1.apply(null, args.concat(Array.prototype.slice.call(arguments, 0))); | |
| // } | |
| // return f2; | |
| // }; |
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 characters
| console.log(inc) | |
| // function add(x,y){ return x + y }(1) |
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 characters
| f1.toString = function() { return fx.toString(); } |
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 characters
| console.log(add) | |
| // function add(x, y){ return x + y } |
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 characters
| var incAll = map(inc); | |
| console.log(incAll) | |
| // function map(f, xs){ return xs.map(f) }(function add(x, y){ return x + y }(1)) |
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 characters
| function fToString(f) { | |
| return f.name ? f.name : f.toString(); | |
| } |
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 characters
| console.log(incAll) | |
| // map(add(1)) |
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 characters
| function curry(fx) { | |
| var arity = fx.length; | |
| function f1() { | |
| var args = Array.prototype.slice.call(arguments, 0); | |
| if (args.length >= arity) return fx.apply(null, args); | |
| function f2() { | |
| return f1.apply(null, args.concat(Array.prototype.slice.call(arguments, 0))); | |
| } |
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 characters
| var compose = function() { | |
| var fns = arguments; | |
| function f(result) { | |
| for (var i = fns.length - 1; i > -1; i--) { | |
| result = fns[i].call(this, result); | |
| } | |
| return result; | |
| }; |