This repository was archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmonapt.min.js
1 lines (1 loc) · 8.44 KB
/
monapt.min.js
1
var monapt;!function(a){a.Tuple1=function(a){return{_1:a}},a.Tuple2=function(a,b){return{_1:a,_2:b}}}(monapt||(monapt={}));var monapt;!function(a){var b=function(a){return a},c=function(){function a(a){this.value=a,this.isEmpty=!1}return a.prototype.get=function(){return this.value},a.prototype.getOrElse=function(){return this.value},a.prototype.orElse=function(){return this},a.prototype.match=function(a){a.Some&&a.Some(this.value)},a.prototype.map=function(b){return new a(b(this.get()))},a.prototype.flatMap=function(a){return a(this.get())},a.prototype.filter=function(a){return a(this.value)?this:new d},a.prototype.reject=function(a){return this.filter(function(b){return!a(b)})},a.prototype.foreach=function(a){a(this.value)},a}();a.Some=c;var d=function(){function a(){this.isEmpty=!0}return a.prototype.get=function(){throw new Error("No such element.")},a.prototype.getOrElse=function(a){return a()},a.prototype.orElse=function(a){return a()},a.prototype.match=function(a){a.None&&a.None()},a.prototype.map=function(){return b(this)},a.prototype.flatMap=function(){return b(this)},a.prototype.filter=function(){return this},a.prototype.reject=function(){return this},a.prototype.foreach=function(){},a}();a.None=d}(monapt||(monapt={}));var monapt;!function(a){var b=function(a){return a},c=function(){function b(a){this.value=a,this.isSuccess=!0,this.isFailure=!1}return b.prototype.get=function(){return this.value},b.prototype.getOrElse=function(){return this.get()},b.prototype.orElse=function(){return this},b.prototype.match=function(a){a.Success&&a.Success(this.get())},b.prototype.map=function(b){var c=this;return a.Try(function(){return b(c.value)})},b.prototype.flatMap=function(a){try{return a(this.value)}catch(b){return new d(b)}},b.prototype.filter=function(a){try{return a(this.value)?this:new d(new Error("Predicate does not hold for "+this.value))}catch(b){return new d(b)}},b.prototype.reject=function(a){return this.filter(function(b){return!a(b)})},b.prototype.foreach=function(a){a(this.value)},b.prototype.recover=function(){return this},b.prototype.recoverWith=function(){return this},b}();a.Success=c;var d=function(){function a(a){this.error=a,this.isSuccess=!1,this.isFailure=!0}return a.prototype.get=function(){throw this.error},a.prototype.getOrElse=function(a){return a()},a.prototype.orElse=function(a){return a()},a.prototype.match=function(a){a.Failure&&a.Failure(this.error)},a.prototype.map=function(){return b(this)},a.prototype.flatMap=function(){return b(this)},a.prototype.filter=function(){return this},a.prototype.reject=function(){return this},a.prototype.foreach=function(){},a.prototype.recover=function(b){try{return new c(b(this.error))}catch(d){return new a(d)}},a.prototype.recoverWith=function(b){try{return b(this.error)}catch(c){return new a(this.error)}},a}();a.Failure=d,a.Try=function(a){try{return new c(a())}catch(b){return new d(b)}}}(monapt||(monapt={}));var monapt;!function(a){var b=function(){function a(){this.fired=!1,this.callbacks=new Array}return a.prototype.fire=function(a){if(this.producer=a,this.fired)throw new Error("Dose fired twice, Can call only once.");this.fireAll()},a.prototype.fireAll=function(){var a=this;this.fired=!0,this.callbacks.forEach(function(b){return a.producer(b)})},a.prototype.add=function(a){this.fired?this.producer(a):this.callbacks.push(a)},a}();a.Cracker=b}(monapt||(monapt={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},monapt;!function(a){function b(a){var b=function(b){b instanceof Error?a.failure(b):a.success(b)};return b.success=function(b){return a.success(b)},b.failure=function(b){return a.failure(b)},b}var c=function(){function c(c){this.cracker=new a.Cracker,c(b(this))}return c.succeed=function(a){return new c(function(b){return b.success(a)})},c.failed=function(a){return new c(function(b){return b.failure(a)})},c.prototype.success=function(b){this.cracker.fire(function(c){return c(new a.Success(b))})},c.prototype.failure=function(b){this.cracker.fire(function(c){return c(new a.Failure(b))})},c.prototype.onComplete=function(a){this.cracker.add(a)},c.prototype.onSuccess=function(a){this.onComplete(function(b){b.match({Success:function(b){return a(b)}})})},c.prototype.onFailure=function(a){this.onComplete(function(b){b.match({Failure:function(b){return a(b)}})})},c.prototype.map=function(a){var c=new d;return this.onComplete(function(d){d.match({Failure:function(a){return c.failure(a)},Success:function(d){return a(d,b(c))}})}),c.future()},c.prototype.flatMap=function(a){var b=new d;return this.onComplete(function(c){c.match({Failure:function(a){return b.failure(a)},Success:function(c){a(c).onComplete(function(a){a.match({Success:function(a){return b.success(a)},Failure:function(a){return b.failure(a)}})})}})}),b.future()},c.prototype.filter=function(a){var b=new d;return this.onComplete(function(c){c.match({Failure:function(a){b.failure(a)},Success:function(c){try{a(c)?b.success(c):b.failure(new Error("No such element."))}catch(d){b.failure(d)}}})}),b.future()},c.prototype.reject=function(a){return this.filter(function(b){return!a(b)})},c.prototype.recover=function(a){var c=new d;return this.onComplete(function(d){d.match({Failure:function(d){try{a(d,b(c))}catch(e){c.failure(e)}},Success:function(a){return c.success(a)}})}),c.future()},c.prototype.recoverWith=function(a){var b=new d;return this.onComplete(function(c){return c.match({Failure:function(c){a(c).onComplete(function(a){return a.match({Success:function(a){return b.success(a)},Failure:function(a){return b.failure(a)}})})},Success:function(a){return b.success(a)}})}),b.future()},c}();a.Future=c;var d=function(a){function b(){a.call(this,function(){}),this.isComplete=!1}return __extends(b,a),b.prototype.success=function(b){this.isComplete=!0,a.prototype.success.call(this,b)},b.prototype.failure=function(b){this.isComplete=!0,a.prototype.failure.call(this,b)},b.prototype.future=function(){return this},b}(c);a.Promise=d,a.future=function(a){var c=new d;try{a(b(c))}catch(e){c.failure(e)}return c.future()}}(monapt||(monapt={}));var monapt;!function(a){var b;!function(b){var c=function(){function b(){this.table={}}return b.prototype.register=function(a,b){this.table[a]=b},b.prototype.index=function(b){return this.table[b]?new a.Some(this.table[b]):new a.None},b}();b.StringSelector=c;var d=function(){function b(){this.table={}}return b.prototype.register=function(a,b){this.table[a.hash()]=b},b.prototype.index=function(b){var c=b.hash();return this.table[c]?new a.Some(this.table[c]):new a.None},b}();b.HashableSelector=d;var e=function(){function b(){}return b.prototype.register=function(){},b.prototype.index=function(){return new a.None},b}();b.ObjectSelector=e}(b||(b={}));var c=function(){function c(a,b){for(var c=[],d=0;d<arguments.length-2;d++)c[d]=arguments[d+2];if(this.real=[],b){if(0!=c.length&&c.length%2!=0)throw new Error(c[c.length-1]+" has not value.");this.ensureSelector(a),this.add(a,b);for(var e=0,f=c.length;f>e;e+=2)this.add(c[e],c[e+1])}else if(a){var g=a;for(var h in g)this.ensureSelector(h),this.add(h,g[h])}this.ensureSelector()}return c.prototype.ensureSelector=function(a){"undefined"==typeof a&&(a=null),this.selector||(this.selector=a?"string"==typeof a?new b.StringSelector:a.hash?new b.HashableSelector:new b.ObjectSelector:new b.ObjectSelector)},c.prototype.add=function(b,c){this.real.push(a.Tuple2(b,c)),this.selector.register(b,this.real.length-1)},c.prototype.foreach=function(a){this.real.forEach(function(b){return a(b._1,b._2)})},c.prototype.map=function(a){var b=new c;return this.foreach(function(c,d){var e=a(c,d);b.add(e._1,e._2)}),b},c.prototype.flatMap=function(a){var b=new c;return this.foreach(function(c,d){var e=a(c,d);e.foreach(function(a,c){return b.add(a,c)})}),b},c.prototype.mapValues=function(a){var b=new c;return this.foreach(function(c,d){b.add(c,a(d))}),b},c.prototype.filter=function(a){var b=new c;return this.foreach(function(c,d){a(c,d)&&b.add(c,d)}),b},c.prototype.reject=function(a){return this.filter(function(b,c){return!a(b,c)})},c.prototype.find=function(a){return this.filter(a).head()},c.prototype.get=function(b){var c=this;return this.selector.index(b).map(function(a){return c.real[a]._2}).orElse(function(){return c.find(function(a){return a==b}).map(function(a){return a._2}).orElse(function(){return new a.None})})},c.prototype.getOrElse=function(a,b){return this.get(a).getOrElse(b)},c.prototype.head=function(){return this.real.length>0?new a.Some(this.real[0]):new a.None},c}();a.Map=c}(monapt||(monapt={}));