Last active
December 9, 2015 19:51
Revisions
-
Keith Rosenberg revised this gist
Dec 9, 2015 . 1 changed file with 10 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 @@ -91,3 +91,13 @@ function dontIf(cond, fn){ } // Example: // dontIf(true, function(){}); // Will most likely run your function but not guaranteed. function likely(fn){ } // Unlikely to run your function, but maybe. function unlikely(fn){ } -
Keith Rosenberg revised this gist
Dec 8, 2015 . 1 changed file with 2 additions and 2 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 @@ -15,12 +15,12 @@ function doIf(cond, cb){ // Takes two functions - ignores the first one, exec the second one. function inLieuOf(fn1, fn2){ fn2(); } // Run fn once, then check cond - if true, repeat. function doWhile(cond, fn){ } function doIfEach(arr, cb){ -
Keith Rosenberg created this gist
Dec 8, 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,93 @@ // // raw whitepaper for functional interface/subset of JS that eliminates logical operations // similar to IFTTT. Based off of this image/site: https://ifttt.com/products // function doIf(cond, cb){ if(cond instanceof Array){ doIfEach(cond, cb); } else if(cond === true && typeof cb === 'function'){ cb(); } } // Example: // doIf(config.webSockets, fn) // Takes two functions - ignores the first one, exec the second one. function inLieuOf(fn1, fn2){ } // Run fn once, then check cond - if true, repeat. function doWhile(cond, fn){ } function doIfEach(arr, cb){ var conds = arr.length; arr.forEach(function(cond){ // If the item passed was a function, call it and then // expect it to represent the comparable condition if(typeof cond === 'function'){ cond = cond(); } if(cond){ conds--; } }); if(conds === 0 && typeof cb === 'function'){ cb(); } } // Example: /* doIfEach([ name == 'Tom', function(){ return true; } ], function); */ function doOneIf(cond, arrFn){ var len = arrFn.len; var fn = arrFn[Math.floor(Math.random() * len)]; doIf(cond, fn); } // Example: /* doOneIf(true, [ function(){ }, function(){ } ]); */ // Example: function doSomeIf(cond, arrFn){ var len = arrFn.len; var howMany = Math.floor(Math.random() * len); for( ; i > howMany; howMany--){ doIf(cond, arrFn[Math.floor(Math.random() * len)]); } } /* doSomeIf(true, [ function(){ }, function(){ } ]); */ function dontIf(cond, fn){ doIf(!(cond), fn) } // Example: // dontIf(true, function(){});