Browse files

rebuilt scripts

  • Loading branch information...
1 parent 065d668 commit 59174aef39e18c330246287ceab2986e2d7d1453 @CatChen committed Sep 17, 2011
Showing with 69 additions and 77 deletions.
  1. +12 −12 build/async.js
  2. +1 −1 build/jshelpers-min.js
  3. +33 −37 build/jshelpers.js
  4. +1 −1 build/list-min.js
  5. +18 −22 build/list.js
  6. +1 −1 build/overload-min.js
  7. +3 −3 build/overload.js
View
24 build/async.js
@@ -41,7 +41,7 @@
raiseGlobalError(operation);
};
- this.yield = function(result) {
+ this["yield"] = function(result) {
var self = this;
if (self.error) {
@@ -140,13 +140,13 @@
};
this.go = function(initialArgument) {
- return this.yield(initialArgument);
- }
+ return this["yield"](initialArgument);
+ };
this.addCallback = function(callback) {
callbackQueue.push(callback);
if (this.completed || (chain && started)) {
- this.yield(this.result);
+ this["yield"](this.result);
}
return this;
};
@@ -179,16 +179,16 @@
Async.go = function(initialArgument) {
return Async.chain().go(initialArgument);
- }
+ };
Async.collect = function(functions, functionArguments) {
- var operation = new Async.Operation()
+ var operation = new Async.Operation();
var results = [];
var count = 0;
var checkCount = function() {
if (count == functions.length) {
- operation.yield(results);
+ operation["yield"](results);
}
};
@@ -203,7 +203,7 @@
if (functionResult && functionResult instanceof Async.Operation) {
functionResult.addCallback(function(result) {
results[i] = result;
- count++
+ count++;
checkCount();
});
} else {
@@ -220,14 +220,14 @@
Async.wait = function(delay, context) {
var operation = new Async.Operation();
setTimeout(function() {
- operation.yield(context);
+ operation["yield"](context);
}, delay);
return operation;
- }
+ };
Async.instant = function(context) {
return Async.wait(0, context);
- }
+ };
Async.onerror = function(callback) {
globalErrorCallbacks.push(callback);
@@ -247,7 +247,7 @@
var operation = new Async.Operation();
var self = this;
setTimeout(function() {
- operation.yield(self.apply(thisReference, argumentsArray || []));
+ operation["yield"](self.apply(thisReference, argumentsArray || []));
/* default value for argumentsArray is empty array */
/* IE8 throws when argumentsArray is undefined */
}, 1);
View
2 build/jshelpers-min.js
@@ -1 +1 @@
-(function(){var a={};if(typeof module!="undefined"&&module.exports)module.exports=a;else if(window)window.Async=a;else return;var b=[],c=function(a){for(var c=0;c<b.length;c++)try{b[c](a)}catch(d){}};a.Operation=function(b){b=b||{};var d=[],e=[],f=b.chain&&b.chain===!0?!0:!1,g=!1,h=null;this.result=undefined,this.error=undefined,this.state=f?"waiting":"running",this.completed=!1;var i=function(a){for(var b=0;b<e.length;b++)try{e[b](a)}catch(d){}c(a)};this.yield=function(b){var c=this;if(c.error)return this;f?(g=!0,c.result=b,c.state="chain running",c.completed=!1):(c.result=b,c.state="completed",c.completed=!0),setTimeout(function(){if(!h){while(d.length>0&&!c.error){var b=d.shift();if(f){try{var e=b.call(c,c.result)}catch(g){c.error=g,c.state="error",i(c);break}if(e&&e instanceof a.Operation){h=a.chain(),h.onerror(function(a){c.error=h.error,c.state="error",i(c)});while(d.length>0)h.next(d.shift()),h.next(function(a){c.result=a;return a});h.next(function(a){c.state="completed",c.completed=!0;return a}),e.addCallback(function(a){c.result=a,h.go(a)})}else c.result=e}else try{b.call(c,c.result)}catch(g){c.error=g,c.state="error",i(c);break}}!h&&!c.error&&(c.state="completed",c.completed=!0)}else{while(d.length>0)h.next(d.shift());h.next(function(a){c.result=a,c.state="completed",c.completed=!0;return a})}},1);return this},this.go=function(a){return this.yield(a)},this.addCallback=function(a){d.push(a),(this.completed||f&&g)&&this.yield(this.result);return this},this.next=function(a){return this.addCallback(a)},this.wait=function(b){var c=this;f&&this.next(function(){return a.wait(b,c.result)});return this},this.onerror=function(a){e.push(a);return this}},a.chain=function(b){var c=new a.Operation({chain:!0});b&&c.next(b);return c},a.go=function(b){return a.chain().go(b)},a.collect=function(b,c){var d=new a.Operation,e=[],f=0,g=function(){f==b.length&&d.yield(e)};for(var h=0;h<b.length;h++)(function(d){var h;c&&c[d]?h=b[d].apply(this,c[d]):h=b[d].apply(this,[]),h&&h instanceof a.Operation?h.addCallback(function(a){e[d]=a,f++,g()}):(e[d]=h,f++,g())})(h);return d},a.wait=function(b,c){var d=new a.Operation;setTimeout(function(){d.yield(c)},b);return d},a.instant=function(b){return a.wait(0,b)},a.onerror=function(c){b.push(c);return a},Function.prototype.asyncCall=function(){var a=arguments[0],b=[];for(var c=1;c<arguments.length;c++)b.push(arguments[c]);return this.asyncApply(a,b)},Function.prototype.asyncApply=function(b,c){var d=new a.Operation,e=this;setTimeout(function(){d.yield(e.apply(b,c||[]))},1);return d}})(),function(){var a={};if(typeof module!="undefined"&&module.exports)module.exports=a;else if(window)window.Central=a;else return;var b=function(a){var b={};a.listen=function(c,d){b[c]=b[c]||[];var e=0,f=b[c];while(e<f.length&&f[e]!=f.length)e++;e==f.length&&(f[f.length]=d);return a},a.call=function(c,d){if(b[c]){var e,f=b[c];for(e=0;e<f.length;e++)try{f[e](d)}catch(g){}}return a}};a.extend=function(a){b(a);return a},a.extend(a)}(),function(){var a={};if(typeof module!="undefined"&&module.exports)module.exports=a;else if(window)window.GrandCentral=a;else return;var b=a.Operators={};b[""]=function(a,c){return a instanceof Array?b["in"].apply(this,arguments):a instanceof RegExp?b.re.apply(this,arguments):a instanceof Function?b.ld.apply(this,arguments):b.eq.apply(this,arguments)},b.eq=function(a,c){if(arguments.length<2)return!1;if(a===null||a===undefined||c===null||c===undefined)return c===a;switch(a.constructor){case String:case Number:case Boolean:return a.constructor==c.constructor&&a==c;default:if(a instanceof Array){if(!(c instanceof Array))return!1;if(c.length!=a.length)return!1;for(var d=0;d<a.length;d++)if(!b.eq(a[d],c[d]))return!1;return!0}if(!(c instanceof Object))return!1;for(var e in a){var f=e.lastIndexOf("$"),g,h,i=a[e],j;f<0?(g=e,j=""):(g=e.substr(0,f),j=e.substr(f+1));if(!b[j])throw"operator doesn't exist: "+j;if(g in c){h=c[g];if(!b[j](i,h))return!1}else if(!b[j](i))return!1}return!0}},b.ne=function(a,c){return!b.eq(a,c)},b.lt=function(a,b){return arguments.length==2&&b<a},b.lte=function(a,b){return arguments.length==2&&b<=a},b.gt=function(a,b){return arguments.length==2&&b>a},b.gte=function(a,b){return arguments.length==2&&b>=a},b["in"]=function(a,c){if(arguments.length<2)return!1;for(var d=0;d<a.length;d++)if(b.eq(a[d],c))return!0;return!1},b.nin=function(a,c){return arguments.length==2&&!b["in"](a,c)},b.all=function(a,c){if(arguments.length<2)return!1;if(!(c instanceof Array))return!1;var d;for(var e=0;e<a.length;e++){d=!1;for(var f=0;f<c.length;f++)if(b.eq(a[e],c[f])){d=!0;break}if(!d)return!1}return!0},b.ex=function(a,b){if(a===!0)return arguments.length==2;if(a===!1)return arguments.length==1;return!1},b.re=function(a,b){return arguments.length==2&&b&&b.match&&b.match(a)},b.f=function(a,b){return a.call(b,b)};var c=function(a){return function(c){return arguments.length>0?b[""](a,c):b[""](a)}},d=function(a){var b=[];a.listen=function(d,e){d instanceof Function||(d=c(d)),b.push({filter:d,handler:e});return a},a.call=function(c){for(var d=0;d<b.length;d++)b[d].filter.apply(this,arguments)&&b[d].handler(c);return a}};a.extend=function(a){d(a);return a},a.extend(a)}(),function(){var a=function(){};a.prototype.item=function(){throw"abstract enumerator should not be instantiated"},a.prototype.next=function(){throw"abstract enumerator should not be instantiated"},a.prototype.reset=function(){throw"abstract enumerator should not be instantiated"};var b=function(a){var b=0,c=1,d=2,e=b,a=a,f=0;this.item=function(){if(e==c)return a[f];if(e==b)throw"incorrect index";if(e==d)throw"incorrect index"},this.next=function(){switch(e){case b:a.length==0?e=d:e=c;break;case c:f++,f>=a.length&&(e=d);break;case d:}return e!=d},this.reset=function(){e=b,f=0}};b.prototype=new a;var c=function(a){var b=NaN,c=[];this.item=function(){if(b>=0){b in c||(c[b]=a.item());return c[b]}return a.item()},this.next=function(){b>=-1&&b++;return a.next()},this.reset=function(){b=-1;return a.reset()},this.cache=function(){return[].slice.call(c,0)}};c.prototype=new a;var d=function(a){this.item=a.item,this.next=a.next,this.reset=a.reset};d.prototype=new a;var e=function(a,b){this.item=a.item,this.next=a.next,this.reset=a.reset,b.item&&(this.item=function(){return b.item(a)}),b.next&&(this.next=function(){return b.next(a)}),b.reset&&(this.reset=function(){return b.reset(a)})};e.prototype=new a;var f=function(a){this.yield=function(b){a.yield&&a.yield(b)},this.end=function(){a.end&&a.end()}},g=function(c){var d,e=[],f=-1;if(!c)d=new b([]),e=[],f=0;else if(arguments.length>1)d=new b([].slice.call(arguments,0)),e=[].slice.call(arguments,0),f=e.length;else if(c instanceof Array)d=new b([].slice.call(c,0)),e=[].slice.call(c,0),f=e.length;else if(c instanceof a)d=c;else throw"source should be an array";this.at=function(a){var b=0;if(a<0)throw"incorrect index";if(e.length>a)return e[a];if(f>=0&&a>=f)throw"incorrect index";d.reset();while(d.next()){e[b]=d.item();if(a==0){var c=e[b];return c}a--,b++}f=b;throw"incorrect index"},this.length=function(){if(f<0){d.reset(),f=0;while(d.next())f++}return f},this.each=function(a){d.reset();for(var b=0;b<e.length;b++)d.next(),a.call(e[b],e[b]);var c=e.length;while(d.next())e[c]=d.item(),a.call(e[c],e[c]),c++;f=c;return this},this.toArray=function(){if(f<0||e.length<f){d.reset();for(var a=0;a<e.length;a++)d.next();var b=e.length;while(d.next())e[b]=d.item(),b++;f=b}return[].slice.call(e,0)},this.enumerator=function(){return d},this.cache=function(){return[].slice.call(e,0)}};g.prototype.reverse=function(){return new g(this.toArray().reverse())},g.prototype.map=function(a){var b=this,d=new e(b.enumerator(),{item:function(b){return a.call(b.item(),b.item())}});return new g(new c(d))},g.prototype.filter=function(a){var b=this,d=new e(b.enumerator(),{next:function(b){var c=!0;while((c=c&&b.next())&&!a.call(b.item(),b.item()));return c}});return new g(new c(d))},g.prototype.fold=function(a,b){var c=b;this.each(function(b){c=a.call(b,c,b)});return c},g.prototype.scan=function(a,b){var d=0,f=1,h=2,i=this,j=d,k,l=new e(i.enumerator(),{item:function(a){switch(j){case d:throw"incorrect index";case f:return k;case h:throw"incorrect index"}},next:function(c){var e,g;switch(j){case d:j=f,k=b;break;case f:g=c.next(),g?(e=c.item(),k=a.call(e,k,e)):j=h;break;case h:}return j!=h},reset:function(a){j=d,a.reset()}});return new g(new c(l))},g.prototype.takeWhile=function(a){var b=0,d=1,f=this,h=b,i=new e(f.enumerator(),{next:function(c){var e=!0;switch(h){case b:e=c.next()&&a.call(c.item(),c.item()),e||(h=d);break;case d:}return h!=d},reset:function(a){h=b,a.reset()}});return new g(new c(i))},g.prototype.take=function(a){var b=this,d=0,f=new e(b.enumerator(),{item:function(b){if(d<=a)return b.item();throw"incorrect index"},next:function(b){if(d<a){d++;return b.next()}return!1},reset:function(a){d=0,a.reset()}});return new g(new c(f))},g.prototype.dropWhile=function(a){var b=0,d=1,f=2,h=this,i=b,j=new e(h.enumerator(),{next:function(c){var e=!0;switch(i){case b:while((e=c.next())&&a.call(c.item(),c.item()));e?i=d:i=f;break;case d:e=c.next(),e||(i=f);break;case f:}return i!=f},reset:function(a){i=b,a.reset()}});return new g(new c(j))},g.prototype.drop=function(a){var b=0,d=1,f=2,h=this,i=b,j=new e(h.enumerator(),{next:function(c){var e=0,g=!0;switch(i){case b:while((g=c.next())&&e<a)e++;g?i=d:i=f;break;case d:g=c.next(),g||(i=f);break;case f:}return i!=f},reset:function(a){i=b,a.reset()}});return new g(new c(j))},g.prototype.cycle=function(){var a=this,b=new e(a.enumerator(),{next:function(a){if(a.next())return!0;a.reset();return a.next()?!0:!1}});return new g(new c(b))},g.generate=function(a){var b=0,e=1,h=2,i,j=b,k=e,l=[],m=NaN,n=new f({yield:function(a){k!=h&&(l[l.length]=a)},end:function(){k=h}}),o=new d({item:function(){switch(j){case b:throw"incorrect index";case e:return l[m];case h:throw"incorrect index"}},next:function(){switch(j){case b:case e:m++;if(k!=h)while(m>=l.length&&k!=h)a.call(n,n);j=k;break;case h:}return j!=h},reset:function(){m=-1,j=b}});return new g(new c(o))},g.iterate=function(a,b){var e=0,f=1,h,i=e,j=new d({item:function(){switch(i){case e:throw"incorrect index";case f:return h}},next:function(){switch(i){case e:h=b,i=f;break;case f:h=a.call(h,h)}return!0},reset:function(){i=e}});return new g(new c(j))},g.count=function(a,b){var a=a||0,b=b||1;return g.iterate(function(a){return a+b},a)},g.repeat=function(a){return g.iterate(function(a){return a},a)},g.concatenate=function(){var a=0,b=1,e=2,f=[].slice.call(arguments,0),h=0,i=a,j=new d({item:function(){return f[h].enumerator().item()},next:function(){switch(i){case a:f[h].enumerator().reset(),i=b;return j.next();case b:if(!f[h].enumerator().next()){h++;if(h<f.length){i=a;return j.next()}i=e}break;case e:}return i!=e},reset:function(){h=0,i=a}});return new g(new c(j))},g.zip=function(a){var b=0,e=1,f=[].slice.call(arguments,1),h=b;if(f.length==0)return new g([]);f=new g(f);var i=new d({item:function(){var c;switch(h){case b:c=f.map(function(){return this.enumerator().item()}).toArray();return a.apply(c,c);case e:throw"incorrect index"}},next:function(){var a=!0;switch(h){case b:f.each(function(){a=a&&this.enumerator().next()}),a||(h=e);break;case e:}return h!=e},reset:function(){f.each(function(){this.enumerator().reset()}),h=b}});return new g(new c(i))},g.prototype.all=function(a){return this.fold(function(b,c){return b&&a.call(c,c)},!0)},g.prototype.any=function(a){return this.fold(function(b,c){return b||a.call(c,c)},!1)},g.prototype.sum=function(){return this.fold(function(a,b){return a+b},0)},g.prototype.average=function(){var a=this.fold(function(a,b){return[a[0]+b,a[1]+1]},[0,0]);return a[0]/a[1]},g.prototype.maximum=function(){var a=this.at(0);if(a)return this.drop(1).fold(function(a,b){return a>b?a:b},a);throw"cannot process empty list"},g.prototype.minimum=function(){var a=this.at(0);if(a)return this.drop(1).fold(function(a,b){return a<b?a:b},a);throw"cannot process empty list"},g.prototype.head=function(){if(this.take(1).length()<1)throw"cannot process empty list";return this.at(0)},g.prototype.tail=function(){if(this.take(1).length()<1)throw"cannot process empty list";return this.drop(1)},g.prototype.init=function(){if(this.take(1).length()<1)throw"cannot process empty list";var a=0,b=1,d=2,f=this,h=a,i,j=new e(f.enumerator(),{item:function(c){switch(h){case a:throw"incorrect index";case b:return i;case d:throw"incorrect index"}},next:function(c){var e=0,f=!0;switch(h){case a:c.next(),i=c.item(),f=c.next(),f?h=b:h=d;break;case b:i=c.item(),f=c.next(),f||(h=d);break;case d:}return h!=d},reset:function(b){h=a,b.reset()}});return new g(new c(j))},g.prototype.last=function(){if(this.take(1).length()<1)throw"cannot process empty list";return this.at(this.length()-1)};if(typeof module!="undefined"&&module.exports)module.exports=g;else if(window)window.List=g;else return}(),function(){var a;if(module&&module.exports)a=module.exports;else if(window)a=window.List;else return;var b=a.ES5Array=function(d){a.apply(this,arguments),this.indexOf=function(a,b){b=b||0;var c=b,d=this.drop(b).dropWhile(function(b){if(a!==b){c++;return!0}return!1});return d.take(1).length()>0?c:-1},this.lastIndexOf=function(a,b){b=b||this.length();var c=this.take(b),d=c.reverse(),e=this.indexOf.call(d,a);return e>=0?c.length()-1-e:-1},this.every=function(a,b){return this.all(function(c){return a.call(b,c)})},this.some=function(a,b){return this.any(function(c){return a.call(b,c)})},this.forEach=function(a,b){this.each(function(c){a.call(b,c)})},this.map=function(a,c){return b.prototype.map.call(this,function(b){return a.call(c,b)})},this.filter=function(a,c){return b.prototype.filter.call(this,function(b){return a.call(c,b)})},this.reduce=function(a,b){return arguments.length>1?this.fold(function(b,c){return a.call(undefined,b,c)},b):c.call(this.drop(1),a,this.at(0))},this.reduceRight=function(a,b){return c.apply(this.reverse(),arguments)}};b.prototype=new a;var c=(new b(0)).reduce}(),function(){var Overload={};if(typeof module!="undefined"&&module.exports)module.exports=Overload;else if(window)window.Overload=Overload;else return;var copySignature=function(a){var b=a.slice(0);a.more&&(b.more=!0);return b},parseSignature=function(signature){if(signature.replace(/(^\s+|\s+$)/ig,"")=="")signature=[];else{signature=signature.split(",");for(var i=0;i<signature.length;i++){var typeExpression=signature[i].replace(/(^\s+|\s+$)/ig,""),type=null;if(typeExpression=="*")type=Overload.Any;else if(typeExpression=="...")type=Overload.More;else try{type=eval("("+typeExpression+")")}catch(error){throw"type expression cannot be evaluated: "+typeExpression}signature[i]=type}}return signature},inheritanceComparator=function(a,b){return a==b?0:b==Overload.Any?1:a==Overload.Any?-1:a.prototype instanceof b?1:b.prototype instanceof a?-1:0},overloadComparator=function(a,b){var c=!1,d=!1,e=a.signature,f=b.signature;if(!e.more&&f.more)c=!0,e=copySignature(e),e.length=f.length;else if(e.more&&!f.more)d=!0,f=copySignature(f),f.length=e.length;else if(e.more&&f.more)if(e.length>f.length){f=copySignature(f);while(f.length<e.length)f[f.length]=Overload.Any}else if(e.length<f.length){e=copySignature(e);while(e.length<f.length)e[e.length]=Overload.Any}for(var g=0;g<e.length;g++){var h=inheritanceComparator(e[g],f[g]);h>0?c=!0:h<0&&(d=!0)}return c&&!d?1:!c&&d?-1:0},matchSignature=function(a,b){if(a.length<b.length)return!1;if(a.length>b.length&&!b.more)return!1;for(var c=0;c<b.length;c++)if(!(a[c]===null||a[c]===undefined||b[c]==Overload.Any||a[c]instanceof b[c]||a[c].constructor==b[c]))return!1;return!0};Overload.create=function(a){var b=[],c=function(a){var c=[];for(var d=0;d<b.length;d++)matchSignature(a,b[d].signature)&&c.push(b[d]);return c},d=function(a){var b=c(a);switch(b.length){case 0:return null;case 1:return b[0];default:b=b.sort(overloadComparator);return overloadComparator(b[b.length-1],b[b.length-2])>0?b[b.length-1]:null}},e=function(){var a=d(arguments);if(a){var b=Array.prototype.slice.call(arguments,0);if(b.length>a.signature.length){var c=b.splice(a.signature.length);b.push(c)}return a["function"].apply(this,b)}throw"cannot select a proper overload"};e.match=c,e.select=d,e.add=function(a,c){if(a instanceof Array)a=copySignature(a);else if(a.constructor==String)a=parseSignature(a);else throw"signature is neither a string nor an array";for(var d=0;d<a.length;d++){if(!(a[d]instanceof Function))throw"argument type should be a function";if(d<a.length-1&&a[d]==Overload.More)throw"arguments type cannot be used in any argument except the last one"}a[a.length-1]==Overload.More&&(a.length=a.length-1,a.more=!0),b.push({signature:a,"function":c});return this};return e},Overload.add=function(a,b){return Overload.create().add(a,b)},Overload.Any=function(){throw"this type is only an identifier and should not be instantiated"},Overload.More=function(){throw"this type is only an identifier and should not be instantiated"}}()
+(function(){var a={};if(typeof module!="undefined"&&module.exports)module.exports=a;else if(window)window.Async=a;else return;var b=[],c=function(a){for(var c=0;c<b.length;c++)try{b[c](a)}catch(d){}};a.Operation=function(b){b=b||{};var d=[],e=[],f=b.chain&&b.chain===!0?!0:!1,g=!1,h=null;this.result=undefined,this.error=undefined,this.state=f?"waiting":"running",this.completed=!1;var i=function(a){for(var b=0;b<e.length;b++)try{e[b](a)}catch(d){}c(a)};this.yield=function(b){var c=this;if(c.error)return this;f?(g=!0,c.result=b,c.state="chain running",c.completed=!1):(c.result=b,c.state="completed",c.completed=!0),setTimeout(function(){if(!h){while(d.length>0&&!c.error){var b=d.shift();if(f){try{var e=b.call(c,c.result)}catch(g){c.error=g,c.state="error",i(c);break}if(e&&e instanceof a.Operation){h=a.chain(),h.onerror(function(a){c.error=h.error,c.state="error",i(c)});while(d.length>0)h.next(d.shift()),h.next(function(a){c.result=a;return a});h.next(function(a){c.state="completed",c.completed=!0;return a}),e.addCallback(function(a){c.result=a,h.go(a)})}else c.result=e}else try{b.call(c,c.result)}catch(g){c.error=g,c.state="error",i(c);break}}!h&&!c.error&&(c.state="completed",c.completed=!0)}else{while(d.length>0)h.next(d.shift());h.next(function(a){c.result=a,c.state="completed",c.completed=!0;return a})}},1);return this},this.go=function(a){return this.yield(a)},this.addCallback=function(a){d.push(a),(this.completed||f&&g)&&this.yield(this.result);return this},this.next=function(a){return this.addCallback(a)},this.wait=function(b){var c=this;f&&this.next(function(){return a.wait(b,c.result)});return this},this.onerror=function(a){e.push(a);return this}},a.chain=function(b){var c=new a.Operation({chain:!0});b&&c.next(b);return c},a.go=function(b){return a.chain().go(b)},a.collect=function(b,c){var d=new a.Operation,e=[],f=0,g=function(){f==b.length&&d.yield(e)};for(var h=0;h<b.length;h++)(function(d){var h;c&&c[d]?h=b[d].apply(this,c[d]):h=b[d].apply(this,[]),h&&h instanceof a.Operation?h.addCallback(function(a){e[d]=a,f++,g()}):(e[d]=h,f++,g())})(h);return d},a.wait=function(b,c){var d=new a.Operation;setTimeout(function(){d.yield(c)},b);return d},a.instant=function(b){return a.wait(0,b)},a.onerror=function(c){b.push(c);return a},Function.prototype.asyncCall=function(){var a=arguments[0],b=[];for(var c=1;c<arguments.length;c++)b.push(arguments[c]);return this.asyncApply(a,b)},Function.prototype.asyncApply=function(b,c){var d=new a.Operation,e=this;setTimeout(function(){d.yield(e.apply(b,c||[]))},1);return d}})(),function(){var a={};if(typeof module!="undefined"&&module.exports)module.exports=a;else if(window)window.Central=a;else return;var b=function(a){var b={};a.listen=function(c,d){b[c]=b[c]||[];var e=0,f=b[c];while(e<f.length&&f[e]!=f.length)e++;e==f.length&&(f[f.length]=d);return a},a.call=function(c,d){if(b[c]){var e,f=b[c];for(e=0;e<f.length;e++)try{f[e](d)}catch(g){}}return a}};a.extend=function(a){b(a);return a},a.extend(a)}(),function(){var a={};if(typeof module!="undefined"&&module.exports)module.exports=a;else if(window)window.GrandCentral=a;else return;var b=a.Operators={};b[""]=function(a,c){return a instanceof Array?b["in"].apply(this,arguments):a instanceof RegExp?b.re.apply(this,arguments):a instanceof Function?b.ld.apply(this,arguments):b.eq.apply(this,arguments)},b.eq=function(a,c){if(arguments.length<2)return!1;if(a===null||a===undefined||c===null||c===undefined)return c===a;switch(a.constructor){case String:case Number:case Boolean:return a.constructor==c.constructor&&a==c;default:if(a instanceof Array){if(!(c instanceof Array))return!1;if(c.length!=a.length)return!1;for(var d=0;d<a.length;d++)if(!b.eq(a[d],c[d]))return!1;return!0}if(!(c instanceof Object))return!1;for(var e in a){var f=e.lastIndexOf("$"),g,h,i=a[e],j;f<0?(g=e,j=""):(g=e.substr(0,f),j=e.substr(f+1));if(!b[j])throw"operator doesn't exist: "+j;if(g in c){h=c[g];if(!b[j](i,h))return!1}else if(!b[j](i))return!1}return!0}},b.ne=function(a,c){return!b.eq(a,c)},b.lt=function(a,b){return arguments.length==2&&b<a},b.lte=function(a,b){return arguments.length==2&&b<=a},b.gt=function(a,b){return arguments.length==2&&b>a},b.gte=function(a,b){return arguments.length==2&&b>=a},b["in"]=function(a,c){if(arguments.length<2)return!1;for(var d=0;d<a.length;d++)if(b.eq(a[d],c))return!0;return!1},b.nin=function(a,c){return arguments.length==2&&!b["in"](a,c)},b.all=function(a,c){if(arguments.length<2)return!1;if(!(c instanceof Array))return!1;var d;for(var e=0;e<a.length;e++){d=!1;for(var f=0;f<c.length;f++)if(b.eq(a[e],c[f])){d=!0;break}if(!d)return!1}return!0},b.ex=function(a,b){if(a===!0)return arguments.length==2;if(a===!1)return arguments.length==1;return!1},b.re=function(a,b){return arguments.length==2&&b&&b.match&&b.match(a)},b.f=function(a,b){return a.call(b,b)};var c=function(a){return function(c){return arguments.length>0?b[""](a,c):b[""](a)}},d=function(a){var b=[];a.listen=function(d,e){d instanceof Function||(d=c(d)),b.push({filter:d,handler:e});return a},a.call=function(c){for(var d=0;d<b.length;d++)b[d].filter.apply(this,arguments)&&b[d].handler(c);return a}};a.extend=function(a){d(a);return a},a.extend(a)}(),function(){var a=function(){};a.prototype.item=function(){throw"abstract enumerator should not be instantiated"},a.prototype.next=function(){throw"abstract enumerator should not be instantiated"},a.prototype.reset=function(){throw"abstract enumerator should not be instantiated"};var b=function(a){var b=0,c=1,d=2,e=b,f=0;this.item=function(){if(e==c)return a[f];if(e==b)throw"incorrect index";if(e==d)throw"incorrect index"},this.next=function(){switch(e){case b:a.length===0?e=d:e=c;break;case c:f++,f>=a.length&&(e=d);break;case d:}return e!=d},this.reset=function(){e=b,f=0}};b.prototype=new a;var c=function(a){var b=NaN,c=[];this.item=function(){if(b>=0){b in c||(c[b]=a.item());return c[b]}return a.item()},this.next=function(){b>=-1&&b++;return a.next()},this.reset=function(){b=-1;return a.reset()},this.cache=function(){return[].slice.call(c,0)}};c.prototype=new a;var d=function(a){this.item=a.item,this.next=a.next,this.reset=a.reset};d.prototype=new a;var e=function(a,b){this.item=a.item,this.next=a.next,this.reset=a.reset,b.item&&(this.item=function(){return b.item(a)}),b.next&&(this.next=function(){return b.next(a)}),b.reset&&(this.reset=function(){return b.reset(a)})};e.prototype=new a;var f=function(a){this.yield=function(b){a.yield&&a.yield(b)},this.end=function(){a.end&&a.end()}},g=function(c){var d,e=[],f=-1;if(!c)d=new b([]),e=[],f=0;else if(arguments.length>1)d=new b([].slice.call(arguments,0)),e=[].slice.call(arguments,0),f=e.length;else if(c instanceof Array)d=new b([].slice.call(c,0)),e=[].slice.call(c,0),f=e.length;else if(c instanceof a)d=c;else throw"source should be an array";this.at=function(a){var b=0;if(a<0)throw"incorrect index";if(e.length>a)return e[a];if(f>=0&&a>=f)throw"incorrect index";d.reset();while(d.next()){e[b]=d.item();if(a===0){var c=e[b];return c}a--,b++}f=b;throw"incorrect index"},this.length=function(){if(f<0){d.reset(),f=0;while(d.next())f++}return f},this.each=function(a){d.reset();for(var b=0;b<e.length;b++)d.next(),a.call(e[b],e[b]);var c=e.length;while(d.next())e[c]=d.item(),a.call(e[c],e[c]),c++;f=c;return this},this.toArray=function(){if(f<0||e.length<f){d.reset();for(var a=0;a<e.length;a++)d.next();var b=e.length;while(d.next())e[b]=d.item(),b++;f=b}return[].slice.call(e,0)},this.enumerator=function(){return d},this.cache=function(){return[].slice.call(e,0)}};g.prototype.reverse=function(){return new g(this.toArray().reverse())},g.prototype.map=function(a){var b=this,d=new e(b.enumerator(),{item:function(b){return a.call(b.item(),b.item())}});return new g(new c(d))},g.prototype.filter=function(a){var b=this,d=new e(b.enumerator(),{next:function(b){var c=!0;while((c=c&&b.next())&&!a.call(b.item(),b.item()));return c}});return new g(new c(d))},g.prototype.fold=function(a,b){var c=b;this.each(function(b){c=a.call(b,c,b)});return c},g.prototype.scan=function(a,b){var d=0,f=1,h=2,i=this,j=d,k,l=new e(i.enumerator(),{item:function(a){switch(j){case d:throw"incorrect index";case f:return k;case h:throw"incorrect index"}},next:function(c){var e,g;switch(j){case d:j=f,k=b;break;case f:g=c.next(),g?(e=c.item(),k=a.call(e,k,e)):j=h;break;case h:}return j!=h},reset:function(a){j=d,a.reset()}});return new g(new c(l))},g.prototype.takeWhile=function(a){var b=0,d=1,f=this,h=b,i=new e(f.enumerator(),{next:function(c){var e=!0;switch(h){case b:e=c.next()&&a.call(c.item(),c.item()),e||(h=d);break;case d:}return h!=d},reset:function(a){h=b,a.reset()}});return new g(new c(i))},g.prototype.take=function(a){var b=this,d=0,f=new e(b.enumerator(),{item:function(b){if(d<=a)return b.item();throw"incorrect index"},next:function(b){if(d<a){d++;return b.next()}return!1},reset:function(a){d=0,a.reset()}});return new g(new c(f))},g.prototype.dropWhile=function(a){var b=0,d=1,f=2,h=this,i=b,j=new e(h.enumerator(),{next:function(c){var e=!0;switch(i){case b:while((e=c.next())&&a.call(c.item(),c.item()));e?i=d:i=f;break;case d:e=c.next(),e||(i=f);break;case f:}return i!=f},reset:function(a){i=b,a.reset()}});return new g(new c(j))},g.prototype.drop=function(a){var b=0,d=1,f=2,h=this,i=b,j=new e(h.enumerator(),{next:function(c){var e=0,g=!0;switch(i){case b:while((g=c.next())&&e<a)e++;g?i=d:i=f;break;case d:g=c.next(),g||(i=f);break;case f:}return i!=f},reset:function(a){i=b,a.reset()}});return new g(new c(j))},g.prototype.cycle=function(){var a=this,b=new e(a.enumerator(),{next:function(a){if(a.next())return!0;a.reset();return a.next()?!0:!1}});return new g(new c(b))},g.generate=function(a){var b=0,e=1,h=2,i,j=b,k=e,l=[],m=NaN,n=new f({yield:function(a){k!=h&&(l[l.length]=a)},end:function(){k=h}}),o=new d({item:function(){switch(j){case b:throw"incorrect index";case e:return l[m];case h:throw"incorrect index"}},next:function(){switch(j){case b:case e:m++;if(k!=h)while(m>=l.length&&k!=h)a.call(n,n);j=k;break;case h:}return j!=h},reset:function(){m=-1,j=b}});return new g(new c(o))},g.iterate=function(a,b){var e=0,f=1,h,i=e,j=new d({item:function(){switch(i){case e:throw"incorrect index";case f:return h}},next:function(){switch(i){case e:h=b,i=f;break;case f:h=a.call(h,h)}return!0},reset:function(){i=e}});return new g(new c(j))},g.count=function(a,b){a=a||0,b=b||1;return g.iterate(function(a){return a+b},a)},g.repeat=function(a){return g.iterate(function(a){return a},a)},g.concatenate=function(){var a=0,b=1,e=2,f=[].slice.call(arguments,0),h=0,i=a,j=new d({item:function(){return f[h].enumerator().item()},next:function(){switch(i){case a:f[h].enumerator().reset(),i=b;return j.next();case b:if(!f[h].enumerator().next()){h++;if(h<f.length){i=a;return j.next()}i=e}break;case e:}return i!=e},reset:function(){h=0,i=a}});return new g(new c(j))},g.zip=function(a){var b=0,e=1,f=[].slice.call(arguments,1),h=b;if(f.length===0)return new g([]);f=new g(f);var i=new d({item:function(){var c;switch(h){case b:c=f.map(function(){return this.enumerator().item()}).toArray();return a.apply(c,c);case e:throw"incorrect index"}},next:function(){var a=!0;switch(h){case b:f.each(function(){a=a&&this.enumerator().next()}),a||(h=e);break;case e:}return h!=e},reset:function(){f.each(function(){this.enumerator().reset()}),h=b}});return new g(new c(i))},g.prototype.all=function(a){return this.fold(function(b,c){return b&&a.call(c,c)},!0)},g.prototype.any=function(a){return this.fold(function(b,c){return b||a.call(c,c)},!1)},g.prototype.sum=function(){return this.fold(function(a,b){return a+b},0)},g.prototype.average=function(){var a=this.fold(function(a,b){return[a[0]+b,a[1]+1]},[0,0]);return a[0]/a[1]},g.prototype.maximum=function(){var a=this.at(0);if(a)return this.drop(1).fold(function(a,b){return a>b?a:b},a);throw"cannot process empty list"},g.prototype.minimum=function(){var a=this.at(0);if(a)return this.drop(1).fold(function(a,b){return a<b?a:b},a);throw"cannot process empty list"},g.prototype.head=function(){if(this.take(1).length()<1)throw"cannot process empty list";return this.at(0)},g.prototype.tail=function(){if(this.take(1).length()<1)throw"cannot process empty list";return this.drop(1)},g.prototype.init=function(){if(this.take(1).length()<1)throw"cannot process empty list";var a=0,b=1,d=2,f=this,h=a,i,j=new e(f.enumerator(),{item:function(c){switch(h){case a:throw"incorrect index";case b:return i;case d:throw"incorrect index"}},next:function(c){var e=0,f=!0;switch(h){case a:c.next(),i=c.item(),f=c.next(),f?h=b:h=d;break;case b:i=c.item(),f=c.next(),f||(h=d);break;case d:}return h!=d},reset:function(b){h=a,b.reset()}});return new g(new c(j))},g.prototype.last=function(){if(this.take(1).length()<1)throw"cannot process empty list";return this.at(this.length()-1)};if(typeof module!="undefined"&&module.exports)module.exports=g;else if(window)window.List=g;else return}(),function(){var a;if(module&&module.exports)a=module.exports;else if(window)a=window.List;else return;var b=a.ES5Array=function(c){a.apply(this,arguments),this.indexOf=function(a,b){b=b||0;var c=b,d=this.drop(b).dropWhile(function(b){if(a!==b){c++;return!0}return!1});return d.take(1).length()>0?c:-1},this.lastIndexOf=function(a,b){b=b||this.length();var c=this.take(b),d=c.reverse(),e=this.indexOf.call(d,a);return e>=0?c.length()-1-e:-1},this.every=function(a,b){return this.all(function(c){return a.call(b,c)})},this.some=function(a,b){return this.any(function(c){return a.call(b,c)})},this.forEach=function(a,b){this.each(function(c){a.call(b,c)})},this.map=function(a,c){return b.prototype.map.call(this,function(b){return a.call(c,b)})},this.filter=function(a,c){return b.prototype.filter.call(this,function(b){return a.call(c,b)})};var d=this.reduce=function(a,b){return arguments.length>1?this.fold(function(b,c){return a.call(undefined,b,c)},b):d.call(this.drop(1),a,this.at(0))};this.reduceRight=function(a,b){return d.apply(this.reverse(),arguments)}};b.prototype=new a}(),function(){var Overload={};if(typeof module!="undefined"&&module.exports)module.exports=Overload;else if(window)window.Overload=Overload;else return;var copySignature=function(a){var b=a.slice(0);a.more&&(b.more=!0);return b},parseSignature=function(signature){if(signature.replace(/(^\s+|\s+$)/ig,"")==="")signature=[];else{signature=signature.split(",");for(var i=0;i<signature.length;i++){var typeExpression=signature[i].replace(/(^\s+|\s+$)/ig,""),type=null;if(typeExpression=="*")type=Overload.Any;else if(typeExpression=="...")type=Overload.More;else try{type=eval("("+typeExpression+")")}catch(error){throw"type expression cannot be evaluated: "+typeExpression}signature[i]=type}}return signature},inheritanceComparator=function(a,b){return a==b?0:b==Overload.Any?1:a==Overload.Any?-1:a.prototype instanceof b?1:b.prototype instanceof a?-1:0},overloadComparator=function(a,b){var c=!1,d=!1,e=a.signature,f=b.signature;if(!e.more&&f.more)c=!0,e=copySignature(e),e.length=f.length;else if(e.more&&!f.more)d=!0,f=copySignature(f),f.length=e.length;else if(e.more&&f.more)if(e.length>f.length){f=copySignature(f);while(f.length<e.length)f[f.length]=Overload.Any}else if(e.length<f.length){e=copySignature(e);while(e.length<f.length)e[e.length]=Overload.Any}for(var g=0;g<e.length;g++){var h=inheritanceComparator(e[g],f[g]);h>0?c=!0:h<0&&(d=!0)}return c&&!d?1:!c&&d?-1:0},matchSignature=function(a,b){if(a.length<b.length)return!1;if(a.length>b.length&&!b.more)return!1;for(var c=0;c<b.length;c++)if(!(a[c]===null||a[c]===undefined||b[c]==Overload.Any||a[c]instanceof b[c]||a[c].constructor==b[c]))return!1;return!0};Overload.create=function(a){var b=[],c=function(a){var c=[];for(var d=0;d<b.length;d++)matchSignature(a,b[d].signature)&&c.push(b[d]);return c},d=function(a){var b=c(a);switch(b.length){case 0:return null;case 1:return b[0];default:b=b.sort(overloadComparator);return overloadComparator(b[b.length-1],b[b.length-2])>0?b[b.length-1]:null}},e=function(){var a=d(arguments);if(a){var b=Array.prototype.slice.call(arguments,0);if(b.length>a.signature.length){var c=b.splice(a.signature.length);b.push(c)}return a["function"].apply(this,b)}throw"cannot select a proper overload"};e.match=c,e.select=d,e.add=function(a,c){if(a instanceof Array)a=copySignature(a);else if(a.constructor==String)a=parseSignature(a);else throw"signature is neither a string nor an array";for(var d=0;d<a.length;d++){if(!(a[d]instanceof Function))throw"argument type should be a function";if(d<a.length-1&&a[d]==Overload.More)throw"arguments type cannot be used in any argument except the last one"}a[a.length-1]==Overload.More&&(a.length=a.length-1,a.more=!0),b.push({signature:a,"function":c});return this};return e},Overload.add=function(a,b){return Overload.create().add(a,b)},Overload.Any=function(){throw"this type is only an identifier and should not be instantiated"},Overload.More=function(){throw"this type is only an identifier and should not be instantiated"}}()
View
70 build/jshelpers.js
@@ -41,7 +41,7 @@
raiseGlobalError(operation);
};
- this.yield = function(result) {
+ this["yield"] = function(result) {
var self = this;
if (self.error) {
@@ -140,13 +140,13 @@
};
this.go = function(initialArgument) {
- return this.yield(initialArgument);
- }
+ return this["yield"](initialArgument);
+ };
this.addCallback = function(callback) {
callbackQueue.push(callback);
if (this.completed || (chain && started)) {
- this.yield(this.result);
+ this["yield"](this.result);
}
return this;
};
@@ -179,16 +179,16 @@
Async.go = function(initialArgument) {
return Async.chain().go(initialArgument);
- }
+ };
Async.collect = function(functions, functionArguments) {
- var operation = new Async.Operation()
+ var operation = new Async.Operation();
var results = [];
var count = 0;
var checkCount = function() {
if (count == functions.length) {
- operation.yield(results);
+ operation["yield"](results);
}
};
@@ -203,7 +203,7 @@
if (functionResult && functionResult instanceof Async.Operation) {
functionResult.addCallback(function(result) {
results[i] = result;
- count++
+ count++;
checkCount();
});
} else {
@@ -220,14 +220,14 @@
Async.wait = function(delay, context) {
var operation = new Async.Operation();
setTimeout(function() {
- operation.yield(context);
+ operation["yield"](context);
}, delay);
return operation;
- }
+ };
Async.instant = function(context) {
return Async.wait(0, context);
- }
+ };
Async.onerror = function(callback) {
globalErrorCallbacks.push(callback);
@@ -247,7 +247,7 @@
var operation = new Async.Operation();
var self = this;
setTimeout(function() {
- operation.yield(self.apply(thisReference, argumentsArray || []));
+ operation["yield"](self.apply(thisReference, argumentsArray || []));
/* default value for argumentsArray is empty array */
/* IE8 throws when argumentsArray is undefined */
}, 1);
@@ -490,14 +490,13 @@
var AbstractEnumerator = function() {
};
- AbstractEnumerator.prototype.item = function() { throw "abstract enumerator should not be instantiated"; }
- AbstractEnumerator.prototype.next = function() { throw "abstract enumerator should not be instantiated"; }
- AbstractEnumerator.prototype.reset = function() { throw "abstract enumerator should not be instantiated"; }
+ AbstractEnumerator.prototype.item = function() { throw "abstract enumerator should not be instantiated"; };
+ AbstractEnumerator.prototype.next = function() { throw "abstract enumerator should not be instantiated"; };
+ AbstractEnumerator.prototype.reset = function() { throw "abstract enumerator should not be instantiated"; };
var ArrayEnumerator = function(array) {
var BEFORE = 0, RUNNING = 1, AFTER = 2;
var state = BEFORE;
- var array = array;
var index = 0;
this.item = function() {
@@ -513,7 +512,7 @@
this.next = function() {
switch (state) {
case BEFORE:
- if (array.length == 0) {
+ if (array.length === 0) {
state = AFTER;
} else {
state = RUNNING;
@@ -590,28 +589,28 @@
if (extensions.item) {
this.item = function() {
return extensions.item(innerEnumerator);
- }
+ };
}
if (extensions.next) {
this.next = function() {
return extensions.next(innerEnumerator);
- }
+ };
}
if (extensions.reset) {
this.reset = function() {
return extensions.reset(innerEnumerator);
- }
+ };
}
};
StackedEnumerator.prototype = new AbstractEnumerator();
var GeneratorProxy = function(handlers) {
- this.yield = function(object) {
- if (handlers.yield) {
- handlers.yield(object);
+ this["yield"] = function(object) {
+ if (handlers["yield"]) {
+ handlers["yield"](object);
}
};
@@ -661,7 +660,7 @@
enumerator.reset();
while (enumerator.next()) {
arrayCache[cacheIndex] = enumerator.item();
- if (index == 0) {
+ if (index === 0) {
var item = arrayCache[cacheIndex];
return item;
} else {
@@ -994,7 +993,7 @@
var index = NaN;
var proxy = new GeneratorProxy({
- yield: function(object) {
+ "yield": function(object) {
if (yieldState != AFTER) {
arrayCache[arrayCache.length] = object;
}
@@ -1080,8 +1079,8 @@
};
List.count = function(start, step) {
- var start = start || 0;
- var step = step || 1;
+ start = start || 0;
+ step = step || 1;
return List.iterate(function(object) { return object + step; }, start);
};
@@ -1106,7 +1105,6 @@
lists[listsIndex].enumerator().reset();
state = RUNNING;
return enumerator.next();
- break;
case RUNNING:
if (!lists[listsIndex].enumerator().next()) {
listsIndex++;
@@ -1138,7 +1136,7 @@
var lists = [].slice.call(arguments, 1);
var state = RUNNING;
- if (lists.length == 0) {
+ if (lists.length === 0) {
return new List([]);
}
@@ -1217,7 +1215,7 @@
return accumulation > object ? accumulation : object;
}, first);
} else {
- throw "cannot process empty list"
+ throw "cannot process empty list";
}
};
@@ -1228,7 +1226,7 @@
return accumulation < object ? accumulation : object;
}, first);
} else {
- throw "cannot process empty list"
+ throw "cannot process empty list";
}
};
@@ -1395,7 +1393,7 @@
});
};
- this.reduce = function(callbackfn, initialValue) {
+ var reduce = this.reduce = function(callbackfn, initialValue) {
if (arguments.length > 1) {
return this.fold(function(accumulation, object) {
return callbackfn.call(undefined, accumulation, object);
@@ -1411,8 +1409,6 @@
};
ES5Array.prototype = new List();
-
- var reduce = new ES5Array(0).reduce;
})();
(function() {
var Overload = {};
@@ -1433,7 +1429,7 @@
};
var parseSignature = function(signature) {
- if (signature.replace(/(^\s+|\s+$)/ig, "") == "") {
+ if (signature.replace(/(^\s+|\s+$)/ig, "") === "") {
signature = [];
} else {
signature = signature.split(",");
@@ -1620,10 +1616,10 @@
};
Overload.Any = function any() {
- throw "this type is only an identifier and should not be instantiated"
+ throw "this type is only an identifier and should not be instantiated";
};
Overload.More = function more() {
- throw "this type is only an identifier and should not be instantiated"
+ throw "this type is only an identifier and should not be instantiated";
};
})();
View
2 build/list-min.js
@@ -1 +1 @@
-(function(){var a=function(){};a.prototype.item=function(){throw"abstract enumerator should not be instantiated"},a.prototype.next=function(){throw"abstract enumerator should not be instantiated"},a.prototype.reset=function(){throw"abstract enumerator should not be instantiated"};var b=function(a){var b=0,c=1,d=2,e=b,a=a,f=0;this.item=function(){if(e==c)return a[f];if(e==b)throw"incorrect index";if(e==d)throw"incorrect index"},this.next=function(){switch(e){case b:a.length==0?e=d:e=c;break;case c:f++,f>=a.length&&(e=d);break;case d:}return e!=d},this.reset=function(){e=b,f=0}};b.prototype=new a;var c=function(a){var b=NaN,c=[];this.item=function(){if(b>=0){b in c||(c[b]=a.item());return c[b]}return a.item()},this.next=function(){b>=-1&&b++;return a.next()},this.reset=function(){b=-1;return a.reset()},this.cache=function(){return[].slice.call(c,0)}};c.prototype=new a;var d=function(a){this.item=a.item,this.next=a.next,this.reset=a.reset};d.prototype=new a;var e=function(a,b){this.item=a.item,this.next=a.next,this.reset=a.reset,b.item&&(this.item=function(){return b.item(a)}),b.next&&(this.next=function(){return b.next(a)}),b.reset&&(this.reset=function(){return b.reset(a)})};e.prototype=new a;var f=function(a){this.yield=function(b){a.yield&&a.yield(b)},this.end=function(){a.end&&a.end()}},g=function(c){var d,e=[],f=-1;if(!c)d=new b([]),e=[],f=0;else if(arguments.length>1)d=new b([].slice.call(arguments,0)),e=[].slice.call(arguments,0),f=e.length;else if(c instanceof Array)d=new b([].slice.call(c,0)),e=[].slice.call(c,0),f=e.length;else if(c instanceof a)d=c;else throw"source should be an array";this.at=function(a){var b=0;if(a<0)throw"incorrect index";if(e.length>a)return e[a];if(f>=0&&a>=f)throw"incorrect index";d.reset();while(d.next()){e[b]=d.item();if(a==0){var c=e[b];return c}a--,b++}f=b;throw"incorrect index"},this.length=function(){if(f<0){d.reset(),f=0;while(d.next())f++}return f},this.each=function(a){d.reset();for(var b=0;b<e.length;b++)d.next(),a.call(e[b],e[b]);var c=e.length;while(d.next())e[c]=d.item(),a.call(e[c],e[c]),c++;f=c;return this},this.toArray=function(){if(f<0||e.length<f){d.reset();for(var a=0;a<e.length;a++)d.next();var b=e.length;while(d.next())e[b]=d.item(),b++;f=b}return[].slice.call(e,0)},this.enumerator=function(){return d},this.cache=function(){return[].slice.call(e,0)}};g.prototype.reverse=function(){return new g(this.toArray().reverse())},g.prototype.map=function(a){var b=this,d=new e(b.enumerator(),{item:function(b){return a.call(b.item(),b.item())}});return new g(new c(d))},g.prototype.filter=function(a){var b=this,d=new e(b.enumerator(),{next:function(b){var c=!0;while((c=c&&b.next())&&!a.call(b.item(),b.item()));return c}});return new g(new c(d))},g.prototype.fold=function(a,b){var c=b;this.each(function(b){c=a.call(b,c,b)});return c},g.prototype.scan=function(a,b){var d=0,f=1,h=2,i=this,j=d,k,l=new e(i.enumerator(),{item:function(a){switch(j){case d:throw"incorrect index";case f:return k;case h:throw"incorrect index"}},next:function(c){var e,g;switch(j){case d:j=f,k=b;break;case f:g=c.next(),g?(e=c.item(),k=a.call(e,k,e)):j=h;break;case h:}return j!=h},reset:function(a){j=d,a.reset()}});return new g(new c(l))},g.prototype.takeWhile=function(a){var b=0,d=1,f=this,h=b,i=new e(f.enumerator(),{next:function(c){var e=!0;switch(h){case b:e=c.next()&&a.call(c.item(),c.item()),e||(h=d);break;case d:}return h!=d},reset:function(a){h=b,a.reset()}});return new g(new c(i))},g.prototype.take=function(a){var b=this,d=0,f=new e(b.enumerator(),{item:function(b){if(d<=a)return b.item();throw"incorrect index"},next:function(b){if(d<a){d++;return b.next()}return!1},reset:function(a){d=0,a.reset()}});return new g(new c(f))},g.prototype.dropWhile=function(a){var b=0,d=1,f=2,h=this,i=b,j=new e(h.enumerator(),{next:function(c){var e=!0;switch(i){case b:while((e=c.next())&&a.call(c.item(),c.item()));e?i=d:i=f;break;case d:e=c.next(),e||(i=f);break;case f:}return i!=f},reset:function(a){i=b,a.reset()}});return new g(new c(j))},g.prototype.drop=function(a){var b=0,d=1,f=2,h=this,i=b,j=new e(h.enumerator(),{next:function(c){var e=0,g=!0;switch(i){case b:while((g=c.next())&&e<a)e++;g?i=d:i=f;break;case d:g=c.next(),g||(i=f);break;case f:}return i!=f},reset:function(a){i=b,a.reset()}});return new g(new c(j))},g.prototype.cycle=function(){var a=this,b=new e(a.enumerator(),{next:function(a){if(a.next())return!0;a.reset();return a.next()?!0:!1}});return new g(new c(b))},g.generate=function(a){var b=0,e=1,h=2,i,j=b,k=e,l=[],m=NaN,n=new f({yield:function(a){k!=h&&(l[l.length]=a)},end:function(){k=h}}),o=new d({item:function(){switch(j){case b:throw"incorrect index";case e:return l[m];case h:throw"incorrect index"}},next:function(){switch(j){case b:case e:m++;if(k!=h)while(m>=l.length&&k!=h)a.call(n,n);j=k;break;case h:}return j!=h},reset:function(){m=-1,j=b}});return new g(new c(o))},g.iterate=function(a,b){var e=0,f=1,h,i=e,j=new d({item:function(){switch(i){case e:throw"incorrect index";case f:return h}},next:function(){switch(i){case e:h=b,i=f;break;case f:h=a.call(h,h)}return!0},reset:function(){i=e}});return new g(new c(j))},g.count=function(a,b){var a=a||0,b=b||1;return g.iterate(function(a){return a+b},a)},g.repeat=function(a){return g.iterate(function(a){return a},a)},g.concatenate=function(){var a=0,b=1,e=2,f=[].slice.call(arguments,0),h=0,i=a,j=new d({item:function(){return f[h].enumerator().item()},next:function(){switch(i){case a:f[h].enumerator().reset(),i=b;return j.next();case b:if(!f[h].enumerator().next()){h++;if(h<f.length){i=a;return j.next()}i=e}break;case e:}return i!=e},reset:function(){h=0,i=a}});return new g(new c(j))},g.zip=function(a){var b=0,e=1,f=[].slice.call(arguments,1),h=b;if(f.length==0)return new g([]);f=new g(f);var i=new d({item:function(){var c;switch(h){case b:c=f.map(function(){return this.enumerator().item()}).toArray();return a.apply(c,c);case e:throw"incorrect index"}},next:function(){var a=!0;switch(h){case b:f.each(function(){a=a&&this.enumerator().next()}),a||(h=e);break;case e:}return h!=e},reset:function(){f.each(function(){this.enumerator().reset()}),h=b}});return new g(new c(i))},g.prototype.all=function(a){return this.fold(function(b,c){return b&&a.call(c,c)},!0)},g.prototype.any=function(a){return this.fold(function(b,c){return b||a.call(c,c)},!1)},g.prototype.sum=function(){return this.fold(function(a,b){return a+b},0)},g.prototype.average=function(){var a=this.fold(function(a,b){return[a[0]+b,a[1]+1]},[0,0]);return a[0]/a[1]},g.prototype.maximum=function(){var a=this.at(0);if(a)return this.drop(1).fold(function(a,b){return a>b?a:b},a);throw"cannot process empty list"},g.prototype.minimum=function(){var a=this.at(0);if(a)return this.drop(1).fold(function(a,b){return a<b?a:b},a);throw"cannot process empty list"},g.prototype.head=function(){if(this.take(1).length()<1)throw"cannot process empty list";return this.at(0)},g.prototype.tail=function(){if(this.take(1).length()<1)throw"cannot process empty list";return this.drop(1)},g.prototype.init=function(){if(this.take(1).length()<1)throw"cannot process empty list";var a=0,b=1,d=2,f=this,h=a,i,j=new e(f.enumerator(),{item:function(c){switch(h){case a:throw"incorrect index";case b:return i;case d:throw"incorrect index"}},next:function(c){var e=0,f=!0;switch(h){case a:c.next(),i=c.item(),f=c.next(),f?h=b:h=d;break;case b:i=c.item(),f=c.next(),f||(h=d);break;case d:}return h!=d},reset:function(b){h=a,b.reset()}});return new g(new c(j))},g.prototype.last=function(){if(this.take(1).length()<1)throw"cannot process empty list";return this.at(this.length()-1)};if(typeof module!="undefined"&&module.exports)module.exports=g;else if(window)window.List=g;else return})(),function(){var a;if(module&&module.exports)a=module.exports;else if(window)a=window.List;else return;var b=a.ES5Array=function(d){a.apply(this,arguments),this.indexOf=function(a,b){b=b||0;var c=b,d=this.drop(b).dropWhile(function(b){if(a!==b){c++;return!0}return!1});return d.take(1).length()>0?c:-1},this.lastIndexOf=function(a,b){b=b||this.length();var c=this.take(b),d=c.reverse(),e=this.indexOf.call(d,a);return e>=0?c.length()-1-e:-1},this.every=function(a,b){return this.all(function(c){return a.call(b,c)})},this.some=function(a,b){return this.any(function(c){return a.call(b,c)})},this.forEach=function(a,b){this.each(function(c){a.call(b,c)})},this.map=function(a,c){return b.prototype.map.call(this,function(b){return a.call(c,b)})},this.filter=function(a,c){return b.prototype.filter.call(this,function(b){return a.call(c,b)})},this.reduce=function(a,b){return arguments.length>1?this.fold(function(b,c){return a.call(undefined,b,c)},b):c.call(this.drop(1),a,this.at(0))},this.reduceRight=function(a,b){return c.apply(this.reverse(),arguments)}};b.prototype=new a;var c=(new b(0)).reduce}()
+(function(){var a=function(){};a.prototype.item=function(){throw"abstract enumerator should not be instantiated"},a.prototype.next=function(){throw"abstract enumerator should not be instantiated"},a.prototype.reset=function(){throw"abstract enumerator should not be instantiated"};var b=function(a){var b=0,c=1,d=2,e=b,f=0;this.item=function(){if(e==c)return a[f];if(e==b)throw"incorrect index";if(e==d)throw"incorrect index"},this.next=function(){switch(e){case b:a.length===0?e=d:e=c;break;case c:f++,f>=a.length&&(e=d);break;case d:}return e!=d},this.reset=function(){e=b,f=0}};b.prototype=new a;var c=function(a){var b=NaN,c=[];this.item=function(){if(b>=0){b in c||(c[b]=a.item());return c[b]}return a.item()},this.next=function(){b>=-1&&b++;return a.next()},this.reset=function(){b=-1;return a.reset()},this.cache=function(){return[].slice.call(c,0)}};c.prototype=new a;var d=function(a){this.item=a.item,this.next=a.next,this.reset=a.reset};d.prototype=new a;var e=function(a,b){this.item=a.item,this.next=a.next,this.reset=a.reset,b.item&&(this.item=function(){return b.item(a)}),b.next&&(this.next=function(){return b.next(a)}),b.reset&&(this.reset=function(){return b.reset(a)})};e.prototype=new a;var f=function(a){this.yield=function(b){a.yield&&a.yield(b)},this.end=function(){a.end&&a.end()}},g=function(c){var d,e=[],f=-1;if(!c)d=new b([]),e=[],f=0;else if(arguments.length>1)d=new b([].slice.call(arguments,0)),e=[].slice.call(arguments,0),f=e.length;else if(c instanceof Array)d=new b([].slice.call(c,0)),e=[].slice.call(c,0),f=e.length;else if(c instanceof a)d=c;else throw"source should be an array";this.at=function(a){var b=0;if(a<0)throw"incorrect index";if(e.length>a)return e[a];if(f>=0&&a>=f)throw"incorrect index";d.reset();while(d.next()){e[b]=d.item();if(a===0){var c=e[b];return c}a--,b++}f=b;throw"incorrect index"},this.length=function(){if(f<0){d.reset(),f=0;while(d.next())f++}return f},this.each=function(a){d.reset();for(var b=0;b<e.length;b++)d.next(),a.call(e[b],e[b]);var c=e.length;while(d.next())e[c]=d.item(),a.call(e[c],e[c]),c++;f=c;return this},this.toArray=function(){if(f<0||e.length<f){d.reset();for(var a=0;a<e.length;a++)d.next();var b=e.length;while(d.next())e[b]=d.item(),b++;f=b}return[].slice.call(e,0)},this.enumerator=function(){return d},this.cache=function(){return[].slice.call(e,0)}};g.prototype.reverse=function(){return new g(this.toArray().reverse())},g.prototype.map=function(a){var b=this,d=new e(b.enumerator(),{item:function(b){return a.call(b.item(),b.item())}});return new g(new c(d))},g.prototype.filter=function(a){var b=this,d=new e(b.enumerator(),{next:function(b){var c=!0;while((c=c&&b.next())&&!a.call(b.item(),b.item()));return c}});return new g(new c(d))},g.prototype.fold=function(a,b){var c=b;this.each(function(b){c=a.call(b,c,b)});return c},g.prototype.scan=function(a,b){var d=0,f=1,h=2,i=this,j=d,k,l=new e(i.enumerator(),{item:function(a){switch(j){case d:throw"incorrect index";case f:return k;case h:throw"incorrect index"}},next:function(c){var e,g;switch(j){case d:j=f,k=b;break;case f:g=c.next(),g?(e=c.item(),k=a.call(e,k,e)):j=h;break;case h:}return j!=h},reset:function(a){j=d,a.reset()}});return new g(new c(l))},g.prototype.takeWhile=function(a){var b=0,d=1,f=this,h=b,i=new e(f.enumerator(),{next:function(c){var e=!0;switch(h){case b:e=c.next()&&a.call(c.item(),c.item()),e||(h=d);break;case d:}return h!=d},reset:function(a){h=b,a.reset()}});return new g(new c(i))},g.prototype.take=function(a){var b=this,d=0,f=new e(b.enumerator(),{item:function(b){if(d<=a)return b.item();throw"incorrect index"},next:function(b){if(d<a){d++;return b.next()}return!1},reset:function(a){d=0,a.reset()}});return new g(new c(f))},g.prototype.dropWhile=function(a){var b=0,d=1,f=2,h=this,i=b,j=new e(h.enumerator(),{next:function(c){var e=!0;switch(i){case b:while((e=c.next())&&a.call(c.item(),c.item()));e?i=d:i=f;break;case d:e=c.next(),e||(i=f);break;case f:}return i!=f},reset:function(a){i=b,a.reset()}});return new g(new c(j))},g.prototype.drop=function(a){var b=0,d=1,f=2,h=this,i=b,j=new e(h.enumerator(),{next:function(c){var e=0,g=!0;switch(i){case b:while((g=c.next())&&e<a)e++;g?i=d:i=f;break;case d:g=c.next(),g||(i=f);break;case f:}return i!=f},reset:function(a){i=b,a.reset()}});return new g(new c(j))},g.prototype.cycle=function(){var a=this,b=new e(a.enumerator(),{next:function(a){if(a.next())return!0;a.reset();return a.next()?!0:!1}});return new g(new c(b))},g.generate=function(a){var b=0,e=1,h=2,i,j=b,k=e,l=[],m=NaN,n=new f({yield:function(a){k!=h&&(l[l.length]=a)},end:function(){k=h}}),o=new d({item:function(){switch(j){case b:throw"incorrect index";case e:return l[m];case h:throw"incorrect index"}},next:function(){switch(j){case b:case e:m++;if(k!=h)while(m>=l.length&&k!=h)a.call(n,n);j=k;break;case h:}return j!=h},reset:function(){m=-1,j=b}});return new g(new c(o))},g.iterate=function(a,b){var e=0,f=1,h,i=e,j=new d({item:function(){switch(i){case e:throw"incorrect index";case f:return h}},next:function(){switch(i){case e:h=b,i=f;break;case f:h=a.call(h,h)}return!0},reset:function(){i=e}});return new g(new c(j))},g.count=function(a,b){a=a||0,b=b||1;return g.iterate(function(a){return a+b},a)},g.repeat=function(a){return g.iterate(function(a){return a},a)},g.concatenate=function(){var a=0,b=1,e=2,f=[].slice.call(arguments,0),h=0,i=a,j=new d({item:function(){return f[h].enumerator().item()},next:function(){switch(i){case a:f[h].enumerator().reset(),i=b;return j.next();case b:if(!f[h].enumerator().next()){h++;if(h<f.length){i=a;return j.next()}i=e}break;case e:}return i!=e},reset:function(){h=0,i=a}});return new g(new c(j))},g.zip=function(a){var b=0,e=1,f=[].slice.call(arguments,1),h=b;if(f.length===0)return new g([]);f=new g(f);var i=new d({item:function(){var c;switch(h){case b:c=f.map(function(){return this.enumerator().item()}).toArray();return a.apply(c,c);case e:throw"incorrect index"}},next:function(){var a=!0;switch(h){case b:f.each(function(){a=a&&this.enumerator().next()}),a||(h=e);break;case e:}return h!=e},reset:function(){f.each(function(){this.enumerator().reset()}),h=b}});return new g(new c(i))},g.prototype.all=function(a){return this.fold(function(b,c){return b&&a.call(c,c)},!0)},g.prototype.any=function(a){return this.fold(function(b,c){return b||a.call(c,c)},!1)},g.prototype.sum=function(){return this.fold(function(a,b){return a+b},0)},g.prototype.average=function(){var a=this.fold(function(a,b){return[a[0]+b,a[1]+1]},[0,0]);return a[0]/a[1]},g.prototype.maximum=function(){var a=this.at(0);if(a)return this.drop(1).fold(function(a,b){return a>b?a:b},a);throw"cannot process empty list"},g.prototype.minimum=function(){var a=this.at(0);if(a)return this.drop(1).fold(function(a,b){return a<b?a:b},a);throw"cannot process empty list"},g.prototype.head=function(){if(this.take(1).length()<1)throw"cannot process empty list";return this.at(0)},g.prototype.tail=function(){if(this.take(1).length()<1)throw"cannot process empty list";return this.drop(1)},g.prototype.init=function(){if(this.take(1).length()<1)throw"cannot process empty list";var a=0,b=1,d=2,f=this,h=a,i,j=new e(f.enumerator(),{item:function(c){switch(h){case a:throw"incorrect index";case b:return i;case d:throw"incorrect index"}},next:function(c){var e=0,f=!0;switch(h){case a:c.next(),i=c.item(),f=c.next(),f?h=b:h=d;break;case b:i=c.item(),f=c.next(),f||(h=d);break;case d:}return h!=d},reset:function(b){h=a,b.reset()}});return new g(new c(j))},g.prototype.last=function(){if(this.take(1).length()<1)throw"cannot process empty list";return this.at(this.length()-1)};if(typeof module!="undefined"&&module.exports)module.exports=g;else if(window)window.List=g;else return})(),function(){var a;if(module&&module.exports)a=module.exports;else if(window)a=window.List;else return;var b=a.ES5Array=function(c){a.apply(this,arguments),this.indexOf=function(a,b){b=b||0;var c=b,d=this.drop(b).dropWhile(function(b){if(a!==b){c++;return!0}return!1});return d.take(1).length()>0?c:-1},this.lastIndexOf=function(a,b){b=b||this.length();var c=this.take(b),d=c.reverse(),e=this.indexOf.call(d,a);return e>=0?c.length()-1-e:-1},this.every=function(a,b){return this.all(function(c){return a.call(b,c)})},this.some=function(a,b){return this.any(function(c){return a.call(b,c)})},this.forEach=function(a,b){this.each(function(c){a.call(b,c)})},this.map=function(a,c){return b.prototype.map.call(this,function(b){return a.call(c,b)})},this.filter=function(a,c){return b.prototype.filter.call(this,function(b){return a.call(c,b)})};var d=this.reduce=function(a,b){return arguments.length>1?this.fold(function(b,c){return a.call(undefined,b,c)},b):d.call(this.drop(1),a,this.at(0))};this.reduceRight=function(a,b){return d.apply(this.reverse(),arguments)}};b.prototype=new a}()
View
40 build/list.js
@@ -2,14 +2,13 @@
var AbstractEnumerator = function() {
};
- AbstractEnumerator.prototype.item = function() { throw "abstract enumerator should not be instantiated"; }
- AbstractEnumerator.prototype.next = function() { throw "abstract enumerator should not be instantiated"; }
- AbstractEnumerator.prototype.reset = function() { throw "abstract enumerator should not be instantiated"; }
+ AbstractEnumerator.prototype.item = function() { throw "abstract enumerator should not be instantiated"; };
+ AbstractEnumerator.prototype.next = function() { throw "abstract enumerator should not be instantiated"; };
+ AbstractEnumerator.prototype.reset = function() { throw "abstract enumerator should not be instantiated"; };
var ArrayEnumerator = function(array) {
var BEFORE = 0, RUNNING = 1, AFTER = 2;
var state = BEFORE;
- var array = array;
var index = 0;
this.item = function() {
@@ -25,7 +24,7 @@
this.next = function() {
switch (state) {
case BEFORE:
- if (array.length == 0) {
+ if (array.length === 0) {
state = AFTER;
} else {
state = RUNNING;
@@ -102,28 +101,28 @@
if (extensions.item) {
this.item = function() {
return extensions.item(innerEnumerator);
- }
+ };
}
if (extensions.next) {
this.next = function() {
return extensions.next(innerEnumerator);
- }
+ };
}
if (extensions.reset) {
this.reset = function() {
return extensions.reset(innerEnumerator);
- }
+ };
}
};
StackedEnumerator.prototype = new AbstractEnumerator();
var GeneratorProxy = function(handlers) {
- this.yield = function(object) {
- if (handlers.yield) {
- handlers.yield(object);
+ this["yield"] = function(object) {
+ if (handlers["yield"]) {
+ handlers["yield"](object);
}
};
@@ -173,7 +172,7 @@
enumerator.reset();
while (enumerator.next()) {
arrayCache[cacheIndex] = enumerator.item();
- if (index == 0) {
+ if (index === 0) {
var item = arrayCache[cacheIndex];
return item;
} else {
@@ -506,7 +505,7 @@
var index = NaN;
var proxy = new GeneratorProxy({
- yield: function(object) {
+ "yield": function(object) {
if (yieldState != AFTER) {
arrayCache[arrayCache.length] = object;
}
@@ -592,8 +591,8 @@
};
List.count = function(start, step) {
- var start = start || 0;
- var step = step || 1;
+ start = start || 0;
+ step = step || 1;
return List.iterate(function(object) { return object + step; }, start);
};
@@ -618,7 +617,6 @@
lists[listsIndex].enumerator().reset();
state = RUNNING;
return enumerator.next();
- break;
case RUNNING:
if (!lists[listsIndex].enumerator().next()) {
listsIndex++;
@@ -650,7 +648,7 @@
var lists = [].slice.call(arguments, 1);
var state = RUNNING;
- if (lists.length == 0) {
+ if (lists.length === 0) {
return new List([]);
}
@@ -729,7 +727,7 @@
return accumulation > object ? accumulation : object;
}, first);
} else {
- throw "cannot process empty list"
+ throw "cannot process empty list";
}
};
@@ -740,7 +738,7 @@
return accumulation < object ? accumulation : object;
}, first);
} else {
- throw "cannot process empty list"
+ throw "cannot process empty list";
}
};
@@ -907,7 +905,7 @@
});
};
- this.reduce = function(callbackfn, initialValue) {
+ var reduce = this.reduce = function(callbackfn, initialValue) {
if (arguments.length > 1) {
return this.fold(function(accumulation, object) {
return callbackfn.call(undefined, accumulation, object);
@@ -923,6 +921,4 @@
};
ES5Array.prototype = new List();
-
- var reduce = new ES5Array(0).reduce;
})();
View
2 build/overload-min.js
@@ -1 +1 @@
-(function(){var Overload={};if(typeof module!="undefined"&&module.exports)module.exports=Overload;else if(window)window.Overload=Overload;else return;var copySignature=function(a){var b=a.slice(0);a.more&&(b.more=!0);return b},parseSignature=function(signature){if(signature.replace(/(^\s+|\s+$)/ig,"")=="")signature=[];else{signature=signature.split(",");for(var i=0;i<signature.length;i++){var typeExpression=signature[i].replace(/(^\s+|\s+$)/ig,""),type=null;if(typeExpression=="*")type=Overload.Any;else if(typeExpression=="...")type=Overload.More;else try{type=eval("("+typeExpression+")")}catch(error){throw"type expression cannot be evaluated: "+typeExpression}signature[i]=type}}return signature},inheritanceComparator=function(a,b){return a==b?0:b==Overload.Any?1:a==Overload.Any?-1:a.prototype instanceof b?1:b.prototype instanceof a?-1:0},overloadComparator=function(a,b){var c=!1,d=!1,e=a.signature,f=b.signature;if(!e.more&&f.more)c=!0,e=copySignature(e),e.length=f.length;else if(e.more&&!f.more)d=!0,f=copySignature(f),f.length=e.length;else if(e.more&&f.more)if(e.length>f.length){f=copySignature(f);while(f.length<e.length)f[f.length]=Overload.Any}else if(e.length<f.length){e=copySignature(e);while(e.length<f.length)e[e.length]=Overload.Any}for(var g=0;g<e.length;g++){var h=inheritanceComparator(e[g],f[g]);h>0?c=!0:h<0&&(d=!0)}return c&&!d?1:!c&&d?-1:0},matchSignature=function(a,b){if(a.length<b.length)return!1;if(a.length>b.length&&!b.more)return!1;for(var c=0;c<b.length;c++)if(!(a[c]===null||a[c]===undefined||b[c]==Overload.Any||a[c]instanceof b[c]||a[c].constructor==b[c]))return!1;return!0};Overload.create=function(a){var b=[],c=function(a){var c=[];for(var d=0;d<b.length;d++)matchSignature(a,b[d].signature)&&c.push(b[d]);return c},d=function(a){var b=c(a);switch(b.length){case 0:return null;case 1:return b[0];default:b=b.sort(overloadComparator);return overloadComparator(b[b.length-1],b[b.length-2])>0?b[b.length-1]:null}},e=function(){var a=d(arguments);if(a){var b=Array.prototype.slice.call(arguments,0);if(b.length>a.signature.length){var c=b.splice(a.signature.length);b.push(c)}return a["function"].apply(this,b)}throw"cannot select a proper overload"};e.match=c,e.select=d,e.add=function(a,c){if(a instanceof Array)a=copySignature(a);else if(a.constructor==String)a=parseSignature(a);else throw"signature is neither a string nor an array";for(var d=0;d<a.length;d++){if(!(a[d]instanceof Function))throw"argument type should be a function";if(d<a.length-1&&a[d]==Overload.More)throw"arguments type cannot be used in any argument except the last one"}a[a.length-1]==Overload.More&&(a.length=a.length-1,a.more=!0),b.push({signature:a,"function":c});return this};return e},Overload.add=function(a,b){return Overload.create().add(a,b)},Overload.Any=function(){throw"this type is only an identifier and should not be instantiated"},Overload.More=function(){throw"this type is only an identifier and should not be instantiated"}})()
+(function(){var Overload={};if(typeof module!="undefined"&&module.exports)module.exports=Overload;else if(window)window.Overload=Overload;else return;var copySignature=function(a){var b=a.slice(0);a.more&&(b.more=!0);return b},parseSignature=function(signature){if(signature.replace(/(^\s+|\s+$)/ig,"")==="")signature=[];else{signature=signature.split(",");for(var i=0;i<signature.length;i++){var typeExpression=signature[i].replace(/(^\s+|\s+$)/ig,""),type=null;if(typeExpression=="*")type=Overload.Any;else if(typeExpression=="...")type=Overload.More;else try{type=eval("("+typeExpression+")")}catch(error){throw"type expression cannot be evaluated: "+typeExpression}signature[i]=type}}return signature},inheritanceComparator=function(a,b){return a==b?0:b==Overload.Any?1:a==Overload.Any?-1:a.prototype instanceof b?1:b.prototype instanceof a?-1:0},overloadComparator=function(a,b){var c=!1,d=!1,e=a.signature,f=b.signature;if(!e.more&&f.more)c=!0,e=copySignature(e),e.length=f.length;else if(e.more&&!f.more)d=!0,f=copySignature(f),f.length=e.length;else if(e.more&&f.more)if(e.length>f.length){f=copySignature(f);while(f.length<e.length)f[f.length]=Overload.Any}else if(e.length<f.length){e=copySignature(e);while(e.length<f.length)e[e.length]=Overload.Any}for(var g=0;g<e.length;g++){var h=inheritanceComparator(e[g],f[g]);h>0?c=!0:h<0&&(d=!0)}return c&&!d?1:!c&&d?-1:0},matchSignature=function(a,b){if(a.length<b.length)return!1;if(a.length>b.length&&!b.more)return!1;for(var c=0;c<b.length;c++)if(!(a[c]===null||a[c]===undefined||b[c]==Overload.Any||a[c]instanceof b[c]||a[c].constructor==b[c]))return!1;return!0};Overload.create=function(a){var b=[],c=function(a){var c=[];for(var d=0;d<b.length;d++)matchSignature(a,b[d].signature)&&c.push(b[d]);return c},d=function(a){var b=c(a);switch(b.length){case 0:return null;case 1:return b[0];default:b=b.sort(overloadComparator);return overloadComparator(b[b.length-1],b[b.length-2])>0?b[b.length-1]:null}},e=function(){var a=d(arguments);if(a){var b=Array.prototype.slice.call(arguments,0);if(b.length>a.signature.length){var c=b.splice(a.signature.length);b.push(c)}return a["function"].apply(this,b)}throw"cannot select a proper overload"};e.match=c,e.select=d,e.add=function(a,c){if(a instanceof Array)a=copySignature(a);else if(a.constructor==String)a=parseSignature(a);else throw"signature is neither a string nor an array";for(var d=0;d<a.length;d++){if(!(a[d]instanceof Function))throw"argument type should be a function";if(d<a.length-1&&a[d]==Overload.More)throw"arguments type cannot be used in any argument except the last one"}a[a.length-1]==Overload.More&&(a.length=a.length-1,a.more=!0),b.push({signature:a,"function":c});return this};return e},Overload.add=function(a,b){return Overload.create().add(a,b)},Overload.Any=function(){throw"this type is only an identifier and should not be instantiated"},Overload.More=function(){throw"this type is only an identifier and should not be instantiated"}})()
View
6 build/overload.js
@@ -17,7 +17,7 @@
};
var parseSignature = function(signature) {
- if (signature.replace(/(^\s+|\s+$)/ig, "") == "") {
+ if (signature.replace(/(^\s+|\s+$)/ig, "") === "") {
signature = [];
} else {
signature = signature.split(",");
@@ -204,10 +204,10 @@
};
Overload.Any = function any() {
- throw "this type is only an identifier and should not be instantiated"
+ throw "this type is only an identifier and should not be instantiated";
};
Overload.More = function more() {
- throw "this type is only an identifier and should not be instantiated"
+ throw "this type is only an identifier and should not be instantiated";
};
})();

0 comments on commit 59174ae

Please sign in to comment.