forked from Reactive-Extensions/RxJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rx.aggregates.min.js
1 lines (1 loc) · 5.44 KB
/
rx.aggregates.min.js
1
(function(t){var n={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},e=n[typeof window]&&window||this,r=n[typeof exports]&&exports&&!exports.nodeType&&exports,i=n[typeof module]&&module&&!module.nodeType&&module,o=(i&&i.exports===r&&r,n[typeof global]&&global);!o||o.global!==o&&o.window!==o||(e=o),"function"==typeof define&&define.amd?define(["rx","exports"],function(n,r){return e.Rx=t(e,r,n),e.Rx}):"object"==typeof module&&module&&module.exports===r?module.exports=t(e,module.exports,require("./rx")):e.Rx=t(e,{},e.Rx)}).call(this,function(t,n,e,r){function i(t,n){return w(t,n)}function o(t){return t}function s(t,n){return t>n?1:n>t?-1:0}function u(t,n,e){return new y(function(i){var o=!1,s=null,u=[];return t.subscribe(function(t){var c,a;try{a=n(t)}catch(h){return i.onError(h),r}if(c=0,o)try{c=e(a,s)}catch(f){return i.onError(f),r}else o=!0,s=a;c>0&&(s=a,u=[]),c>=0&&u.push(t)},i.onError.bind(i),function(){i.onNext(u),i.onCompleted()})})}function c(t){if(0===t.length)throw Error(E);return t[0]}function a(t,n,e){return new y(function(i){var o=0,s=n.length;return t.subscribe(function(t){var u=!1;try{s>o&&(u=e(t,n[o++]))}catch(c){return i.onError(c),r}u||(i.onNext(!1),i.onCompleted())},i.onError.bind(i),function(){i.onNext(o===s),i.onCompleted()})})}function h(t,n,e,r){if(0>n)throw Error(g);return new y(function(i){var o=n;return t.subscribe(function(t){0===o&&(i.onNext(t),i.onCompleted()),o--},i.onError.bind(i),function(){e?(i.onNext(r),i.onCompleted()):i.onError(Error(g))})})}function f(t,n,e){return new y(function(r){var i=e,o=!1;return t.subscribe(function(t){o?r.onError(Error("Sequence contains more than one element")):(i=t,o=!0)},r.onError.bind(r),function(){o||n?(r.onNext(i),r.onCompleted()):r.onError(Error(E))})})}function l(t,n,e){return new y(function(r){return t.subscribe(function(t){r.onNext(t),r.onCompleted()},r.onError.bind(r),function(){n?(r.onNext(e),r.onCompleted()):r.onError(Error(E))})})}function p(t,n,e){return new y(function(r){var i=e,o=!1;return t.subscribe(function(t){i=t,o=!0},r.onError.bind(r),function(){o||n?(r.onNext(i),r.onCompleted()):r.onError(Error(E))})})}function d(t,n,e,i){return new y(function(o){var s=0;return t.subscribe(function(u){var c;try{c=n.call(e,u,s,t)}catch(a){return o.onError(a),r}c?(o.onNext(i?s:u),o.onCompleted()):s++},o.onError.bind(o),function(){o.onNext(i?-1:r),o.onCompleted()})})}var b=e.Observable,v=b.prototype,m=e.CompositeDisposable,y=e.Internals.AnonymousObservable,w=e.Internals.isEqual,g="Argument out of range",E="Sequence contains no elements.";return v.aggregate=function(){var t,n,e;return 2===arguments.length?(t=arguments[0],n=!0,e=arguments[1]):e=arguments[0],n?this.scan(t,e).startWith(t).finalValue():this.scan(e).finalValue()},v.reduce=function(t){var n,e;return 2===arguments.length&&(e=!0,n=arguments[1]),e?this.scan(n,t).startWith(n).finalValue():this.scan(t).finalValue()},v.some=v.any=function(t,n){var e=this;return t?e.where(t,n).any():new y(function(t){return e.subscribe(function(){t.onNext(!0),t.onCompleted()},t.onError.bind(t),function(){t.onNext(!1),t.onCompleted()})})},v.isEmpty=function(){return this.any().select(function(t){return!t})},v.every=v.all=function(t,n){return this.where(function(n){return!t(n)},n).any().select(function(t){return!t})},v.contains=function(t,n){return n||(n=i),this.where(function(e){return n(e,t)}).any()},v.count=function(t,n){return t?this.where(t,n).count():this.aggregate(0,function(t){return t+1})},v.sum=function(t,n){return t?this.select(t,n).sum():this.aggregate(0,function(t,n){return t+n})},v.minBy=function(t,n){return n||(n=s),u(this,t,function(t,e){return-1*n(t,e)})},v.min=function(t){return this.minBy(o,t).select(function(t){return c(t)})},v.maxBy=function(t,n){return n||(n=s),u(this,t,n)},v.max=function(t){return this.maxBy(o,t).select(function(t){return c(t)})},v.average=function(t,n){return t?this.select(t,n).average():this.scan({sum:0,count:0},function(t,n){return{sum:t.sum+n,count:t.count+1}}).finalValue().select(function(t){if(0===t.count)throw Error("The input sequence was empty");return t.sum/t.count})},v.sequenceEqual=function(t,n){var e=this;return n||(n=i),Array.isArray(t)?a(e,t,n):new y(function(i){var o=!1,s=!1,u=[],c=[],a=e.subscribe(function(t){var e,o;if(c.length>0){o=c.shift();try{e=n(o,t)}catch(a){return i.onError(a),r}e||(i.onNext(!1),i.onCompleted())}else s?(i.onNext(!1),i.onCompleted()):u.push(t)},i.onError.bind(i),function(){o=!0,0===u.length&&(c.length>0?(i.onNext(!1),i.onCompleted()):s&&(i.onNext(!0),i.onCompleted()))}),h=t.subscribe(function(t){var e,s;if(u.length>0){s=u.shift();try{e=n(s,t)}catch(a){return i.onError(a),r}e||(i.onNext(!1),i.onCompleted())}else o?(i.onNext(!1),i.onCompleted()):c.push(t)},i.onError.bind(i),function(){s=!0,0===c.length&&(u.length>0?(i.onNext(!1),i.onCompleted()):o&&(i.onNext(!0),i.onCompleted()))});return new m(a,h)})},v.elementAt=function(t){return h(this,t,!1)},v.elementAtOrDefault=function(t,n){return h(this,t,!0,n)},v.single=function(t,n){return t?this.where(t,n).single():f(this,!1)},v.singleOrDefault=function(t,n,e){return t?this.where(t,e).singleOrDefault(null,n):f(this,!0,n)},v.first=function(t,n){return t?this.where(t,n).first():l(this,!1)},v.firstOrDefault=function(t,n){return t?this.where(t).firstOrDefault(null,n):l(this,!0,n)},v.last=function(t,n){return t?this.where(t,n).last():p(this,!1)},v.lastOrDefault=function(t,n,e){return t?this.where(t,e).lastOrDefault(null,n):p(this,!0,n)},v.find=function(t,n){return d(this,t,n,!1)},v.findIndex=function(t,n){return d(this,t,n,!0)},e});