(function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,_,ab,bb,cb,db,eb,fb=[].slice,gb={}.hasOwnProperty,hb=function(a,b){function c(){this.constructor=a}for(var d in b)gb.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},ib=function(a,b){return function(){return a.apply(b,arguments)}};a={toString:function(){return"Bacon"}},a.version="",a.fromBinder=function(b,c){return null==c&&(c=db.id),new k(z(a,"fromBinder",b,c),function(d){var e;return e=b(function(){var b,f,g,h,i,k;for(b=1<=arguments.length?fb.call(arguments,0):[],h=c.apply(null,b),G(h)&&db.last(h)instanceof j||(h=[h]),g=a.more,i=0,k=h.length;k>i;i++)if(f=h[i],g=d(f=Y(f)),g===a.noMore||f.isEnd())return null!=e?e():a.scheduler.setTimeout(function(){return e()},0),g;return g})})},a.$={asEventStream:function(b,c,d){var e;return I(c)&&(e=[c,null],d=e[0],c=e[1]),bb(this.selector||this,"asEventStream",b,a.fromBinder(function(a){return function(d){return a.on(b,c,d),function(){return a.off(b,c,d)}}}(this),d))}},null!=(eb="undefined"!=typeof jQuery&&null!==jQuery?jQuery:"undefined"!=typeof Zepto&&null!==Zepto?Zepto:null)&&(eb.fn.asEventStream=a.$.asEventStream),a.fromEventTarget=function(b,c,d){var e,f,g,h,i,j;return e=null!=(g=b.addEventListener)?g:null!=(h=b.addListener)?h:b.bind,f=null!=(i=b.removeEventListener)?i:null!=(j=b.removeListener)?j:b.unbind,bb(a,"fromEventTarget",b,c,a.fromBinder(function(a){return e.call(b,c,a),function(){return f.call(b,c,a)}},d))},a.fromPromise=function(b,c){return bb(a,"fromPromise",b,a.fromBinder(function(a){return b.then(a,function(b){return a(new i(b))}),function(){return c&&"function"==typeof b.abort?b.abort():void 0}},function(a){return[a,A()]}))},a.noMore=[""],a.more=[""],a.later=function(b,c){return bb(a,"later",b,c,a.sequentially(b,[c]))},a.sequentially=function(b,c){var d;return d=0,bb(a,"sequentially",b,c,a.fromPoll(b,function(){var a;return a=c[d++],dc;c++)b=W[c],e.push(b(a));return e}finally{delete V.running}},cb=function(a){return function(){var b,c,d,e;return d=arguments[0],b=2<=arguments.length?fb.call(arguments,1):[],"object"==typeof d&&b.length&&(c=d,e=b[0],d=function(){return c[e].apply(c,arguments)},b=b.slice(1)),a.apply(null,[d].concat(fb.call(b)))}},L=function(b,c){return cb(function(){var d,e,f;return e=arguments[0],d=2<=arguments.length?fb.call(arguments,1):[],f=T(c,[function(a,b){return e.apply(null,fb.call(a).concat([b]))}]),bb.apply(null,[a,b,e].concat(fb.call(d),[a.combineAsArray(d).flatMap(f)]))})},a.fromCallback=L("fromCallback",function(){var b,c;return c=arguments[0],b=2<=arguments.length?fb.call(arguments,1):[],a.fromBinder(function(a){return M(c,b)(a),S},function(a){return[a,A()]})}),a.fromNodeCallback=L("fromNodeCallback",function(){var b,c;return c=arguments[0],b=2<=arguments.length?fb.call(arguments,1):[],a.fromBinder(function(a){return M(c,b)(a),S},function(a,b){return a?[new i(a),A()]:[b,A()]})}),a.fromPoll=function(b,c){return bb(a,"fromPoll",b,c,a.fromBinder(function(c){var d;return d=a.scheduler.setInterval(c,b),function(){return a.scheduler.clearInterval(d)}},c))},a.interval=function(b,c){return null==c&&(c={}),bb(a,"interval",b,c,a.fromPoll(b,function(){return R(c)}))},a.constant=function(b){return new p(z(a,"constant",b),function(a){return a(F(b)),a(A()),S})},a.never=function(){return bb(a,"never",a.fromArray([]))},a.once=function(b){return bb(a,"once",b,a.fromArray([b]))},a.fromArray=function(b){return b=v(b),new k(z(a,"fromArray",b),function(c){var d,e,f;for(e=!1,d=a.more;d!==a.noMore&&!e;)db.empty(b)?(c(A()),d=a.noMore):(f=db.popHead(b),d=c(Y(f)));return function(){return e=!0}})},a.mergeAll=function(){var b;return b=1<=arguments.length?fb.call(arguments,0):[],G(b[0])&&(b=b[0]),bb.apply(null,[a,"mergeAll"].concat(fb.call(b),[db.fold(b,a.never(),function(a,b){return a.merge(b)})]))},a.zipAsArray=function(){var b;return b=1<=arguments.length?fb.call(arguments,0):[],G(b[0])&&(b=b[0]),bb.apply(null,[a,"zipAsArray"].concat(fb.call(b),[a.zipWith(b,function(){var a;return a=1<=arguments.length?fb.call(arguments,0):[]})]))},a.zipWith=function(){var b,c,d;return b=arguments[0],c=2<=arguments.length?fb.call(arguments,1):[],I(b)||(d=[b,c[0]],c=d[0],b=d[1]),c=db.map(function(a){return a.toEventStream()},c),bb.apply(null,[a,"zipWith",b].concat(fb.call(c),[a.when(c,b)]))},a.groupSimultaneous=function(){var c,d,e;return e=1<=arguments.length?fb.call(arguments,0):[],1===e.length&&G(e[0])&&(e=e[0]),d=function(){var a,d,f;for(f=[],a=0,d=e.length;d>a;a++)c=e[a],f.push(new b(c));return f}(),bb.apply(null,[a,"groupSimultaneous"].concat(fb.call(e),[a.when(d,function(){var a;return a=1<=arguments.length?fb.call(arguments,0):[]})]))},a.combineAsArray=function(){var b,c,d,e,f,g,h;for(f=1<=arguments.length?fb.call(arguments,0):[],1===f.length&&G(f[0])&&(f=f[0]),b=g=0,h=f.length;h>g;b=++g)e=f[b],J(e)||(f[b]=a.constant(e));return f.length?(d=function(){var a,b,d;for(d=[],a=0,b=f.length;b>a;a++)c=f[a],d.push(new s(c,!0,c.subscribeInternal));return d}(),bb.apply(null,[a,"combineAsArray"].concat(fb.call(f),[a.when(d,function(){var a;return a=1<=arguments.length?fb.call(arguments,0):[]}).toProperty()]))):a.constant([])},a.onValues=function(){var b,c,d;return c=2<=arguments.length?fb.call(arguments,0,d=arguments.length-1):(d=0,[]),b=arguments[d++],a.combineAsArray(c).onValues(b)},a.combineWith=function(){var b,c;return b=arguments[0],c=2<=arguments.length?fb.call(arguments,1):[],bb.apply(null,[a,"combineWith",b].concat(fb.call(c),[a.combineAsArray(c).map(function(a){return b.apply(null,a)})]))},a.combineTemplate=function(b){var c,d,e,f,g,h,i,j,k,l;return i=[],l=[],h=function(a){return a[a.length-1]},k=function(a,b,c){return h(a)[b]=c},c=function(a,b){return function(c,d){return k(c,a,d[b])}},g=function(a,b){return function(c){return k(c,a,b)}},j=function(a){return G(a)?[]:{}},e=function(a,b){var d,e;return J(b)?(l.push(b),i.push(c(a,l.length-1))):b!==Object(b)||"function"==typeof b||b instanceof RegExp||b instanceof Date?i.push(g(a,b)):(e=function(a){return function(c){var d;return d=j(b),k(c,a,d),c.push(d)}},d=function(a){return a.pop()},i.push(e(a)),f(b),i.push(d))},f=function(a){return db.each(a,e)},f(b),d=function(a){var c,d,e,f,g;for(e=j(b),c=[e],f=0,g=i.length;g>f;f++)(d=i[f])(c,a);return e},bb(a,"combineTemplate",b,a.combineAsArray(l).map(d))},B=0,j=function(){function a(){this.id=++B}return a.prototype.isEvent=function(){return!0},a.prototype.isEnd=function(){return!1},a.prototype.isInitial=function(){return!1},a.prototype.isNext=function(){return!1},a.prototype.isError=function(){return!1},a.prototype.hasValue=function(){return!1},a.prototype.filter=function(){return!0},a.prototype.inspect=function(){return this.toString()},a.prototype.log=function(){return this.toString()},a}(),m=function(a){function b(a){b.__super__.constructor.call(this),this.value=I(a)?db.cached(a):db.always(a)}return hb(b,a),b.prototype.isNext=function(){return!0},b.prototype.hasValue=function(){return!0},b.prototype.fmap=function(a){var b;return b=this.value,this.apply(function(){return a(b())})},b.prototype.apply=function(a){return new b(a)},b.prototype.filter=function(a){return a(this.value())},b.prototype.toString=function(){return db.toString(this.value())},b.prototype.log=function(){return this.value()},b}(j),l=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return hb(b,a),b.prototype.isInitial=function(){return!0},b.prototype.isNext=function(){return!1},b.prototype.apply=function(a){return new b(a)},b.prototype.toNext=function(){return new m(this.value)},b}(m),h=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return hb(b,a),b.prototype.isEnd=function(){return!0},b.prototype.fmap=function(){return this},b.prototype.apply=function(){return this},b.prototype.toString=function(){return""},b}(j),i=function(a){function b(a){this.error=a}return hb(b,a),b.prototype.isError=function(){return!0},b.prototype.fmap=function(){return this},b.prototype.apply=function(){return this},b.prototype.toString=function(){return" "+db.toString(this.error)},b}(j),E=0,o=function(){function b(a){this.id=++E,bb(a,this)}return b.prototype.onValue=function(){var a;return a=N(arguments),this.subscribe(function(b){return b.hasValue()?a(b.value()):void 0})},b.prototype.onValues=function(a){return this.onValue(function(b){return a.apply(null,b)})},b.prototype.onError=function(){var a;return a=N(arguments),this.subscribe(function(b){return b.isError()?a(b.error):void 0})},b.prototype.onEnd=function(){var a;return a=N(arguments),this.subscribe(function(b){return b.isEnd()?a():void 0})},b.prototype.errors=function(){return bb(this,"errors",this.filter(function(){return!1}))},b.prototype.filter=function(){var b,c;return c=arguments[0],b=2<=arguments.length?fb.call(arguments,1):[],y(this,c,b,function(b){return bb(this,"filter",b,this.withHandler(function(c){return c.filter(b)?this.push(c):a.more}))})},b.prototype.takeWhile=function(){var b,c;return c=arguments[0],b=2<=arguments.length?fb.call(arguments,1):[],y(this,c,b,function(b){return bb(this,"takeWhile",b,this.withHandler(function(c){return c.filter(b)?this.push(c):(this.push(A()),a.noMore)}))})},b.prototype.endOnError=function(){var a,b;return b=arguments[0],a=2<=arguments.length?fb.call(arguments,1):[],null==b&&(b=!0),y(this,b,a,function(a){return bb(this,"endOnError",this.withHandler(function(b){return b.isError()&&a(b.error)?(this.push(b),this.push(A())):this.push(b)}))})},b.prototype.take=function(b){return 0>=b?a.never():bb(this,"take",b,this.withHandler(function(c){return c.hasValue()?(b--,b>0?this.push(c):(0===b&&this.push(c),this.push(A()),a.noMore)):this.push(c)}))},b.prototype.map=function(){var a,b;return b=arguments[0],a=2<=arguments.length?fb.call(arguments,1):[],b instanceof p?b.sampledBy(this,D):y(this,b,a,function(a){return bb(this,"map",a,this.withHandler(function(b){return this.push(b.fmap(a))}))})},b.prototype.mapError=function(){var a;return a=N(arguments),bb(this,"mapError",a,this.withHandler(function(b){return this.push(b.isError()?R(a(b.error)):b)}))},b.prototype.mapEnd=function(){var b;return b=N(arguments),bb(this,"mapEnd",b,this.withHandler(function(c){return c.isEnd()?(this.push(R(b(c))),this.push(A()),a.noMore):this.push(c)}))},b.prototype.doAction=function(){var a;return a=N(arguments),bb(this,"doAction",a,this.withHandler(function(b){return b.hasValue()&&a(b.value()),this.push(b)}))},b.prototype.skip=function(b){return bb(this,"skip",b,this.withHandler(function(c){return c.hasValue()&&b>0?(b--,a.more):this.push(c)}))},b.prototype.skipDuplicates=function(a){return null==a&&(a=function(a,b){return a===b}),bb(this,"skipDuplicates",this.withStateMachine(n,function(b,c){return c.hasValue()?c.isInitial()||b===n||!a(b.get(),c.value())?[new r(c.value()),[c]]:[b,[]]:[b,[c]]}))},b.prototype.skipErrors=function(){return bb(this,"skipErrors",this.withHandler(function(b){return b.isError()?a.more:this.push(b)}))},b.prototype.withStateMachine=function(b,c){var d;return d=b,bb(this,"withStateMachine",b,c,this.withHandler(function(b){var e,f,g,h,i,j,k;for(e=c(d,b),f=e[0],h=e[1],d=f,i=a.more,j=0,k=h.length;k>j;j++)if(g=h[j],i=this.push(g),i===a.noMore)return i;return i}))},b.prototype.scan=function(b,c,d){var e,f,g,h;return null==d&&(d={}),f=X(c),c=d.lazyF?f:function(a,b){return f(a(),b())},e=_(b).map(function(a){return db.always(a)}),h=function(b){return function(f){var h,i,j,k;return h=!1,k=S,i=a.more,j=function(){return h?void 0:e.forEach(function(b){return h=!0,i=f(new l(b)),i===a.noMore?(k(),k=S):void 0})},k=b.subscribeInternal(function(b){var g,k;return b.hasValue()?h&&b.isInitial()?a.more:(b.isInitial()||j(),h=!0,k=e.getOrElse(function(){return void 0}),g=db.cached(function(){return c(k,b.value)}),e=new r(g),d.eager&&g(),f(b.apply(g))):(b.isEnd()&&(i=j()),i!==a.noMore?f(b):void 0)}),t.whenDoneWith(g,j),k}}(this),g=new p(z(this,"scan",b,c),h)},b.prototype.fold=function(a,b,c){return bb(this,"fold",a,b,this.scan(a,b,c).sampledBy(this.filter(!1).mapEnd().toProperty()))},b.prototype.zip=function(b,c){return null==c&&(c=Array),bb(this,"zip",b,a.zipWith([this,b],c))},b.prototype.diff=function(a,b){return b=X(b),bb(this,"diff",a,b,this.scan([a],function(a,c){return[c,b(a[0],c)]}).filter(function(a){return 2===a.length}).map(function(a){return a[1]}))},b.prototype.flatMap=function(){return C(this,Q(arguments))},b.prototype.flatMapFirst=function(){return C(this,Q(arguments),!0)},b.prototype.flatMapWithConcurrencyLimit=function(){var a,b;return b=arguments[0],a=2<=arguments.length?fb.call(arguments,1):[],bb.apply(null,[this,"flatMapWithConcurrencyLimit",b].concat(fb.call(a),[C(this,Q(a),!1,b)]))},b.prototype.flatMapLatest=function(){var a,b;return a=Q(arguments),b=this.toEventStream(),bb(this,"flatMapLatest",a,b.flatMap(function(c){return P(a(c)).takeUntil(b)}))},b.prototype.flatMapConcat=function(){return bb.apply(null,[this,"flatMapConcat"].concat(fb.call(arguments),[this.flatMapWithConcurrencyLimit.apply(this,[1].concat(fb.call(arguments)))]))},b.prototype.rateLimit=function(b){return bb(this,"rateLimit",b,this.flatMapConcat(function(c){return a.once(c).concat(a.later(b).filter(!1))}))},b.prototype.not=function(){return bb(this,"not",this.map(function(a){return!a}))},b.prototype.log=function(){var a;return a=1<=arguments.length?fb.call(arguments,0):[],this.subscribe(function(b){return"undefined"!=typeof console&&null!==console&&"function"==typeof console.log?console.log.apply(console,fb.call(a).concat([b.log()])):void 0}),this},b.prototype.slidingWindow=function(a,b){return null==b&&(b=0),bb(this,"slidingWindow",a,b,this.scan([],function(b,c){return b.concat([c]).slice(-a)}).filter(function(a){return a.length>=b}))},b.prototype.combine=function(b,c){var d;return d=X(c),bb(this,"combine",b,c,a.combineAsArray(this,b).map(function(a){return d(a[0],a[1])}))},b.prototype.decode=function(b){return bb(this,"decode",b,this.combine(a.combineTemplate(b),function(a,b){return b[a]}))},b.prototype.awaiting=function(b){return bb(this,"awaiting",b,a.groupSimultaneous(this,b).map(function(a){var b,c;return b=a[0],c=a[1],0===c.length}).toProperty(!1).skipDuplicates())},b.prototype.name=function(a){return this.toString=function(){return a},this},b.prototype.withDescription=function(){return z.apply(null,arguments).apply(this)},b}(),o.prototype.reduce=o.prototype.fold,o.prototype.assign=o.prototype.onValue,C=function(b,c,e,f){return new k(z(b,"flatMap"+(e?"First":""),c),function(g){var h,i,j,k,m;return j=new d,k=[],m=function(b){var d;return d=P(c(b.value())),j.add(function(b,c){return d.subscribeInternal(function(d){var e;return d.isEnd()?(i(),h(c),a.noMore):(d instanceof l&&(d=d.toNext()),e=g(d),e===a.noMore&&b(),e)})})},i=function(){var a;return a=db.popHead(k),a?m(a):void 0},h=function(a){return a(),j.empty()?g(A()):void 0},j.add(function(c,d){return b.subscribeInternal(function(b){return b.isEnd()?h(d):b.isError()?g(b):e&&j.count()>1?a.more:j.unsubscribed?a.noMore:f&&j.count()>f?k.push(b):m(b)})}),j.unsubscribe})},k=function(b){function c(a,b){var d;I(a)&&(b=a,a=[]),c.__super__.constructor.call(this,a),d=new g(b),this.subscribeInternal=d.subscribe,this.subscribe=t.wrappedSubscribe(this),this.hasSubscribers=d.hasSubscribers,V(this)}return hb(c,b),c.prototype.delay=function(b){return bb(this,"delay",b,this.flatMap(function(c){return a.later(b,c)}))},c.prototype.debounce=function(b){return bb(this,"debounce",b,this.flatMapLatest(function(c){return a.later(b,c)}))},c.prototype.debounceImmediate=function(b){return bb(this,"debounceImmediate",b,this.flatMapFirst(function(c){return a.once(c).concat(a.later(b).filter(!1))}))},c.prototype.throttle=function(a){return bb(this,"throttle",a,this.bufferWithTime(a).map(function(a){return a[a.length-1]}))},c.prototype.bufferWithTime=function(a){return bb(this,"bufferWithTime",a,this.bufferWithTimeOrCount(a,Number.MAX_VALUE))},c.prototype.bufferWithCount=function(a){return bb(this,"bufferWithCount",a,this.bufferWithTimeOrCount(void 0,a))},c.prototype.bufferWithTimeOrCount=function(a,b){var c;return c=function(c){return c.values.length===b?c.flush():void 0!==a?c.schedule():void 0},bb(this,"bufferWithTimeOrCount",a,b,this.buffer(a,c,c))},c.prototype.buffer=function(b,c,d){var e,f,g;return null==c&&(c=function(){}),null==d&&(d=function(){}),e={scheduled:!1,end:null,values:[],flush:function(){var b;if(this.scheduled=!1,this.values.length>0){if(b=this.push(R(this.values)),this.values=[],null!=this.end)return this.push(this.end);if(b!==a.noMore)return d(this)}else if(null!=this.end)return this.push(this.end)},schedule:function(){return this.scheduled?void 0:(this.scheduled=!0,b(function(a){return function(){return a.flush()}}(this)))}},g=a.more,I(b)||(f=b,b=function(b){return a.scheduler.setTimeout(b,f)}),bb(this,"buffer",this.withHandler(function(a){return e.push=this.push,a.isError()?g=this.push(a):a.isEnd()?(e.end=a,e.scheduled||e.flush()):(e.values.push(a.value()),c(e)),g}))},c.prototype.merge=function(b){var d;return d=this,new c(z(d,"merge",b),function(c){var e,f;return e=0,f=function(b){return function(d){return b.subscribeInternal(function(b){var f;return b.isEnd()?(e++,2===e?c(A()):a.more):(f=c(b),f===a.noMore&&d(),f)})}},w(f(d),f(b))})},c.prototype.toProperty=function(a){return 0===arguments.length&&(a=n),bb(this,"toProperty",a,this.scan(a,K,{lazyF:!0}))},c.prototype.toEventStream=function(){return this},c.prototype.sampledBy=function(a,b){return bb(this,"sampledBy",a,b,this.toProperty().sampledBy(a,b))},c.prototype.concat=function(a){var b;return b=this,new c(z(b,"concat",a),function(c){var d,e;return e=S,d=b.subscribeInternal(function(b){return b.isEnd()?e=a.subscribeInternal(c):c(b)}),function(){return d(),e()}})},c.prototype.takeUntil=function(b){var c;return c={},bb(this,"takeUntil",b,a.groupSimultaneous(this.mapEnd(c),b.skipErrors()).withHandler(function(d){var e,f,g,h,i,j;if(d.hasValue()){if(j=d.value(),e=j[0],b=j[1],b.length)return this.push(A());for(f=a.more,h=0,i=e.length;i>h;h++)g=e[h],f=this.push(g===c?A():R(g));return f}return this.push(d)}))},c.prototype.skipUntil=function(a){var b;return b=a.take(1).map(!0).toProperty(!1),bb(this,"skipUntil",a,this.filter(b))},c.prototype.skipWhile=function(){var b,c,d;return c=arguments[0],b=2<=arguments.length?fb.call(arguments,1):[],d=!1,y(this,c,b,function(b){return bb(this,"skipWhile",b,this.withHandler(function(c){return!d&&c.hasValue()&&b(c.value())?a.more:(c.hasValue()&&(d=!0),this.push(c))}))})},c.prototype.holdWhen=function(b){var c,d,e;return e=b.startWith(!1),d=e.filter(function(a){return!a}),c=e.filter(db.id),bb(this,"holdWhen",b,this.filter(!1).merge(e.flatMapConcat(function(b){return function(e){return e?b.scan([],function(a,b){return a.concat(b)},{eager:!0}).sampledBy(d).take(1).flatMap(a.fromArray):b.takeUntil(c)}}(this))))},c.prototype.startWith=function(b){return bb(this,"startWith",b,a.once(b).concat(this))},c.prototype.withHandler=function(a){var b;return b=new g(this.subscribeInternal,a),new c(z(this,"withHandler",a),b.subscribe)},c}(o),p=function(b){function c(a,b,d){I(a)&&(d=b,b=a,a=[]),c.__super__.constructor.call(this,a),this.subscribeInternal=d===!0?b:new q(this,b,d).subscribe,this.subscribe=t.wrappedSubscribe(this),V(this)}return hb(c,b),c.prototype.sampledBy=function(b,d){var e,f,g,h,i;return null!=d?d=X(d):(e=!0,d=function(a){return a()}),i=new s(this,!1,this.subscribeInternal,e),g=new s(b,!0,b.subscribeInternal,e),h=a.when([i,g],d),f=b instanceof c?h.toProperty():h,bb(this,"sampledBy",b,d,f)},c.prototype.sample=function(b){return bb(this,"sample",b,this.sampledBy(a.interval(b,{})))},c.prototype.changes=function(){return new k(z(this,"changes"),function(a){return function(b){return a.subscribeInternal(function(a){return a.isInitial()?void 0:b(a)})}}(this))},c.prototype.withHandler=function(a){return new c(z(this,"withHandler",a),this.subscribeInternal,a)},c.prototype.toProperty=function(){return this},c.prototype.toEventStream=function(){return new k(z(this,"toEventStream"),function(a){return function(b){return a.subscribeInternal(function(a){return a.isInitial()&&(a=a.toNext()),b(a)})}}(this))},c.prototype.and=function(a){return bb(this,"and",a,this.combine(a,function(a,b){return a&&b}))},c.prototype.or=function(a){return bb(this,"or",a,this.combine(a,function(a,b){return a||b}))},c.prototype.delay=function(a){return this.delayChanges("delay",a,function(b){return b.delay(a)})},c.prototype.debounce=function(a){return this.delayChanges("debounce",a,function(b){return b.debounce(a)})},c.prototype.throttle=function(a){return this.delayChanges("throttle",a,function(b){return b.throttle(a)})},c.prototype.delayChanges=function(){var a,b,c;return a=2<=arguments.length?fb.call(arguments,0,c=arguments.length-1):(c=0,[]),b=arguments[c++],bb.apply(null,[this].concat(fb.call(a),[u(this,b(this.changes()))]))},c.prototype.takeUntil=function(a){var b;return b=this.changes().takeUntil(a),bb(this,"takeUntil",a,u(this,b))},c.prototype.startWith=function(a){return bb(this,"startWith",a,this.scan(a,function(a,b){return b}))},c.prototype.rateLimit=function(){var a;return(a=c.__super__.rateLimit.apply(this,arguments)).rateLimit.apply(a,arguments).toProperty()},c}(o),y=function(a,b,c,d){var e;return b instanceof p?(e=b.sampledBy(a,function(a,b){return[a,b]}),d.apply(e,[function(a){var b,c;return b=a[0],c=a[1],b}]).map(function(a){var b,c;return b=a[0],c=a[1]})):(b=M(b,c),d.apply(a,[b]))},u=function(b,c){var d;return d=new k(z(b,"justInitValue"),function(c){var e,f;return f=null,e=b.subscribeInternal(function(b){return b.hasValue()&&(f=b),a.noMore}),t.whenDoneWith(d,function(){return null!=f&&c(f),c(A())}),e}),d.concat(c).toProperty()},g=function(){function b(b,c){var d,e,f,g,h,i,j,k,l,m;null==b&&(b=function(){return S}),k=[],i=[],h=!1,e=!1,this.hasSubscribers=function(){return k.length>0},f=null,l=S,j=function(a){return k=db.without(a,k)},m=null,d=function(){var a,b,c,d,e;if(null!=m){for(b=m,m=null,e=[],c=0,d=b.length;d>c;c++)a=b[c],e.push(a());return e}},g=function(b){var c,e,g,m,n,o;if(h)return i.push(b),a.more;if(b!==f){b.isError()&&(f=b),g=!1;try{for(h=!0,m=k,n=0,o=m.length;o>n;n++)e=m[n],c=e.sink(b),(c===a.noMore||b.isEnd())&&j(e);g=!0}finally{h=!1,g||(i=[])}for(g=!0;i.length;)b=i.shift(),this.push(b);return d(b),this.hasSubscribers()?a.more:(l(),a.noMore)}},this.push=function(a){return function(b){return t.inTransaction(b,a,g,[b])}}(this),null==c&&(c=function(a){return this.push(a)}),this.handleEvent=function(a){return function(b){return b.isEnd()&&(e=!0),c.apply(a,[b])}}(this),this.subscribe=function(a){return function(c){var d,f;return e?(c(A()),S):(d={sink:c},k.push(d),1===k.length&&(f=b(a.handleEvent),l=function(){return f(),l=S}),function(){return j(d),a.hasSubscribers()?void 0:l()})}}(this)}return b}(),q=function(b){function c(b,d,e){var f,g,h,i;c.__super__.constructor.call(this,d,e),f=n,g=void 0,i=this.push,d=this.subscribe,h=!1,this.push=function(a){return function(b){return b.isEnd()&&(h=!0),b.hasValue()&&(f=new r(b),g=t.currentEventId()),i.apply(a,[b])}}(this),this.subscribe=function(c){return function(e){var i,j,k,l,m;return j=!1,l=a.more,k=function(){return l===a.noMore?S:h?(e(A()),S):d.apply(this,[e])},f.isDefined&&(c.hasSubscribers()||h)?(i=t.currentEventId(),m=g,!h&&m&&i&&i!==m?(t.whenDoneWith(b,function(){return g===m?e(F(f.get().value())):void 0}),k()):(t.inTransaction(void 0,c,function(){return l=e(F(f.get().value()))},[]),k())):k()}}(this)}return hb(c,b),c}(g),c=function(b){function c(){var b,d,e,f,g,h,j,k;e=void 0,h=[],b=!1,d=function(){return function(b){return function(c){return c.isEnd()?(k(b),a.noMore):e(c)}}}(this),j=function(){var a,b,c,d;for(d=[],b=0,c=h.length;c>b;b++)a=h[b],d.push("function"==typeof a.unsub?a.unsub():void 0);return d},g=function(a){return a.unsub=a.input.subscribeInternal(d(a.input))},k=function(a){var b,c,d,e;for(b=d=0,e=h.length;e>d;b=++d)if(c=h[b],c.input===a)return"function"==typeof c.unsub&&c.unsub(),void h.splice(b,1)},f=function(){return function(a){var b,c,d,f;for(e=a,f=v(h),c=0,d=f.length;d>c;c++)b=f[c],g(b);return j}}(this),c.__super__.constructor.call(this,z(a,"Bus"),f),this.plug=function(){return function(a){var c;if(!b)return c={input:a},h.push(c),null!=e&&g(c),function(){return k(a)}}}(this),this.push=function(){return function(a){return"function"==typeof e?e(R(a)):void 0}}(this),this.error=function(){return function(a){return"function"==typeof e?e(new i(a)):void 0}}(this),this.end=function(){return function(){return b=!0,j(),"function"==typeof e?e(A()):void 0}}(this)}return hb(c,b),c}(k),s=function(){function a(a,b,c,d){this.obs=a,this.sync=b,this.subscribe=c,this.lazy=null!=d?d:!1,this.queue=[],null==this.subscribe&&(this.subscribe=this.obs.subscribeInternal),this.toString=this.obs.toString}return a.prototype.markEnded=function(){return this.ended=!0},a.prototype.consume=function(){return this.lazy?db.always(this.queue[0]):this.queue[0]},a.prototype.push=function(a){return this.queue=[a]},a.prototype.mayHave=function(){return!0},a.prototype.hasAtLeast=function(){return this.queue.length},a.prototype.flatten=!0,a}(),e=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return hb(b,a),b.prototype.consume=function(){return this.queue.shift()},b.prototype.push=function(a){return this.queue.push(a)},b.prototype.mayHave=function(a){return!this.ended||this.queue.length>=a},b.prototype.hasAtLeast=function(a){return this.queue.length>=a},b.prototype.flatten=!1,b}(s),b=function(a){function b(a){this.obs=a,b.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return hb(b,a),b.prototype.consume=function(){var a;return a=this.queue,this.queue=[],function(){return a}},b.prototype.push=function(a){return this.queue.push(a())},b.prototype.hasAtLeast=function(){return!0},b}(s),s.isTrigger=function(a){return a instanceof s?a.sync:a instanceof k},s.fromObservable=function(a){return a instanceof s?a:a instanceof p?new s(a,!1):new e(a,!0)},z=function(){var a,b,c;return b=arguments[0],c=arguments[1],a=3<=arguments.length?fb.call(arguments,2):[],(b||c)instanceof f?b||c:new f(b,c,a)},f=function(){function a(a,b,c){var d,e,f,g;f=function(a){return G(a)?db.flatMap(f,a):J(a)?[a]:a instanceof s?[a.obs]:[]},g=null,d=function(a){var b,c,e,f,h;for(c=a.internalDeps(),h=[],e=0,f=c.length;f>e;e++)b=c[e],g[b.id]=!0,h.push(d(b));return h},e=function(a){return null==g&&(g={},d(this)),g[a.id]},this.apply=function(d){var g;return g=db.cached(function(){return f([a].concat(c))}),d.internalDeps=d.internalDeps||g,d.dependsOn=e,d.deps=g,d.toString=function(){return db.toString(a)+"."+db.toString(b)+"("+db.map(db.toString,c)+")"},d.inspect=function(){return d.toString()},d.desc=function(){return{context:a,method:b,args:c}},d}}return a}(),bb=function(){var a,b,c;return a=2<=arguments.length?fb.call(arguments,0,c=arguments.length-1):(c=0,[]),b=arguments[c++],z.apply(null,a).apply(b)},a.when=function(){var b,c,d,e,f,g,h,i,j,l,m,n,o,p,q,r,u,v,y,B;if(l=1<=arguments.length?fb.call(arguments,0):[],0===l.length)return a.never();for(f=l.length,q="when: expecting arguments in the form (Observable+,function)+",o=[],j=[],c=0;f>c;){for(i=db.toArray(l[c]),b=l[c+1],h={f:I(b)?b:function(){return b},ixs:[]},p=!1,r=0,v=i.length;v>r;r++){for(n=i[r],d=db.indexOf(o,n),p||(p=s.isTrigger(n)),0>d&&(o.push(n),d=o.length-1),B=h.ixs,u=0,y=B.length;y>u;u++)e=B[u],e.index===d&&e.count++;h.ixs.push({index:d,count:1})}i.length>0&&j.push(h),c+=2}return o.length?(o=db.map(s.fromObservable,o),g=db.any(o,function(a){return a.flatten})&&x(db.map(function(a){return a.obs},o)),m=new k(z.apply(null,[a,"when"].concat(fb.call(l))),function(b){var d,e,f,h,i,k,l;return l=[],f=!1,h=function(a){var b,d,e;for(e=a.ixs,b=0,d=e.length;d>b;b++)if(c=e[b],!o[c.index].hasAtLeast(c.count))return!1;return!0},e=function(a){return!a.sync||a.ended},d=function(a){var b,d,e;for(e=a.ixs,b=0,d=e.length;d>b;b++)if(c=e[b],!o[c.index].mayHave(c.count))return!0},i=function(a){return!a.source.flatten},k=function(k){return function(n){var p,q,r;return q=function(){return t.whenDoneWith(m,p)},r=function(){var d,e,f,k,m,n;if(!(l.length>0))return a.more;for(f=a.more,k=l.pop(),m=0,n=j.length;n>m;m++)if(e=j[m],h(e))return d=function(){var a,b,d,f;for(d=e.ixs,f=[],a=0,b=d.length;b>a;a++)c=d[a],f.push(o[c.index].consume());return f}(),f=b(k.e.apply(function(){var a,b;return b=function(){var b,c,e;for(e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a());return e}(),e.f.apply(e,b)})),l.length&&g&&(l=db.filter(i,l)),f===a.noMore?f:r()},p=function(){var c;return c=r(),f&&(f=!1,(db.all(o,e)||db.all(j,d))&&(c=a.noMore,b(A()))),c===a.noMore&&n(),c},k.subscribe(function(c){var d;return c.isEnd()?(f=!0,k.markEnded(),q()):c.isError()?d=b(c):(k.push(c.value),k.sync&&(l.push({source:k,e:c}),g?q():p())),d===a.noMore&&n(),d||a.more})}},w.apply(null,function(){var a,b,c;for(c=[],a=0,b=o.length;b>a;a++)n=o[a],c.push(k(n));return c}())})):a.never()},x=function(b,c){var d;return null==c&&(c=[]),d=function(b){var e;return a._.contains(c,b)?!0:(e=b.internalDeps(),e.length?(c.push(b),a._.any(e,d)):(c.push(b),!1))},a._.any(b,d)},a.update=function(){var b,c,d,e;for(c=arguments[0],e=2<=arguments.length?fb.call(arguments,1):[],d=function(a){return function(){var b;return b=1<=arguments.length?fb.call(arguments,0):[],function(c){return a.apply(null,[c].concat(b))}}},b=e.length-1;b>0;)e[b]instanceof Function||(e[b]=function(a){return function(){return a}}(e[b])),e[b]=d(e[b]),b-=2;return bb.apply(null,[a,"update",c].concat(fb.call(e),[a.when.apply(a,e).scan(c,function(a,b){return b(a)})]))},w=function(){var a;return a=1<=arguments.length?fb.call(arguments,0):[],new d(a).unsubscribe},d=function(){function a(a){var b,c,d;for(null==a&&(a=[]),this.unsubscribe=ib(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[],c=0,d=a.length;d>c;c++)b=a[c],this.add(b)}return a.prototype.add=function(a){var b,c,d;if(!this.unsubscribed)return b=!1,c=S,this.starting.push(a),d=function(d){return function(){return d.unsubscribed?void 0:(b=!0,d.remove(c),db.remove(a,d.starting))}}(this),c=a(this.unsubscribe,d),this.unsubscribed||b||this.subscriptions.push(c),db.remove(a,this.starting),c},a.prototype.remove=function(a){return this.unsubscribed?void 0:void 0!==db.remove(a,this.subscriptions)?a():void 0},a.prototype.unsubscribe=function(){var a,b,c,d;if(!this.unsubscribed){for(this.unsubscribed=!0,d=this.subscriptions,b=0,c=d.length;c>b;b++)(a=d[b])();return this.subscriptions=[],this.starting=[]}},a.prototype.count=function(){return this.unsubscribed?0:this.subscriptions.length+this.starting.length},a.prototype.empty=function(){return 0===this.count()},a}(),a.CompositeUnsubscribe=d,r=function(){function a(a){this.value=a}return a.prototype.getOrElse=function(){return this.value},a.prototype.get=function(){return this.value},a.prototype.filter=function(b){return b(this.value)?new a(this.value):n},a.prototype.map=function(b){return new a(b(this.value))},a.prototype.forEach=function(a){return a(this.value)},a.prototype.isDefined=!0,a.prototype.toArray=function(){return[this.value]},a.prototype.inspect=function(){return"Some("+this.value+")"},a.prototype.toString=function(){return this.inspect()},a}(),n={getOrElse:function(a){return a},filter:function(){return n},map:function(){return n},forEach:function(){},isDefined:!1,toArray:function(){return[]},inspect:function(){return"None"},toString:function(){return this.inspect()}},t=function(){var b,c,d,e,f,g,h,i,j,k,l;return i=void 0,j=[],c=[],b=function(a){return i?c.push(a):a()},h=function(a){return!db.any(j,function(b){return a.obs.dependsOn(b.obs)})},k=function(a,b){return i?j.push({obs:a,f:b}):b() },e=function(){for(;!h(j[0]);)j.push(db.popHead(j));return db.popHead(j)},f=function(){var a;for(a=[];j.length;)a.push(e().f());return a},g=function(a,b,d,e){var g;if(i)return d.apply(b,e);i=a;try{g=d.apply(b,e),f()}finally{for(i=void 0;c.length;)(d=c.splice(0,1)[0])()}return g},d=function(){return i?i.id:void 0},l=function(c){return function(d){var e,f,g;return g=!1,e=function(){},f=function(){return g=!0,e()},g||(e=c.subscribeInternal(function(c){return b(function(){var b;return g||(b=d(c),b!==a.noMore)?void 0:f()})})),f}},{whenDoneWith:k,inTransaction:g,currentEventId:d,wrappedSubscribe:l}}(),a.EventStream=k,a.Property=p,a.Observable=o,a.Bus=c,a.Initial=l,a.Next=m,a.End=h,a.Error=i,S=function(){},K=function(a,b){return b()},D=function(a){return a},F=function(a){return new l(db.always(a))},R=function(a){return new m(db.always(a))},A=function(){return new h},Y=function(a){return a instanceof j?a:R(a)},v=function(a){return a.slice(0)},I=function(a){return"function"==typeof a},G=function(a){return a instanceof Array},J=function(a){return a instanceof o},T=function(a,b){return function(){var c;return c=1<=arguments.length?fb.call(arguments,0):[],a.apply(null,b.concat(c))}},Q=function(a){return 1===a.length&&J(a[0])?db.always(a[0]):N(a)},N=function(a){return a=Array.prototype.slice.call(a),O.apply(null,a)},O=cb(function(){var a,b;return b=arguments[0],a=2<=arguments.length?fb.call(arguments,1):[],I(b)?a.length?T(b,a):b:H(b)?Z(b,a):db.always(b)}),M=function(a,b){return O.apply(null,[a].concat(fb.call(b)))},P=function(b){return J(b)?b:a.once(b)},H=function(a){return"string"==typeof a&&a.length>1&&"."===a.charAt(0)},a.isFieldKey=H,Z=function(a,b){var c,d;return d=a.slice(1).split("."),c=db.map(ab(b),d),function(b){var d,e;for(d=0,e=c.length;e>d;d++)a=c[d],b=a(b);return b}},ab=function(a){return function(b){return function(c){var d;return null==c?void 0:(d=c[b],I(d)?d.apply(c,a):d)}}},$=function(a){return a.slice(1)},X=function(a){var b;return I(a)?a:H(a)?(b=$(a),function(a,c){return a[b](c)}):void 0},_=function(a){return a instanceof r||a===n?a:new r(a)},db={indexOf:Array.prototype.indexOf?function(a,b){return a.indexOf(b)}:function(a,b){var c,d,e,f;for(c=e=0,f=a.length;f>e;c=++e)if(d=a[c],b===d)return c;return-1},indexWhere:function(a,b){var c,d,e,f;for(c=e=0,f=a.length;f>e;c=++e)if(d=a[c],b(d))return c;return-1},head:function(a){return a[0]},always:function(a){return function(){return a}},negate:function(a){return function(b){return!a(b)}},empty:function(a){return 0===a.length},tail:function(a){return a.slice(1,a.length)},filter:function(a,b){var c,d,e,f;for(c=[],e=0,f=b.length;f>e;e++)d=b[e],a(d)&&c.push(d);return c},map:function(a,b){var c,d,e,f;for(f=[],d=0,e=b.length;e>d;d++)c=b[d],f.push(a(c));return f},each:function(a,b){var c,d,e;e=[];for(c in a)d=a[c],e.push(b(c,d));return e},toArray:function(a){return G(a)?a:[a]},contains:function(a,b){return-1!==db.indexOf(a,b)},id:function(a){return a},last:function(a){return a[a.length-1]},all:function(a,b){var c,d,e;for(null==b&&(b=db.id),d=0,e=a.length;e>d;d++)if(c=a[d],!b(c))return!1;return!0},any:function(a,b){var c,d,e;for(null==b&&(b=db.id),d=0,e=a.length;e>d;d++)if(c=a[d],b(c))return!0;return!1},without:function(a,b){return db.filter(function(b){return b!==a},b)},remove:function(a,b){var c;return c=db.indexOf(b,a),c>=0?b.splice(c,1):void 0},popHead:function(a){return a.splice(0,1)[0]},fold:function(a,b,c){var d,e,f;for(e=0,f=a.length;f>e;e++)d=a[e],b=c(b,d);return b},flatMap:function(a,b){return db.fold(b,[],function(b,c){return b.concat(a(c))})},cached:function(a){var b;return b=n,function(){return b===n&&(b=a(),a=null),b}},toString:function(a){var b,c,d,e;try{return U++,null==a?"undefined":I(a)?"function":G(a)?U>5?"[..]":"["+db.map(db.toString,a).toString()+"]":null!=(null!=a?a.toString:void 0)&&a.toString!==Object.prototype.toString?a.toString():"object"==typeof a?U>5?"{..}":(c=function(){var c;c=[];for(d in a)gb.call(a,d)&&(e=function(){try{return a[d]}catch(c){return b=c}}(),c.push(db.toString(d)+":"+db.toString(e)));return c}(),"{"+c+"}"):a}finally{U--}}},U=0,a._=db,a.scheduler={setTimeout:function(a,b){return setTimeout(a,b)},setInterval:function(a,b){return setInterval(a,b)},clearInterval:function(a){return clearInterval(a)},now:function(){return(new Date).getTime()}},"undefined"!=typeof define&&null!==define&&null!=define.amd?(define([],function(){return a}),this.Bacon=a):"undefined"!=typeof module&&null!==module?(module.exports=a,a.Bacon=a):this.Bacon=a}).call(this);