forked from Reactive-Extensions/RxJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrx.aggregates.min.js
More file actions
1 lines (1 loc) · 4.83 KB
/
Copy pathrx.aggregates.min.js
File metadata and controls
1 lines (1 loc) · 4.83 KB
1
(function(t,e){var n="object"==typeof exports&&exports&&("object"==typeof t&&t&&t==t.global&&(window=t),exports);"function"==typeof define&&define.amd?define(["rx","exports"],function(n,r){return t.Rx=e(t,r,n),t.Rx}):"object"==typeof module&&module&&module.exports==n?module.exports=e(t,module.exports,require("./rx")):t.Rx=e(t,{},t.Rx)})(this,function(t,e,n){function r(t,e){return t===e}function i(t){return t}function o(t,e){return t>e?1:t===e?0:-1}function s(t,e,n){return new v(function(r){var i=!1,o=null,s=[];return t.subscribe(function(t){var u,c;try{c=e(t)}catch(a){return r.onError(a),undefined}if(u=0,i)try{u=n(c,o)}catch(h){return r.onError(h),undefined}else i=!0,o=c;u>0&&(o=c,s=[]),u>=0&&s.push(t)},r.onError.bind(r),function(){r.onNext(s),r.onCompleted()})})}function u(t){if(0==t.length)throw Error(y);return t[0]}function c(t,e,n){return new v(function(r){var i=0,o=e.length;return t.subscribe(function(t){var s=!1;try{o>i&&(s=n(t,e[i++]))}catch(u){return r.onError(u),undefined}s||(r.onNext(!1),r.onCompleted())},r.onError.bind(r),function(){r.onNext(i===o),r.onCompleted()})})}function a(t,e,n,r){if(0>e)throw Error(m);return new v(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(m))})})}function h(t,e,n){return new v(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(y))})})}function l(t,e,n){return new v(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(y))})})}function f(t,e,n){return new v(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(y))})})}var p=n.Observable,d=p.prototype,b=n.CompositeDisposable,v=n.Internals.AnonymousObservable,m="Argument out of range",y="Sequence contains no elements.";return d.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()},d.reduce=function(){var t,e,n=arguments[0];return 2===arguments.length&&(e=!0,t=arguments[1]),e?this.scan(t,n).startWith(t).finalValue():this.scan(n).finalValue()},d.any=d.some=function(t){var e=this;return t?e.where(t).any():new v(function(t){return e.subscribe(function(){t.onNext(!0),t.onCompleted()},t.onError.bind(t),function(){t.onNext(!1),t.onCompleted()})})},d.isEmpty=function(){return this.any().select(function(t){return!t})},d.all=d.every=function(t){return this.where(function(e){return!t(e)}).any().select(function(t){return!t})},d.contains=function(t,e){return e||(e=r),this.where(function(n){return e(n,t)}).any()},d.count=function(t){return t?this.where(t).count():this.aggregate(0,function(t){return t+1})},d.sum=function(t){return t?this.select(t).sum():this.aggregate(0,function(t,e){return t+e})},d.minBy=function(t,e){return e||(e=o),s(this,t,function(t,n){return-1*e(t,n)})},d.min=function(t){return this.minBy(i,t).select(function(t){return u(t)})},d.maxBy=function(t,e){return e||(e=o),s(this,t,e)},d.max=function(t){return this.maxBy(i,t).select(function(t){return u(t)})},d.average=function(t){return t?this.select(t).average():this.scan({sum:0,count:0},function(t,e){return{sum:t.sum+e,count:t.count+1}}).finalValue().select(function(t){return t.sum/t.count})},d.sequenceEqual=function(t,e){var n=this;return e||(e=r),Array.isArray(t)?c(n,t,e):new v(function(r){var i=!1,o=!1,s=[],u=[],c=n.subscribe(function(t){var n,i;if(u.length>0){i=u.shift();try{n=e(i,t)}catch(c){return r.onError(c),undefined}n||(r.onNext(!1),r.onCompleted())}else o?(r.onNext(!1),r.onCompleted()):s.push(t)},r.onError.bind(r),function(){i=!0,0===s.length&&(u.length>0?(r.onNext(!1),r.onCompleted()):o&&(r.onNext(!0),r.onCompleted()))}),a=t.subscribe(function(t){var n,o;if(s.length>0){o=s.shift();try{n=e(o,t)}catch(c){return r.onError(c),undefined}n||(r.onNext(!1),r.onCompleted())}else i?(r.onNext(!1),r.onCompleted()):u.push(t)},r.onError.bind(r),function(){o=!0,0===u.length&&(s.length>0?(r.onNext(!1),r.onCompleted()):i&&(r.onNext(!0),r.onCompleted()))});return new b(c,a)})},d.elementAt=function(t){return a(this,t,!1)},d.elementAtOrDefault=function(t,e){return a(this,t,!0,e)},d.single=function(t){return t?this.where(t).single():h(this,!1)},d.singleOrDefault=function(t,e){return t?this.where(t).singleOrDefault(null,e):h(this,!0,e)},d.first=function(t){return t?this.where(t).first():l(this,!1)},d.firstOrDefault=function(t,e){return t?this.where(t).firstOrDefault(null,e):l(this,!0,e)},d.last=function(t){return t?this.where(t).last():f(this,!1)},d.lastOrDefault=function(t,e){return t?this.where(t).lastOrDefault(null,e):f(this,!0,e)},n});