/* Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.*/ (function(a){var b={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},c=b[typeof window]&&window||this,d=b[typeof exports]&&exports&&!exports.nodeType&&exports,e=b[typeof module]&&module&&!module.nodeType&&module,f=(e&&e.exports===d&&d,b[typeof global]&&global);!f||f.global!==f&&f.window!==f||(c=f),"function"==typeof define&&define.amd?define(["rx"],function(b,d){return a(c,d,b)}):"object"==typeof module&&module&&module.exports===d?module.exports=a(c,module.exports,require("./rx")):c.Rx=a(c,{},c.Rx)}).call(this,function(a,b,c,d){function e(a,b){return new q(function(){return new p(function(){return a()?{done:!1,value:b}:{done:!0,value:d}})})}var f=c.Observable,g=f.prototype,h=c.AnonymousObservable,i=f.concat,j=f.defer,k=f.empty,l=c.Disposable.empty,m=c.CompositeDisposable,n=c.SerialDisposable,o=c.SingleAssignmentDisposable,p=c.internals.Enumerator,q=c.internals.Enumerable,r=q.of,s=c.Scheduler.immediate,t=c.Scheduler.currentThread,u=(Array.prototype.slice,c.AsyncSubject),v=c.Observer,w=c.internals.inherits,x=c.internals.bindCallback,y=c.internals.addProperties,z=c.helpers,A=z.noop,B=z.isPromise,C=z.isScheduler,D=f.fromPromise,E="function"==typeof Symbol&&Symbol.iterator||"_es6shim_iterator_";a.Set&&"function"==typeof(new a.Set)["@@iterator"]&&(E="@@iterator");c.doneEnumerator={done:!0,value:d},c.helpers.isIterable=function(a){return a[E]!==d},c.helpers.isArrayLike=function(a){return a&&a.length!==d};c.helpers.iterator=E,g.letBind=g.let=function(a){return a(this)},f["if"]=f.ifThen=function(a,b,c){return j(function(){return c||(c=k()),B(b)&&(b=D(b)),B(c)&&(c=D(c)),"function"==typeof c.now&&(c=k(c)),a()?b:c})},f["for"]=f.forIn=function(a,b,c){return r(a,b,c).concat()};var F=f["while"]=f.whileDo=function(a,b){return B(b)&&(b=D(b)),e(a,b).concat()};g.doWhile=function(a){return i([this,F(a,this)])},f["case"]=f.switchCase=function(a,b,c){return j(function(){B(c)&&(c=D(c)),c||(c=k()),"function"==typeof c.now&&(c=k(c));var d=b[a()];return B(d)&&(d=D(d)),d||c})},g.expand=function(a,b){C(b)||(b=s);var c=this;return new h(function(d){var e=[],f=new n,g=new m(f),h=0,i=!1,j=function(){var c=!1;e.length>0&&(c=!i,i=!0),c&&f.setDisposable(b.scheduleRecursive(function(b){var c;if(!(e.length>0))return void(i=!1);c=e.shift();var f=new o;g.add(f),f.setDisposable(c.subscribe(function(b){d.onNext(b);var c=null;try{c=a(b)}catch(f){d.onError(f)}e.push(c),h++,j()},d.onError.bind(d),function(){g.remove(f),h--,0===h&&d.onCompleted()})),b()}))};return e.push(c),h++,j(),g},this)},f.forkJoin=function(){var a=[];if(Array.isArray(arguments[0]))a=arguments[0];else for(var b=0,c=arguments.length;c>b;b++)a.push(arguments[b]);return new h(function(b){var c=a.length;if(0===c)return b.onCompleted(),l;for(var d=new m,e=!1,f=new Array(c),g=new Array(c),h=new Array(c),i=0;c>i;i++)!function(i){var j=a[i];B(j)&&(j=D(j)),d.add(j.subscribe(function(a){e||(f[i]=!0,h[i]=a)},function(a){e=!0,b.onError(a),d.dispose()},function(){if(!e){if(!f[i])return void b.onCompleted();g[i]=!0;for(var a=0;c>a;a++)if(!g[a])return;e=!0,b.onNext(h),b.onCompleted()}}))}(i);return d})},g.forkJoin=function(a,b){var c=this;return new h(function(d){var e,f,g=!1,h=!1,i=!1,j=!1,k=new o,l=new o;return B(a)&&(a=D(a)),k.setDisposable(c.subscribe(function(a){i=!0,e=a},function(a){l.dispose(),d.onError(a)},function(){if(g=!0,h)if(i)if(j){var a;try{a=b(e,f)}catch(c){return void d.onError(c)}d.onNext(a),d.onCompleted()}else d.onCompleted();else d.onCompleted()})),l.setDisposable(a.subscribe(function(a){j=!0,f=a},function(a){k.dispose(),d.onError(a)},function(){if(h=!0,g)if(i)if(j){var a;try{a=b(e,f)}catch(c){return void d.onError(c)}d.onNext(a),d.onCompleted()}else d.onCompleted();else d.onCompleted()})),new m(k,l)},c)},g.manySelect=function(a,b){C(b)||(b=s);var c=this;return j(function(){var d;return c.map(function(a){var b=new G(a);return d&&d.onNext(a),d=b,b}).tap(A,function(a){d&&d.onError(a)},function(){d&&d.onCompleted()}).observeOn(b).map(a)},c)};var G=function(a){function b(a){var b=this,c=new m;return c.add(t.schedule(function(){a.onNext(b.head),c.add(b.tail.mergeAll().subscribe(a))})),c}function c(c){a.call(this,b),this.head=c,this.tail=new u}return w(c,a),y(c.prototype,v,{onCompleted:function(){this.onNext(f.empty())},onError:function(a){this.onNext(f.throwError(a))},onNext:function(a){this.tail.onNext(a),this.tail.onCompleted()}}),c}(f);return g.exclusive=function(){var a=this;return new h(function(b){var c=!1,d=!1,e=new o,f=new m;return f.add(e),e.setDisposable(a.subscribe(function(a){if(!c){c=!0,B(a)&&(a=D(a));var e=new o;f.add(e),e.setDisposable(a.subscribe(b.onNext.bind(b),b.onError.bind(b),function(){f.remove(e),c=!1,d&&1===f.length&&b.onCompleted()}))}},b.onError.bind(b),function(){d=!0,c||1!==f.length||b.onCompleted()})),f},this)},g.exclusiveMap=function(a,b){var c=this,d=x(a,b,3);return new h(function(a){var b=0,e=!1,f=!0,g=new o,h=new m;return h.add(g),g.setDisposable(c.subscribe(function(c){e||(e=!0,innerSubscription=new o,h.add(innerSubscription),B(c)&&(c=D(c)),innerSubscription.setDisposable(c.subscribe(function(e){var f;try{f=d(e,b++,c)}catch(g){return void a.onError(g)}a.onNext(f)},function(b){a.onError(b)},function(){h.remove(innerSubscription),e=!1,f&&1===h.length&&a.onCompleted()})))},function(b){a.onError(b)},function(){f=!0,1!==h.length||e||a.onCompleted()})),h},this)},c}); //# sourceMappingURL=rx.experimental.map