typeof window=='undefined'&&(window={});var Functional=window.Functional||{};Functional.install=function(except){var source=Functional,target=window;for(var name in source) name=='install'||name.charAt(0)=='_'||except&&name in except||{}[name]||(target[name]=source[name]);} Functional.compose=function(){var fns=Functional.map(Function.toFunction,arguments),arglen=fns.length;return function(){for(var i=arglen;--i>=0;) arguments=[fns[i].apply(this,arguments)];return arguments[0];}} Functional.sequence=function(){var fns=Functional.map(Function.toFunction,arguments),arglen=fns.length;return function(){for(var i=0;i=0;) result=fn.apply(object,[sequence[i],result]);return result;} Functional.and=function(){var args=Functional.map(Function.toFunction,arguments),arglen=args.length;return function(){var value=true;for(var i=0;i ',result);return result;}} Functional._attachMethodDelegates(Functional.__initalFunctionState.getChangedMethods());delete Functional.__initalFunctionState;Function.toFunction=Function.toFunction||Functional.K;if(!Array.slice){Array.slice=(function(slice){return function(object){return slice.apply(object,slice.call(arguments,1));};})(Array.prototype.slice);} String.prototype.lambda=function(){var params=[],expr=this,sections=expr.ECMAsplit(/\s*->\s*/m);if(sections.length>1){while(sections.length){expr=sections.pop();params=sections.pop().split(/\s*,\s*|\s+/m);sections.length&§ions.push('(function('+params+'){return ('+expr+')})');}}else if(expr.match(/\b_\b/)){params='_';}else{var leftSection=expr.match(/^\s*(?:[+*\/%&|\^\.=<>]|!=)/m),rightSection=expr.match(/[+\-*\/%&|\^\.=<>!]\s*$/m);if(leftSection||rightSection){if(leftSection){params.push('$1');expr='$1'+expr;} if(rightSection){params.push('$2');expr=expr+'$2';}}else{var vars=this.replace(/(?:\b[A-Z]|\.[a-zA-Z_$])[a-zA-Z_$\d]*|[a-zA-Z_$][a-zA-Z_$\d]*\s*:|this|arguments|'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/g,'').match(/([a-z_$][a-z_$\d]*)/gi)||[];for(var i=0,v;v=vars[i++];) params.indexOf(v)>=0||params.push(v);}} return new Function(params,'return ('+expr+')');} String.prototype.lambda.cache=function(){var proto=String.prototype,cache={},uncached=proto.lambda,cached=function(){var key='#'+this;return cache[key]||(cache[key]=uncached.call(this));};cached.cached=function(){};cached.uncache=function(){proto.lambda=uncached};proto.lambda=cached;} String.prototype.apply=function(thisArg,args){return this.toFunction().apply(thisArg,args);} String.prototype.call=function(){return this.toFunction().apply(arguments[0],Array.prototype.slice.call(arguments,1));} String.prototype.toFunction=function(){var body=this;if(body.match(/\breturn\b/)) return new Function(this);return this.lambda();} Function.prototype.toFunction=function(){return this;} Function.toFunction=function(value){return value.toFunction();} String.prototype.ECMAsplit=('ab'.split(/a*/).length>1?String.prototype.split:function(separator,limit){if(typeof limit!='undefined') throw"ECMAsplit: limit is unimplemented";var result=this.split.apply(this,arguments),re=RegExp(separator),savedIndex=re.lastIndex,match=re.exec(this);if(match&&match.index==0) result.unshift('');re.lastIndex=savedIndex;return result;});