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
| //Some extra sugar on top | |
| let program = R.compose( R.flip(pipePromise), R.unapply(R.flatten) ); |
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
| R.reduce( (a,b) => a+b ,0)//sum | |
| R.reduce( (a,b) => a+b ,"")//join strings | |
| R.reduce( (a,b) => a.length > b.length ? a : b ,"")//return the longest string | |
| R.reduce( (a,b) => {a[b]=b;return a;}} ,{})//create object of keys set to their values |
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
| let pipePromise = R.reduce( (p,fn) => p.then(fn) ); |
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 bindP = function(promise, f) { | |
| return promise.then(f); | |
| }; | |
| var pipeP = _.curry(function(functionList, starting_promise) { | |
| return _.reduce(functionList, bind, starting_promise); | |
| }); | |
| var pipeP = _.curry(_.partial(_.reduce,_, bind),2);//shorter | |
| var sequenceP = _.compose(pipeP,_.restParam(_.flattenDeep,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 bindP = function(promise, f) { | |
| input.then(function(x) { | |
| return f(x); | |
| }); | |
| }; | |
| //ok, this is better | |
| var bindP = function(promise, f) { | |
| input.then(f); | |
| }; |
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; | |
| return function f1() { | |
| var args = Array.prototype.slice.call(arguments, 0); | |
| if (args.length >= arity) { | |
| return fx.apply(null, args); | |
| } | |
| else { | |
| return function 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
| document.documentElement.innerHTML = '<iframe src="'+document.location.href+'" style="position:absolute;top:0;left:0;width:100%;height:100%;border:0"></iframe>'; |
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 parseJSON(json_string){ | |
| try { | |
| return JSON.parse(json_string); | |
| } | |
| catch(e){ | |
| e.value = json_string; | |
| return e; | |
| } | |
| } |
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 done_wrapper(fn){ | |
| return function(value){ | |
| fn(value); | |
| return value; | |
| }; | |
| } | |
| function badlog(x){ | |
| console.log(x); | |
| return 'return a complete nonsense string!'; |
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
| //using the .then( successCB, failCB ) pattern | |
| $.ajax('some-url') | |
| .then( filter_and_format_results, filter_and_format_errors ) | |
| .done( display_results ) | |
| .fail( display_error_message ); | |
| //or, using the new .catch( failCB ) pattern | |
| $.ajax('some-url') | |
| .then( filter_and_format_results, ) | |
| .catch( filter_and_format_errors ) |