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