Created
June 4, 2014 06:36
-
-
Save elclanrs/4164eac195f1b3283476 to your computer and use it in GitHub Desktop.
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 add,all,andF,any,apply,builtin,capitalize,compact,compose,concat,concatF,countBy,curry,curryN,difference,div,drop,dups,each,even,extend,filter,find,first,flatMap,flatten,flip,flip3,flipN,fold,foldr,forOwn,gmatch,groupBy,gt,gte,has,id,inArray,initial,instanceOf,intersection,isF,isType,isntF,join,keys,last,lt,lte,map,match,max,memo,merge,min,mod,mul,nop,notF,odd,orF,pairs,partial,partition,pluck,pluckF,pluckR,reject,replace,rest,reverse,search,sequence,shuffle,size,slice,sort,sortBy,split,sub,substr,take,toArray,toLower,toObject,toUpper,trim,union,unique,unwords,unzipObject,values,variadic,where,withF,words,zip,zipObject,zipWith,_,__slice=[].slice,__indexOf=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++){if(t in this&&this[t]===e)return t}return-1},__hasProp={}.hasOwnProperty;_={};nop=function(){};id=function(e){return e};builtin=function(e){return nop.call.bind(e)};variadic=function(){var e;e=1<=arguments.length?__slice.call(arguments,0):[];return e};apply=function(){var e,t;t=arguments[0],e=2<=arguments.length?__slice.call(arguments,1):[];return t.apply(null,[].concat.apply([],e))};notF=function(e){return function(){var t;t=1<=arguments.length?__slice.call(arguments,0):[];return!e.apply(null,t)}};curryN=function(e,t,n){if(n==null){n=[]}return function(){var r;r=1<=arguments.length?__slice.call(arguments,0):[];r=n.concat(r);if(r.length<e){return curryN(e,t,r)}return t.apply(null,r)}};curry=function(e){return function(){var t;t=1<=arguments.length?__slice.call(arguments,0):[];if(e.length>t.length){return curryN(e.length,e,t)}return e.apply(null,t)}};partial=function(){var e,t;t=arguments[0],e=2<=arguments.length?__slice.call(arguments,1):[];return function(){var n,r,i;r=1<=arguments.length?__slice.call(arguments,0):[];n=e.concat(r);i=n.length;while(i--){if(n[i]===_){n[i]=n.splice(-1)[0]}}return t.apply(null,n)}};flip=curry(function(e,t,n){return e.apply(null,[n,t])});flip3=curry(function(e,t,n,r){return e.apply(null,[r,n,t])});flipN=function(e){return function(){var t;t=1<=arguments.length?__slice.call(arguments,0):[];return e.apply(null,t.reverse())}};compose=function(){var e;e=1<=arguments.length?__slice.call(arguments,0):[];return e.reduce(function(e,t){return function(){var n;n=1<=arguments.length?__slice.call(arguments,0):[];return e(t.apply(null,n))}})};sequence=flipN(compose);isType=curry(function(e,t){return Object.prototype.toString.call(t).slice(8,-1)===e});instanceOf=curry(function(e,t){return t instanceof e});isF=curry(function(e,t){return e===t});isntF=notF(isF);andF=curry(function(e,t){return t&&e});orF=curry(function(e,t){return t||e});gte=curry(function(e,t){return t>=e});lte=curry(function(e,t){return t<=e});gt=notF(lte);lt=notF(gte);mod=curry(function(e,t){return t%e===0});even=mod(2);odd=notF(even);add=curry(function(e,t){return e+t});sub=curry(function(e,t){return t-e});mul=curry(function(e,t){return e*t});div=curry(function(e,t){return t/e});min=partial(apply,Math.min);max=partial(apply,Math.max);toArray=builtin(Array.prototype.slice);find=flip(builtin(Array.prototype.indexOf));each=flip(builtin(Array.prototype.forEach));map=flip(builtin(Array.prototype.map));filter=flip(builtin(Array.prototype.filter));fold=flip3(builtin(Array.prototype.reduce));foldr=flip3(builtin(Array.prototype.reduceRight));all=flip(builtin(Array.prototype.every));any=flip(builtin(Array.prototype.some));reverse=builtin(Array.prototype.reverse);join=flip(builtin(Array.prototype.join));concat=builtin(Array.prototype.concat);sort=flip(builtin(Array.prototype.sort));inArray=curry(function(e,t){return __indexOf.call(t,e)>=0});slice=curry(function(e,t,n){if(t!=null){return n.slice(e,t)}else{return n.slice(e)}});first=function(e){var t,n;t=e[0],n=2<=e.length?__slice.call(e,1):[];return t};last=function(e){var t,n,r;n=2<=e.length?__slice.call(e,0,r=e.length-1):(r=0,[]),t=e[r++];return t};rest=slice(1,null);initial=slice(0,-1);take=slice(0);drop=partial(slice,_,null,_);reject=curry(function(e,t){return filter(notF(e),t)});compact=filter(Boolean);unique=function(e){return e.filter(function(t,n){return e.indexOf(t)===n})};dups=function(e){return e.filter(function(t,n){return e.indexOf(t)!==n})};zip=function(){var e;e=1<=arguments.length?__slice.call(arguments,0):[];return e[0].map(function(t,n){return e.map(function(e){return e[n]})})};zipWith=function(){var e,t;e=arguments[0],t=2<=arguments.length?__slice.call(arguments,1):[];return map(partial(apply,e),apply(zip,t))};flatten=function(e){return e.reduce(function(e,t){if([].concat(t).some(Array.isArray)){return e.concat(flatten(t))}return e.concat(t)},[])};flatMap=flip(compose(flatten,map));union=compose(unique,flatten,variadic);intersection=compose(unique,dups,flatten,variadic);partition=curry(function(e,t){return[filter(e,t),reject(e,t)]});difference=function(){var e,t;t=arguments[0],e=2<=arguments.length?__slice.call(arguments,1):[];return reject(inArray(unique(flatten(e))),t)};concatF=function(){var e;e=1<=arguments.length?__slice.call(arguments,0):[];return function(t){return e.reduce(function(e,n,r){e[r]=n(t);return e},[])}};shuffle=function(e){var t,n,r,i,s;for(t=r=i=e.length-1;i<=1?r<=1:r>=1;t=i<=1?++r:--r){n=Math.random()*(t+1)|0;s=[e[n],e[t]],e[t]=s[0],e[n]=s[1]}return e};split=flip(builtin(String.prototype.split));match=flip(builtin(String.prototype.match));replace=flip3(builtin(String.prototype.replace));search=flip(builtin(String.prototype.search));substr=flip3(builtin(String.prototype.substr));trim=builtin(String.prototype.trim);toUpper=builtin(String.prototype.toUpperCase);toLower=builtin(String.prototype.toLowerCase);words=split(" ");unwords=join(" ");capitalize=replace(toUpper,/^./);gmatch=curry(function(e,t){var n;n=[];t.replace(e,function(){var e;e=1<=arguments.length?__slice.call(arguments,0):[];return n.push.apply(n,e.slice(1,-2))});return n});toObject=function(e){return e.reduce(function(t,n,r){if(r%2!==0){t[e[r-1]]=n}return t},{})};forOwn=curry(function(e,t,n){var r,i,s;r=0;for(i in n){if(!__hasProp.call(n,i))continue;s=n[i];e=t.apply(null,[e,i,s,r++])}return e});pluck=curry(function(e,t){return String(e).split(".").reduce(function(e,t){if(t in Object(e)){return e[t]}else{return void 0}},t)});pluckR=curry(function(e,t){var n;n=[];while(t=pluck(e,t)){n.push(t)}return n});pluckF=function(){var e,t;t=arguments[0],e=2<=arguments.length?__slice.call(arguments,1):[];return function(n){return n[t].apply(n,e)}};pairs=forOwn([],function(e,t,n){e.push([t,n]);return e});zipObject=compose(toObject,flatten,zip);unzipObject=forOwn([[],[]],function(e,t,n,r){e[0][r]=t;e[1][r]=n;return e});keys=Object.keys;values=compose(pluck(1),unzipObject);size=compose(pluck("length"),keys);has=compose(notF(isType("Undefined")),pluck);extend=partial(forOwn,_,function(e,t,n){e[t]=n;return e},_);merge=curry(function(e,t){return extend(extend({},e),t)});where=curry(function(e,t){return t.filter(function(t){return Object.keys(e).every(function(n){return e[n]===t[n]})})});sortBy=curry(function(e,t){return t.sort(withF(e,function(e,t){if(typeof e==="number"){return e-t}else if(e>t){return 1}else if(e<t){return-1}else{return 0}}))});groupBy=curry(function(e,t){return t.reduce(function(t,n){var r;r=e(n);t[r]=(t[r]||[]).concat([n]);return t},{})});countBy=curry(function(e,t){return forOwn(_,function(e,t,n){e[t]=n.length;return e},groupBy(e,t))});withF=curry(function(e,t){return compose(partial(apply,t),map(e),variadic)});memo=function(e){var t;t={};return function(n){if(n in t){return t[n]}return t[n]=e(n)}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment