VimUnDoB#%Z3h~)i6姯h=R&mPoA return next(element), index <= end ? (stop(), false) : true#NRt_W4i'i#v#NOܖTVXq4 var streams = stack(source), open = 1, interrupt5_h@i'i#v#NOܞgjq@ // If steam is still open and read is not interrupted 5_j=j'j#v#NOܯikrF return open && false !== alive ? alive = next(value) : false5_i j'j#v#NOܱhjr //5_i;j'j#v#NOhjr; // element to the reader, otherwise we interrupt 5_iBj'j#v#NOVhjrB // element to the reader, otherwise we interrupt reader.5_Nj'j#v#NOMOr4 * var stream = merge(list(async, list(1, 2, 3)))5_W(J JvNOWVXr0 var streams = stack(source), open = 1, alive5_g+J JvNP&gis gir5_hJ JvNP'Xgis console.log()5_hJ JvNP'BYgis console.log(element)5_hJ JvNP'hjt hjs5_W0J JvNP'ZVXt0 var streams = stack(source), open = 2, alive5_e3J JvNP'egu egt5_fJ JvNP'[egu console.log()5_jmm'v'NP(0]iku console.log()5_jmm'v'NP)iku. console.log(open && false !== alive)5_jmm'v'NP)^iku/ console.log(open, && false !== alive)5_fmm'v'NP)*_egu console.log(stream)5__mm'v'NP)q`b console.log_bv _au5_aoo'v'NP)u``bw console.log()5_W(oo'v'NP)aVXw7 var streams = stack(source), open = 2, alive = true5_W(oo'v'NP*bVXw7 var streams = stack(source), open = 3, alive = true5_Xoo'v'NP**XZx XZw5_Ypp'v'NP*-XZx console.log()5_Ypp'v'NP*-cXZx console.log('')5_Ypp'v'NP*2dXZx console.log('stop')5_bpp'v'NP*?eacx console.log(open)5_ipp'v'NP*Pfhjx! console.log(stream, open)5_lpp'v'NP*Vkmx% console.log('!!!', element)5_l(pp'v'NP*Ykmx) console.log('element', element)5_l.pp'v'NP*]kmx/ console.log('element', element, open)5_mmm*v*NP*`lnx, console.log(open, false !== alive)5_mmm*v*NP*alnx console.log(open, )5_m mm*v*NP*alm console.log(open, 5_l0mm*v*NP*dgkmw1 console.log('element', element, open, )5_W(mm*v*NP*hVXw7 var streams = stack(source), open = 1, alive = true5_iii*v*NP*hjw+ console.log('stream', stream, open)5_iii*v*NP*hi 5_iii*v*NP*iikw ikv5_W*ii*v*NP+WYx WYw5_Xjj*v*NP+ WYx function onStop()5_ Xjj*v*NP+jWZx function onStop() {}5_  [[gvNP+)Z\y  console.log('stop', open)8 // If no more open streams left just return early.. if (!open || false === alive) return nilE // If stream was stopped with error we mark all streams closed. if (error) open = 0< // Otherwise we just decrement number of open streams. else open --$ console.log('decrement', open)4 // If stream is no longer open we stop reader. if (!open) stop(error)5_    [[[!vNP+,Z[ 5_   X[[!vNP+-Xfm XZl5_  ghh!vNP+5fhy !function onStop(error) {5_ ghh!vNP+8fhy !function recursive(error) {5_rhh!vNP+@kqsy }, onStop)5_j hh!vNP+Sliky4 else head(streams)(function onStream(stream) {5_ghh!vNP+^mgiz giy5_h ii!vNP+ingiz onStop()5_fii!vNP+ofhz5_Xjj!vNP+pWY{ function onStop() {5_Wjj!vNP+qWY{5__kk!vNP+r_a|5_`ll!vNP+t_`5_W(kk!vNP,>uVX|7 var streams = stack(source), open = 2, alive = true5_W(kk!vNP,vVX|7 var streams = stack(source), open = 3, alive = true5_W(kk!vNP,wVX|7 var streams = stack(source), open = 2, alive = true5_Zkk!vNP- YZ console.log('stop', open)5_bjj!vNP- ab$ console.log('decrement', open)5_bii!vNP- ab5_lhh!vNP-kl+ console.log('stream', stream, open)5_ mhh!vNP-xlm@ console.log('element', element, open, false !== alive)5_! W(hh!vNP-myVXw7 var streams = stack(source), open = 3, alive = true5_ "!chh!vNP-wzbdw if (!open) stop(error)5_!$"_hh!vNP-z|^_< // Otherwise we just decrement number of open streams.5_"%#$ogg!vNP-npv }, recur)5_$&%o gg!vNP-npv }, func)5_%'&ogg!vNP-npv }, func)5_&('ogg!vNP-npv }, function onStop())5_')(ogg!vNP-nqv! }, function onStop() {})5_(*)ogg!vNP-npw }, function onStop() {5_)+*o gg!vNP-oqx oqw5_*,+pgg!vNP-oqx if ()5_+-,pgg!vNP-}oqx if (error)5_,.-pgg!vNP.pry prx5_-/.qgg!vNP.pry if ()5_.0/qgg!vNP.pry if (!open)5_/10qgg!vNP.~pry if (!open) stop()5_021pgg!vNP.oqy if (error) open = 05_132pgg!vNP.oqy if (error) stop()5_243pgg!vNP.oqy if (error) stop(error)5_354pgg!vNP.oqy( if (error) returns stop(error)5_465pgg!vNP.oqy' if (error) return stop(error)5_576pgg!vNP."oqy* return error) return stop(error)5_687p+gg!vNP.$oqy+ return error ? return stop(error)5_798p3gg!vNP.+oqy3 return error ? return stop(error) : recur5_8:9q gg!vNP.-pq if (!open) stop(error)5_9;:p gg!vNP.:oqx5 return error ? return stop(error) : recur()5_:<;p gg!vNP.AoqxC return error ? return open = false, stop(error) : recur()5_;=<p:gg!vNP.EoqxD return error ? return (open = false, stop(error) : recur()5_<>=p>gg!vNP.XoqxE return error ? return (open = false, stop(error)) : recur()5_=?>pOgg!vNP.coqxO return error ? return (open = false, stop(error)) : (open --, recur()5_>@?fgg!vNP.lef onStop(error)5_?A@fff!vNP.mefF // Otherwise we open a next stream and pipe all it's elements to5_@BAfff!vNP.mef // the reader.5_ACBoff!vNP.pnpu }, onStop)5_BDCoff!vNP.unpu }, function onStop())5_CEDoff!vNP.unqu }, function onStop() {})5_DFEoff!vNP.{npv }, function onStop() {5_EGFoff!vNP.}oqw oqv5_FHGm ff!vNP.lnwP return error ? return (open = false, stop(error)) : (open --, recur())5_GIHpff!vNP.oqw return error 5_HJIpff!vNP.oqw return error ? ()5_IKJp$ff!vNP.oqw% return error ? (open = false)5_JLKp+ff!vNP.oqw- return error ? (open = false, stop())5_KMLp2ff!vNP.orw2 return error ? (open = false, stop(error))5_LNMqff!vNP.prx open5_MONqff!vNP.prx !open5_NPOqff!vNP.prx !open ? stop()5_OQPqff!vNP.prx !open ? stop()5_PRQq#ff!vNP.prx# !open ? stop() : inl5_QSRXXcvNP.WYx  function onStop(error) {8 // If no more open streams left just return early.. if (!open || false === alive) return nilE // If stream was stopped with error we mark all streams closed. if (error) open = 0 else open --4 // If stream is no longer open we stop reader. if (!open--) stop(error) }5_RTSYXXvNP/ Y[m Y[l5_SUTZXXvNP/YZ function o5_TVUXXXvNP/TWYl5_UWVXXXvNP/WWYl func5_VXWXXXvNP/XWYl func5_WYXXXXvNP/`WYl function onStop()5_XZYXXXvNP/bWZl function onStop() {}5_Y[ZXXXvNP/dXZn XZm5_Z\[XXXvNP/iWYn function onStop() {5_[]\YXXvNP/nXZn return error ? 5_\^]YXXvNP/oXZn return error ? ()5_]_^Y)XXvNP/vXZn+ return error ? (open = false, stop())5_^`_W7XXvNP/VXn7 var streams = stack(source), open = 0, alive = true5__a`Y XXvNP/XZn0 return error ? (open = false, stop(error))5_`baYXXvNP/X[n: return stopped ? error ? (open = false, stop(error))5_acbZ#XXvNP/Y[o0 error ? (open = false, stop(error))5_bfcZ@XXvNP/Y\o@ error ? (open = false, stopped = true, stop(error))5_cgdfY XXvNP/XZp return stopped ? nil :5_fhg[ XXvNP/Z\p open5_gih[XXvNP/Z\p !open5_hji[XXvNP/Z\p !open ? stop()5_ilj[ XXvNP/Z\p !open ? stop(error)5_joklYXXvNP0 XZp return !stopped ? nil :5_lpnoZXXvNP0Y[pB error ? (open = false, stopped = true, stop(error)) :5_oqp[!XXvNP0+Z\p! !open ? stop(error) 5_prq\XXvNP0M\^p5_qsrh!XXvNP0Rgiq! }, function onStop(error) {5_rtsiXXvNP0Xhi4 return error ? (open = false, stop(error)) :5_sutiXXvNP0Yhi# !open ? stop() : nil5_tvuiXXvNP0Zhi })5_uwvf7XXvNP0egnI return error ? (open = false, stop(error)) : (open --, recur())5_vxwfXXvNP0egn# return (open --, recur())5_wzxeXXvNP0dfn$ }, function onStop(error) {5_x{yzfffvNP0egn2 return (open --, onStop(error), recur())5_z|{fffvNP0egn* return ( onStop(error), recur())5_{}|f ffvNP1egn) return (onStop(error), recur())5_|~}hffvNP1ggin }, onStop)5_}~fffvNP1megn2 return (onStop(error), open --, recur())5_~effvNP1vdfn }, function (error) {5_XffvNP1{WYn function onStop(error) {5_WffvNP1~WYn5_eggvNP7dfoH return open && false !== alive ? alive = next(element) : false5_eggvNP7dfoP return stopped open && false !== alive ? alive = next(element) : false5_eggvNP7dfoQ return !stopped open && false !== alive ? alive = next(element) : false5_`ggvNP8\`bp `bo5_ahhvNP8_`a console5_aggvNP8`acp aco5_bhhvNP8cacp console.log()5_bhhvNP8gacp console.log(open, )5_bhhvNP8jacp console.log('open, )5_bhhvNP8lacp console.log('open:', )5_bhhvNP8oacp console.log('open:', )5_g hhvNP8sgiq gip5_hiivNP8xgiq console.log()5_hiivNP8xgiq console.log('')5_hiivNP8|giq console.log('close')5_YiivNP8Y[r Y[q5_ZjjvNP8Y[r console.log()5_ZjjvNP8Y[r console.log('')5_ZjjvNP8Y[r console.log('update')5_bjjvNP9acr open ++5_YjjvNP9Y[s Y[r5_k)kkvNP9+jls2 return (update(error), open --, recur())5_^kkvNP9]_s nil5_ZkkvNP9YZ open --5_ZjjvNP9YZ! console.log('update', open)5_biivNP9ab" console.log('open:', open)5_ghhvNP9fg console.log('close')5_bggvNP:0bdp bdo5_chhvNP:3bdp console.log()5_chhvNP:4bdp console.log('')5_chhvNP:5bdp console.log('>>>')5_`#hhvNP;6`bq `bp5_aiivNP;:`bq console.log()5_aiivNP;`bq console.log(stream)5_diivNP;ceq% console.log('>>>', element)5_hiivNP;hjr hjq5_ijjvNP;hjr console.log()5_ijjvNP;hjr console.log('')5_ijjvNP;hjr console.log('close')5_YjjvNP;Y[s Y[r5_ZkkvNP;Y[s console.log()5_ZkkvNP;Y[s console.log('')5_ZkkvNP;Y[s console.log('sync: ')5_kkkvNP<]jls) return (update(error), recur())5_kkkvNP<^jls return (, recur())5_kkkvNP<_jls return (recur())5_Z!kkvNP)u t5_mmvNP>3u return filter()5_mmvNP>6u return filter(function())5_mmvNP>7u return filter(function() {})5_nnvNP>:v return filter(function() {5_nnvNP><w v5_oovNP>Ew stop5_oovNP>x w5_ppvNP>x return start < index5_ppvNP>x return index < stream5_ppvNP>x return index < start5_ ppvNP>x return index++ < start5_ppvNP>x return ++index++ < start5_ppvNP>x return ++index < start5_ ppvNP>x return ++index <= start5_ppvNP>x return index <= start5_ppvNP>x return index++ <= start5_ppvNP>x return index ++ <= start5_ppvNP>x })5_ppvNP>x }, source)5_ ppvNP>x# return filter(function(element) {5_ ppvNP>x# return filter(function(element) {5_ppvNP>x( return take(filter(function(element) {5_qqvNP?y return take(function () {5_qqvNP? z y5_#vNP?z & return function stream(next, stop) { var index = -1, interrupt( source(function onElement(element) {D // Skip elements until we reach start of the extraction range.& if (++index < start) return trueA // If index is in range we want to extract from then yield.0 if (index < end) interrupt = next(element)E // If this is last element we stop stream and interrupt reading; return index + 1 >= end ? (stop(), false) : interrupt }, stop = limit(stop)) }5_vNP? 5_vNP?Ao return index ++ < start5_ vNP?Do return index ++ > start5_vNP?Go return ++index ++ > start5_vNP?Jo return ++index > start5_ vNP?Mo return ++index >= start5_vNP?Po return index >= start5_vNP?Ro return index++ >= start5_vNP?So return index+ + >= start5_vNP?So return index++ >= start5_ vNP?Uo return ++index < end5_ vNP?io }, source)5_vNP?o return index ++ >= start5_ vNP?o return index ++ > start5_vNP?o return ++ index ++ > start5_vNP?o return ++ index > start5_vNP?o return index > start5_vNP?o return index < start5_vNP?o return index++ < start5_vNP?o return index ++ < start5_vNP?o return start5_vNP?o return ++ index < end5_vNP?o return end5_vNP@@p var index = 0p o5_ vNP@zo" return take(function (element) {5_vNP@p return end >= index ++5_vNP@p return end >= index ++ }, filter(function(element) { return start <= index ++ }, source))5_vNP@p }, source))5_vNP@p }, source))()5_vNP@p }, source))(next, stopped)5_vNP@q p5_vNP@q var index = 05_vNP@ 5_vNP@q p5_ vNPAAq }, stop)5_vNPAHq }, stop = limit())5_vNPAq return end >= index ++5_vNPAq return end >= index5_ vNPBUq return end >= ++ index5_   vNPBq return end >= index5_   vNPBq return end >= index + 15_ vNPBq return end < index + 15_vNPBq return end < index5_vNPBq return index5_vNPBq return index < ended5_vNPBq return index < end5_vNPDq return index <= end5_vNPD"q return index <= end ? 5_vNPD#q return index < end ? 5_vNPDJ take(function (element) {5_vNPDK0 return index < end ? true : index === end 5_vNPDMo! }, filter(function(element) {5_vNPDYo }, source))(next, stop)5_ vNPD\o }, source)(next, stop)5_! "vNPDao. }, source)(function onElement()next, stop)5_ "!+vNPDdo6 }, source)(function onElement(elements)next, stop)5_!#"vNPDpp next, stop)5_"$#vNPDyp }, stop = limit())5_#%$vNPD|p5_$&%vNPD~q5_%'&vNPDq index === end ? stop()5_&('$vNPDq% index === end ? stop() : next()5_'*(*vNPDq- }, source)(function onElement(elements) {5_(3)*vNPDq, index === end ? stop() : next(element)5_*4+3vNPDq* index < end ? stop() : next(element)5_354vNPDq$ index < end ? : next(element)5_4V5vNPDq! index < end ? next(element)5_5W6VvNPGq next(element)5_VXWvNPGq return next(element)5_WX3vNPGq3 return next(element), index === stop ? stop()5_XZ3vNPIq9 return next(element), index === stop ? stop() : nil5_-vNPJq@ return next(element), index === stop ? stop(), false : nil5_;vNPJ qA return next(element), index === stop ? (stop(), false : nil5_*vNPJqB return next(element), index === stop ? (stop(), false) : nil5_vNPJ5q% return function steam(next, stop) {5_` vNP_aq" console.log('open stream')5_`vNP_aq console.log('open')5_h`&`vNPgiq console.log('close')5_c`&`vNPbdq' console.log('yield', element)5_a`&`vNP `bq open += 25_a`&`vNP`bq open +++5_XX XvNPWYq open --5_XX XvNPWX 5_W!X XvNPVXp" console.log('sync: ', error)5_h(X XvNP!gip) return (recur(), update(error))5_h*h0h*v*NP1gip2 return (recur(), update(error), open --)5_h*h0h*v*NP1gip+ return (recur(), update(error), )5_hh0h*v*NP3gip) return (recur(), update(error))5_hhh!v!NP:gip2 return (open --, recur(), update(error))5_hhh!v!NP;gip+ return (open --, , update(error))5_h(hh!v!NP=gip) return (open --, update(error))5_T)hh!v!NPFSUpH var streams = stack(source), open = 1, alive = true, stopped = false5_hhhvNPggip2 return (open --, update(error), recur())5_hhhvNPhgip+ return (, update(error), recur())5_h!hhvNPkgip) return (update(error), recur())5_h!h)h!v!NP{gip2 return (update(error), open --, recur())5_h(h)h!v!NP} gip) return (update(error), recur())5_h3h)h!v!NP!gip4 return (update(error), recur(), open --, )5_T(h)h!v!NP"SUpH var streams = stack(source), open = 0, alive = true, stopped = false5_h*h*h0v0NPgip2 return (update(error), recur(), open --)5_h*h*h0v0NP#gip+ return (update(error), recur(), )5_Vh*h0v0NP$VXq VXp5_[i*i0v0NP%Z\q nil5_Wi*i0v0NP&VW open --5___'_vNP^`p( console.log('open', stream.name)5___'_vNP ^_ 5___'_vNP _ap _ao5_`'_'_vNP!_ap( console.log('open', stream.name)5_`*_'_vNP$'_ap+ console.log('open', stream.name, 3)5_g*_'_vNP)(fhp+ console.log('close', stream.name)5_V_'_vNP[UWp function update(error) {5_V_'_vNP^UWp function onStream(error) {5_VSVvNP`UWp function onS(error) {5_jVV v NPgikp }, update)5_hVV v NPj)gip) return (update(error), recur())5_fVV v NPq*egp$ }, function onStop(error) {5_WVV v NP+VXp( console.log('sync: ', error, open)5_WVV v NP-VXp* console.log('onStop: ', error, open)5_jVV v NP-ikp }, onStop)5_jVV v NP1ikp }, function stopped())5_jVV v NP2ilp }, function stopped() {})5_jVV v NP3jlr jlq5_jVV v NP9ikr }, function stopped() {5_kVV v NP;jlr console.log()5_kVV v NP=jlr console.log('')5_kVV v NPAjlr console.log('stop-head')5_kVV v NPDkms kmr5_lVV v NPGkms onStop()5_lVV v NPHlnt lns5_mVV v NPLlnt console.log()5_mVV v NPLlnt console.log('')5_mVV v NPQ.lnt console.log('stop-head')5_hVV v NPagit) return (onStop(error), recur())5_h VV v NPegit" (onStop(error), recur())5_hVV v NPfgjt! onStop(error), recur())5_iVV v NPhhju recur())5_iVV v NPhikv iku5_jVV v NPmikv console.log()5_jVV v NPnikv console.log('')5_jVV v NPp/ikv console.log('#')5_Y-VV v NPXZvK error || !open ? (open = false, stopped = true, stop(error)) :5_YVV v NP2XZv= error || !open ? (stopped = true, stop(error)) :5_YVV v NP3XZv< error || !open ? stopped = true, stop(error)) :5_oVV v NPnpv console.log('#', open)5_jVV v NP4ikv console.log('#', open)5_lVV v NP'5kmv" }, function stopped(error) {5_7VV v NPv!(typeof define !== "function" ? function($){ $(require, exports, module); } : define)(function(require, exports, module, undefined) {5_EVV v NPv!(typeof define !== "function" ? function($){ $(null, exports, module); } : define)(function(require, exports, module, undefined) {5_=VV v NPv{!(typeof define !== "function" ? function($){ $(null, exports); } : define)(function(require, exports, module, undefined) {5_JVV v NPv!(typeof define !== "function" ? function($){ $(null, typeof exports !== ''); } : define)(function(require, exports, module, undefined) {5_UVV v NPv!(typeof define !== "function" ? function($){ $(null, typeof exports !== 'undefined'); } : define)(function(require, exports, module, undefined) {5_UVV v NPv!(typeof define !== "function" ? function($){ $(null, typeof exports !== 'undefined') ; } : define)(function(require, exports, module, undefined) {5_=VV v NPv!(typeof define !== "function" ? function($){ $(null, typeof exports !== 'undefined') ; } : define)(function(require, exports, module, undefined) {5_DVV v NPv!(typeof define !== "function" ? function($){ $(null, typeof(exports !== 'undefined') ; } : define)(function(require, exports, module, undefined) {5_FVV v NPv!(typeof define !== "function" ? function($){ $(null, typeof(exports) !== 'undefined') ; } : define)(function(require, exports, module, undefined) {5_VVV v NPv!(typeof define !== "function" ? function($){ $(null, typeof(exports) === 'undefined') ; } : define)(function(require, exports, module, undefined) {5_^VV v NPv!(typeof define !== "function" ? function($){ $(null, typeof(exports) === 'undefined' ? window ; } : define)(function(require, exports, module, undefined) {5_hVV v NP&v!(typeof define !== "function" ? function($){ $(null, typeof(exports) === 'undefined' ? this : exports ; } : define)(function(require, exports, module, undefined) {5_fVV v NP(v!(typeof define !== "function" ? function($){ $(null, typeof(exports) === 'undefined' ? this : export; } : define)(function(require, exports, module, undefined) {5_fVV v NP*v!(typeof define !== "function" ? function($){ $(null, typeof(exports) === 'undefined' ? this : export, } : define)(function(require, exports, module, undefined) {5_VV v NP.v!(typeof define !== "function" ? function($){ $(null, typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports, module, undefined) {5_4VV v NP4v!(typeof define !== "function" ? function($){ $(null, typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_7VV v NP7v!(typeof define !== "function" ? function($){ $(typeof(), typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_?VV v NP:v!(typeof define !== "function" ? function($){ $(typeof(require), typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_EVV v NP=v!(typeof define !== "function" ? function($){ $(typeof(require) === '', typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_OVV v NP?v!(typeof define !== "function" ? function($){ $(typeof(require) === 'undefined', typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_QQ@vUNPDv!(typeof define !== "function" ? function($){ $(typeof(require) === 'undefined' ?, typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_QQ@vUNPSv!(typeof define !== "function" ? function($){ $(typeof(require) === 'undefined' ? , typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_\Q@vUNPWv!(typeof define !== "function" ? function($){ $(typeof(require) === 'undefined' ? function() , typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_^Q@vUNPXv!(typeof define !== "function" ? function($){ $(typeof(require) === 'undefined' ? function() {} , typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_kQ@vUNP]v!(typeof define !== "function" ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error()} , typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_lQ@vUNP]v!(typeof define !== "function" ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error('')} , typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_Q@vUNPev!(typeof define !== "function" ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error('require unsupported')} , typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_Q@vUNPgv!(typeof define !== "function" ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error('require unsupported') } , typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_Q@vUNPlv!(typeof define !== "function" ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error('require unsupported'); } , typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_Q@vUNPmv!(typeof define !== "function" ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error('require unsupported') } , typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_Q@vUNPv!(typeof define !== "function" ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error('require unsupported') } : require , typeof(exports) === 'undefined' ? this : export } : define)(function(require, exports) {5_ Q@vUNP7v!(typeof define !== "function" ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error('require unsupported') } : require , typeof(exports) === 'undefined' ? this : export) } : define)(function(require, exports) {5_   vNP v!(typeof define !== "function" ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error('require unsupported') } : require , typeof(exports) === 'undefined' ? this : export); } : define)(function(require, exports) {5_   vNP v!(typeof(define !== "function" ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error('require unsupported') } : require , typeof(exports) === 'undefined' ? this : export); } : define)(function(require, exports) {5_  vNPv!(typeof(define) !== "function" ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error('require unsupported') } : require , typeof(exports) === 'undefined' ? this : export); } : define)(function(require, exports) {5_  vNP8v!(typeof(define) === "function" ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error('require unsupported') } : require , typeof(exports) === 'undefined' ? this : export); } : define)(function(require, exports) {5_AvNPv!(typeof(define) !== "function" ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error('require unsupported') } : require , typeof(exports) === 'undefined' ? this : export); } : define)(function(require, exports) {5_OvNP v!(typeof(define) !== "function" ? function($){ $(typeof(require) !== 'undefined' ? function() { throw Error('require unsupported') } : require , typeof(exports) === 'undefined' ? this : export); } : define)(function(require, exports) {5_vNP,v!(typeof(define) !== "function" ? function($){ $(typeof(require) !== 'function' ? function() { throw Error('require unsupported') } : require , typeof(exports) === 'undefined' ? this : export); } : define)(function(require, exports) {5_RvNP0v!(typeof(define) !== "function" ? function($){ $(typeof(require) !== 'function' ? function() { throw Error('require unsupported'); } : require , typeof(exports) === 'undefined' ? this : export); } : define)(function(require, exports) {5_vNP6v!(typeof(define) !== "function" ? function($){ $(typeof(require) !== 'function' ? (function() { throw Error('require unsupported'); } : require , typeof(exports) === 'undefined' ? this : export); } : define)(function(require, exports) {5_vNP9v!(typeof(define) !== "function" ? function($){ $(typeof(require) !== 'function' ? (function() { throw Error('require unsupported'); }) : require , typeof(exports) === 'undefined' ? this : export); } : define)(function(require, exports) {5_vNP}9v!(typeof(define) !== "function" ? function($){ $(typeof(require) !== 'function' ? (function() { throw Error('require unsupported'); }) : require, typeof(exports) === 'undefined' ? this : export); } : define)(function(require, exports) {5_[vVNR@[]w []v5_\wVNR@[]w function pipeStream()5_\wVNR@[]w function pipeStream(stream)5_\!wVNR@[^w" function pipeStream(stream) {}5_\xVNR@\^y \^x5_] yVNRA\^y stream()5_]yVNRA\^y stream(next, )5_]yVNRA\^y stream(next, function)5_ ]yVNRA\^y stream(next, function)5_! ]$yVNRA\^y% stream(next, function onStop())5_ "!]&yVNRA\_y( stream(next, function onStop() {})5_!#"]#zVNRA\^z& stream(next, function onStop() {5_"$#]'zVNRA ]_{ ]_z5_#%$^ {VNRA"]_{ if ()5_$&%^{VNRA#]_{ if (error)5_%'&^{VNRA']_{ if (error) stop()5_&('^{VNRA*^`| ^`{5_')(_|VNRA3^`| else pipeStream()5_(*)_|VNRA5^`| else pipeStream(head())5_)+*__$_vNRA;^`|& else pipeStream(head(streams))5_*,+_ _$_vNRA<^`| else pipeStream()5_+-,__$_vNRA?^`|& else head(streams)pipeStream()5_,.-_'_$_vNRA@^`|' else head(streams)(pipeStream()5_-/.\_$_vNRAb[\! function pipeStream(stream) {5_.0/\^$^vNRAb[\+ stream(next, function onStop(error) {5_/10\]$]vNRAc[\ if (error) stop(error)5_021\\$\vNRAc[\4 else head(streams)(pipeStream, onStreamStop)5_132\\$\vNRAd[\ })5_243\\$\vNRAd:[\ }5_354_\$\vNRAn=^`v open ++5_465Z \$\vNRAYZ open --5_576W[$[vNRA>WYv WYu5_687Z=\$\vNRA?Y[v= error || !open ? (stopped = true, stop(error)) :5_798f\$\vNRBegv% }, function stopped(error) {5_8:9g \$\vNRBfg1 console.log('close', stream.name, open)5_9;:g \$\vNRBfiu onStop(error)5_:<;h \$\vNRB hjw hjv5_;=<g \$\vNRB"gix giw5_<>=f\$\vNRB'fhy fhx5_=?>g\$\vNRB(fhy if ()5_>@?g\$\vNRB*fhy if (stopped)5_?A@h\$\vNRB:giy if (error) {5_@BAg \$\vNRB<fg! if (stopped) return nil5_ACBg\$\vNRB=fhx if (error) 5_BDCg\$\vNRB@fhx if (error) stop()5_CEDh \$\vNRBBgh stopped = 5_DFEh \$\vNRBBgh onStop(error)5_EGFh \$\vNRBCgh }5_FHGg \$\vNRBEgiv giu5_GIHf\$\vNRBLfhw fhv5_HJI_\$\vNRBQ^`w open += 25_IKJi\$\vNRBYhjw else 5_JLKi\$\vNRBYhjw else ()5_KMLj \$\vNRBbij recur()5_LNMj \$\vNRBcij& console.log('stream#', open)5_MONi\$\vNRBehju else (recur)5_NPOi\$\vNRBl@hju else recur()5_OQP_\$\vNRBwA^`u open ++5_PRQT(\$\vNRB~BSUuH var streams = stack(source), open = 1, alive = true, stopped = false5_QSRk!\$\vNRBjlu! }, function stoppe(error) {5_RTSk\$\vNRBjlu }, function onStop()5_SUTk\$\vNRBjlu }, function onStop(error)5_TVUk"\$\vNRBjlu" }, function onStop(error) {}5_UWV\\$\vNRB\^v\^u5_VXW]\$\vNRB\^v stop = limit()5_WYXV\$\vNRBUV function onStop(error) {5_XZYV[$[vNRBUV+ console.log(' onStop: ', error, open)5_Y[ZVZ$ZvNRBUV open --5_Z\[VY$YvNRBUV return stopped ? nil :5_[]\V X$XvNRBUVA error || !open ? (stopped = true, stop(error)) : nil5_\^]VW$WvNRBUV }5_]_^VV$VvNRBCUV5_^`_fV$VvNRBef console.log('stop-head')5__a`fV$VvNRBef onStop(error)5_`bafV$VvNRBef" console.log('head#', open)5_acbeV$VvNRBDegm egl5_bdcfV$VvNRBfhn fhm5_cedg V$VvNRBfhn if ()5_dfegV$VvNRBfhn if (error)5_egfgV$VvNRBfhn if (error) stop()5_fhggV$VvNRBgio gin5_gihhV$VvNRBgio else if ()5_hjihV$VvNRBEgio else if (!open)5_ikjcV$VvNRBcep ceo5_jlkdV$VvNRBcep else ()5_kmldV$VvNRBcep else (stop())5_lnmdV$VvNRBGcep else stop())5_monX.V$VvNRC?XZq XZp5_npoYV$VvNRCCHXY con5_oqpZV$VvNRCIIY[p. console.log('open', stream.name, open)5_prqaZZ0v0NRCRacq acp5_qsrb2ZZ0v0NRCTJacq3 console.log(' open', stream.name, open)5_rtshZZ0v0NRCWhjr hjq5_sutiZZ0v0NRC[hjr1 console.log(' open', stream.name, open)5_tvuiZZ0v0NRC\hjr4 console.log(' closure', stream.name, open)5_uwvbZZ0v0NRC_Kacr3 console.log(' open', stream.name, open)5_vxwT'ZZ0v0NRCSUrH var streams = stack(source), open = 0, alive = true, stopped = false5_wzxT)ZZ0v0NRCLSUrH var streams = stack(source), open = 0, alive = true, stopped = false5_x{yz\ZZ0v0NRC[]r* console.log(' yield', element)5_z|{ZZZ0v0NRCY[r1 console.log(' open', stream.name, open)5_{}|ZZZ0v0NRCY[r2 console.log(' +open', stream.name, open)5_|~}\ZZ0v0NRC[]r, console.log(' yield', element)5_}~\ZZ0v0NRC[]r. console.log(' |- yield', element)5_~bZZ0v0NRCacr4 console.log(' close', stream.name, open)5_iZZ0v0NRChjr2 console.log(' close', stream.name, open)5_iZZ0v0NRCMhjr4 console.log(' _ close', stream.name, open)5_\ZZ0v0NRDN[]r, console.log(' |- yield', element)5_bZZ0v0NRD>Pacr6 console.log(' - close', stream.name, open)5__7ZZ0v0NRE{Q^arT return !stopped && open && false !== alive ? alive = next(element) : false5_YZZ0v0NRERXZs open += 25_T)ZZ0v0NRESSUsH var streams = stack(source), open = 1, alive = true, stopped = false5_iZZ0v0NREVhi open --5_f ZZ0v0NREef else stop()5_eZZ0v0NREWdfq else if (open) recur()5_eZZ0v0NRFXdfq else (open) recur()5_h h h2v2NRFYgiq4 console.log(' - close', stream.name, open)5_hh h2v2NRFZgiq! console.log(' - close')5_ch h2v2NRF[bdq6 console.log(' @ close', stream.name, open)5_\h h2v2NRF\[]q- console.log(' |- yield', element)5_Zh h2v2NRFZ\r Z\q5_[i i2v2NRFZ\r console.log()5_[i i2v2NRF]Z\r console.log('')5_[i i2v2NRFZ\r console.log(stream.name)5_[i i2v2NRFZ\r' console.log(' + 'stream.name)5_[i i2v2NRF^Z\r) console.log(' + 'stream.name)5_ZZZ,v,NRF_Y[r3 console.log(' + open', stream.name, open)5_ZZZ,v,NRF`Y[r% console.log(' + open' open)5_ZZZ,v,NRFaY[r& console.log(' + open', open)5_iZZ,v,NRFhjr! console.log(' < close')5_iZZ,v,NRFbhjr console.log(' < ')5_iZZ,v,NRGchjr" console.log(' < ', open)5_dZZ,v,NRGcer6 console.log(' - close', stream.name, open)5_d#ZZ,v,NRG cer8 console.log(' - close', stream.name, open)5_d2ZZ,v,NRGecer3 console.log(' - ', stream.name, open)5_]$ZZ,v,NRGf\^r/ console.log(' |- yield', element)5_Z ZZ,v,NRGGY[r! console.log(' >', open)5_i ZZ,v,NRGKghjr! console.log(' <', open)5_WZZ,v,NRGWYs WYr5_X[[,v,NRGWYs console.log()5_X[[,v,NRGhWYs console.log('')5_Y[[,v,NRGY[t Y[s5_Z\\,v,NRGY[t console.log()5_Z\\,v,NRGiY[t console.log('')5_X\\,v,NRGlWX console.log('#######')5_f [[,v,NRImegs if (error) stop(error)5_g [[,v,NRIfhs else recur()5_g[[,v,NRInfis //else recur()5_h [[,v,NRIogit //recur()5_T([[,v,NRJhpSUtH var streams = stack(source), open = 0, alive = true, stopped = false5_Z[[,v,NRJqqY[t open ++5_e [[,v,NRJzde- console.log(' - ', stream.name)5_e [[,v,NRJ{dfs" //if (error) stop(error)5_f [[,v,NRJ~egs //else5_f[[,v,NRJegs else5_T([[,v,NRJSUsH var streams = stack(source), open = 1, alive = true, stopped = false5_Z[[,v,NRJY[s open += 25_f[[,v,NRJegs else 5_f[[,v,NRJegs else if ()5_f[[,v,NRJegs else if (open)5_f[[,v,NRJegs else if (!open)5_g [[,v,NRJsfg recur()5_i[[,v,NRJhi console.log(' <')5_i[[,v,NRJikr ikq5_j [[,v,NRJikr if ()5_j[[,v,NRJtikr if (open === 0)5_j[[,v,NRJjls jlr5_k [[,v,NRJjls if ()5_l[[,v,NRJjls if (open === -1)stop()kms else if (!open) stop()5_k[[,v,NRJujlr if (open === -1)stop()5_h [[,v,NRJvhjs hjr5_Z[[,v,NRKxY[s open ++5_d[[,v,NRKydft dfs5_e[[,v,NRK|dft console.log()5_e[[,v,NRK}dft console.log('')5_e[[,v,NRKydft console.log(' - ')5_j[[,v,NRKjlu jlt5_k[[,v,NRKjlu console.log()5_n[[,v,NRQmou if (open === -1) stop()5_A[[,v,NRUjuA return next(element), index === end ? (stop(), false) : nil5_+[[,v,NRUv u5_ \\,v,NRUv if ()5_\\,v,NRUv if (index < end)5_\\,v,NRUv if (index < end) next()5_\\,v,NRUvB return next(element), index === end ? (stop(), false) : true5_\\,v,NRUv$ if (index < end) next(element)5_f\\,v,NRUegv+ console.log(' - ', strict.name)5_ \\,v,NRVv% if (index <= end) next(element)5_\\,v,NRVv! index <= end) next(element)5_\\,v,NRV v" index <= end ? next(element)5_)\\,v,NRVv) return index <= end ? next(element)5_\\,v,NRV next(element), v+ return index <= end ? next(element), 5_ ]],v,NRVw (next(element), &index === end ? (stop(), false) : truew3 return index === end ? (stop(), false) : true5_ C\\,v,NRV stopvC (next(element), index === end ? (stop(), false) : true5_! ]],v,NRV%w stop()5_ "! ]],v,NRV)w stop(), false5_!$"]],v,NRV+w (stop(), false5_"%#$m]],v,NRVlnw console.log('')5_$&%[]],v,NRWZ[ console.log('!!!!!!')5_%'&Y\\,v,NRWY[w Y[v5_&('Z]],v,NRWY[w console.log()5_')(Z]],v,NRWY[w console.log('')5_(*)]],v,NRXw'/* vim:set ts=2 sw=2 sts=2 expandtab */?/*jshint asi: true undef: true es5: true node: true devel: true' forin: false latedef: false *//*global define: true */!(typeof(define) !== "function" ? function($){ $(typeof(require) !== 'function' ? (function() { throw Error('require unsupported'); }) : require, typeof(exports) === 'undefined' ? this : exports); } : define)(function(require, exports) { 'use strict';"var nil // Shortcut for undefined./**H * Internal utility function that takes a `source` function and optionalG * `number` arguments and returns a function that calls `source` with aG * given arguments only first `number` of times it's called. Useful for@ * wrapping callbacks that must be called only ones for example. */ function limit(source, number) { number = number || 1 return function limited() {G return number-- > 0 && source ? source.apply(this, arguments) : nil }}function normalize(source) {& return function stream(next, stop) {' var stopped = false, reading = true( source(function onElement(element) {( if (!stopped && false !== reading)( return (reading = next(element)) }, function onStop(reason) {; return stopped ? nil : (stopped = true, stop(reason)) }) }}/**K * Utility function that returns streams of elements of given `array`. ThisI * function is dangerous as array mutations will have side effects on theJ * returned stream so it should be used with a care, reader of such streamL * **MUST NOT** mutate source array, this is also reason why we don't export * this function. */ function streamArray(elements) {& return function stream(next, stop) { var index = 0# while (index < elements.length)< // If stream reader interrupts reading we just return.9 if (false === next(elements[index++])) return falseK // Once all elements were yielded we stop a stream if such callback was // passed. if (stop) stop() }}/**$ * Creates stream of given elements. * @examples# * list('a', 2, {})(console.log) */function list() {; return streamArray(Array.prototype.slice.call(arguments))}exports.list = list/*8 * Creates empty stream. This is equivalent of `list()`. */function empty() {> return function stream(next, stop) { return stop && stop() }}exports.empty = empty/**# * Returns stream of mapped values. * @param {Function} lambda# * function that maps each value * @param {Function} input * source stream to be mapped * @examples: * var stream = list({ name: 'foo' }, { name: 'bar' })D * var names = map(function(value) { return value.name }, stream) * names(console.log) * // 'foo' * // 'bar'! * var numbers = list(1, 2, 3)N * var mapped = map(function onEach(number) { return number * 2 }, numbers) * mapped(console.log) * // 2 * // 4 * // 6 */function map(lambda, source) {& return function stream(next, stop) {( source(function onElement(element) {" return next(lambda(element)) }, stop) }}exports.map = map/**% * Returns stream of filtered values. * @param {Function} lambda" * function that filters values * @param {Function} source" * source stream to be filtered * @examples* * var numbers = list(10, 23, 2, 7, 17)+ * var digits = filter(function(value) {' * return value >= 0 && value <= 9 * }, numbers) * digits(console.log) * // 2 * // 7 */!function filter(lambda, source) {& return function stream(next, stop) {( source(function onElement(element) {3 return lambda(element) ? next(element) : true }, stop) }}exports.filter = filter/**# * Returns stream of reduced values * @param {Function} source * stream to reduce. * @param {Function} reducer * reducer function * @param initial * initial value * @examples! * var numbers = list(2, 3, 8)> * var sum = reduce(function onElement(previous, current) {( * return (previous || 0) + current * }, numbers) * sum(console.log) * // 13 */+function reduce(reducer, source, initial) {& return function stream(next, stop) { var value = initial( source(function onElement(element) {% value = reducer(value, element) }, function onStop(error) {# if (error) return stop(error) next(value) if (stop) stop() }) }}exports.reduce = reduce/**L * This function returns stream of tuples, where the n-th tuple contains theI * n-th element from each of the argument streams. The returned stream isE * truncated in length to the length of the shortest argument stream. * @params {Function}" * source steams to be combined * @examples% * var a = list([ 'a', 'b', 'c' ])" * var b = list([ 1, 2, 3, 4 ])/ * var c = list([ '!', '@', '#', '$', '%' ]) * var abc = zip(a, b, c) * abs(console.log) * // [ 'a', 1, '!' ] * // [ 'b', 2, '@' ] * // [ 'c', 3, '#' ] */var zip = (function Zip() {+ // Returns weather array is empty or not.2 function isEmpty(array) { return !array.length }G // Utility function that check if each array in given array of arraysA // has at least one element (in which case we do have a tuple).: function hasTuple(array) { return !array.some(isEmpty) }F // Utility function that creates tuple by shifting element from each // array of arrays. function shiftTuple(array) {( var index = array.length, tuple = []< while (0 <= --index) tuple.unshift(array[index].shift()) return tuple } return function zip() {7 var sources = Array.prototype.slice.call(arguments)( return function stream(next, stop) {? var buffers = [], id, reason, isStopped = false, shortest' function onElement(id, element) {N // If resulting stream is already stopped (we are in truncate mode) orP // if this stream is stopped (we deal with badly implemented stream that> // yields value after it's stopped) we ignore element." if (isStopped) return null* // Otherwise we buffer an element.! buffers[id].push(element)) // If tuple is ready we yield it.C return hasTuple(buffers) ? next(shiftTuple(buffers)) : true }" function onStop(id, error) {N // If shortest stream was already stopped then we are in truncate mode@ // which means we ignore all the following stream stops." if (isStopped) return nullL // If stream being stopped is the first one to be stopped or if it'sK // shorter then the shortest one stopped, we update stop reason and- // shortest stopped stream reference.@ if (!shortest || shortest.length > buffers[id].length) { shortest = buffers[id] reason = error }P // If shortest stream has no buffered elements, we stop resulting stream // & do some clean up. if (!shortest.length) {' // Marking stream as stopped. isStopped = true // Stopping a stream. stop(reason)K // Setting all closure captured elements to `null` so that gc can // collect them.# buffers = shortest = null } } // Initializing buffers. id = sources.length( while (0 <= --id) buffers.push([]) // Start reading streams. id = sources.length while (0 <= --id)D sources[id](onElement.bind(null, id), onStop.bind(null, id)) } }})()exports.zip = zip/**K * Returns stream containing first `n` elements of given `source`, on which * given lambda returns `true`. * * @param {Function} lambda# * function that takes elements. * @param {Function} source* * source stream to take elements from. * @examples* * var numbers = list(10, 23, 2, 7, 17)) * var digits = take(function(value) { * return value >= 10 * }, numbers) * digits(console.log) * // 10 * // 23 */function take(lambda, source) {& return function stream(next, stop) {( source(function onElement(element) {> return lambda(element) ? next(element) : stop() && false }, stop = limit(stop)) }}exports.take = take/**M * Returns a stream consisting of the given `source` stream elements startingL * form the `start` zero-based index till `end` zero-based index element. If5 * `end` is not passed all elements will be included. */$function slice(source, start, end) {3 // Zero-based index at which to begin extraction. start = start || 00 // Zero-based index at which to end extraction end = end || Infinity& return function stream(next, stop) { var index = 0 filter(function(element) { return start <= index ++, }, source)(function onElement(element) { return index <= end ?F (next(element), index === end ? (stop(), false) : true) : (stop(), false) }, stop = limit(stop)) }}exports.slice = slice/**K * Returns a stream containing only first `number` of elements of the givenM * `source` stream or all elements, if `source` stream has less than `number`= * of elements. If `number` is not passed it defaults to `1`. * @param {Function} source * source stream * @param {Number} number=1, * number of elements to take from stream */function head(source, number) {= return slice(source, 0, number && number >= 0 ? number : 1)}exports.head = head/**N * Returns a stream equivalent to given `source` stream, except that the firstN * `number` of elements are omitted. If `source` stream has less than `number`O * of elements, then empty stream is returned. `number` defaults to `1` if it's * not passed. * @param {Function} source& * source stream to return tail of. * @param {Number} number=1. * Number of elements that will be omitted. */function tail(source, number) {: return slice(source, number && number >= 0 ? number : 1)}exports.tail = tail/**O * Returns a stream that contains all elements of each stream in the order theyL * appear in the original streams. If any of the `source` streams is stoppedM * with an error than it propagates to the resulting stream and it also get's * stopped. * @examples5 * var stream = append(list(1, 2), list('a', 'b')) * stream(console.log) * // 1 * // 2 * // 'a' * // 'b' */function append() {8 var streams = Array.prototype.slice.call(arguments, 0)& return function stream(next, stop) {* var source, sources = streams.slice(0) function onStop(error) {+ if (error) return stop && stop(error): if ((source = sources.shift())) source(next, onStop) else return stop && stop() } onStop() }}exports.append = append/**J * Returns a stream that contains all elements of each stream of the givenP * source stream. `source` is stream of streams whose elements will be containedK * by the resulting stream. Any error from any stream will propagate to theP * resulting stream. Stream is stopped when all streams from `source` and sourceI * itself is ended. Elements of the stream are position in order they areL * delivered so it could happen that elements from second stream will appear2 * before or between elements of the first stream. * @param {Function} sourceL * Stream of streams whose elements will be contained by resulting stream * @examples" * function async(next, stop) { * setTimeout(function() { * next('async') * stop() * }, 10) * }4 * var stream = merge(list(async, list(1, 2, 3))) * stream(console.log) * // 1 * // 2 * // 3 * // 'async' */function merge(source) {& return function stream(next, stop) { var open = 1, alive function onStop(error) {0 if (!open || false === alive) return false if (error) open = 0 else open -- if (!open) stop(error) }& source(function onStream(stream) { open ++% stream(function onNext(value) {D return open && false !== alive ? alive = next(value) : false }, onStop) }, onStop) }}exports.merge = merge/**% * Utility function to print streams. * @param {Function} stream * stream to print * @examples# * print(list('Hello', 'world')) */function print(stream) { console.log('>>')< stream(console.log.bind(console), function onStop(error) {# if (error) console.error(error) else console.log('<<') })}exports.print = print/**H * Returns a stream equivalent to a given `source`, with difference thatK * all the consumers will start reading it from the point it's at the givenM * moment. This is useful with streams such as user generated events (clicks,M * keypress, etc..) where multiple stream readers might need to read from the, * same source. In other words, this is yourK * [pub / sub](http://en.wikipedia.org/wiki/Publish/subscribe) for streams. * @param {Function} source; * Stream whose elements get published to a subscribers. * @return {Function}5 * Stream that multiple subscribers can read from. * @examples" * function range(start, end) {, * return function stream(next, stop) { * var number = start - 1( * setTimeout(function onNext() { * if (++number >= end) * return stop()' * if (false !== next(number))# * setTimeout(onNext, 2) * }, 2) * } * } * function printer(index) {' * return function print(stream) {> * stream(console.log.bind(console, '#' + index + '>'),9 * console.log.bind(console, '<#' + index)) * } * } * var numbers = range(1, 5) * printer(1)(numbers)8 * setTimeout(function () { printer(2)(numbers) }, 5) *. * // Output will look something like this: * #1> 1 * #1> 2 * #1> 3 * #2> 1 * #1> 4 * #2> 2 * <#1 * #2> 3 * #2> 4 * <#2 *L * // If you noticed second print started form the first `1` element. Now* * // lets do similar thing with a hub. *$ * var numbers = hub(range(1, 5)) * printer(1)(numbers)8 * setTimeout(function () { printer(2)(numbers) }, 5) */ * // In this case output will be different: * * #1> 1 * #1> 2 * #1> 3 * #1> 4 * #2> 4 * <#1 * <#2 *L * // Notice this time second print only printed only following elements. */function hub(source) {/ var listeners = [], isStopped = false, reason# source(function onNext(element) { var index = 0E // Maybe it'd be better to just iterate on sliced array instead ?& while (index < listeners.length) {3 if (listeners[index++][0](element) === false)$ listeners.splice(--index, 1) } }, function onStop(error) { isStopped = true reason = error var listener, stop- while ((listener = listeners.shift())) {, if ((stop = listener[1])) stop(reason) } })& return function stream(next, stop) {: // If stream is already stopped, we notify a listener.' if (isStopped && stop) stop(reason)! // Else we register listener.' else listeners.push([ next, stop ]) }}exports.hub = hub/**O * Returns a stream equivalent to a given `source` by caching all it's elementsN * into memory for faster reads. This is useful with `source` streams that areL * expensive to compute (requires access to the network for example). Use itD * carefully though, do not cache infinite streams and be aware thatB * asynchronous stream when cached will yield some or all elementsL * synchronously. Also be aware, that unlike other functions, this is greedyF * which means that it will start reading `source` stream immediately. * @param {Function} source * source stream to cache. * @returns {Function}B * cached equivalent of source that can be read multiple times. */function cache(source) { var buffer = []@ // Creating a stream that streams element of the buffer array. function cached(next, stop) { var index = 0! while (index < buffer.length)7 if (false === next(buffer[index++])) return false stop() }9 return append(cached, hub(function stream(next, stop) {( source(function onElement(element) { buffer.push(element) return next(element) }, stop) }));}exports.cache = cache/**N * Returns stream equivalent to a given `source` with a difference that it hasL * a state, meaning that if reader stops reading on n-th element next readerM * will continue reading from n-th element. Purpose is to wrap any other typeL * of stream, such that each element of `source` can be read only once. ThisO * allow element distribution across different consumers with a help of `head`, * `tail` and similars. * @param {Function} source0 * source stream to create stack stream from. * @returns {Function}< * stack equivalent of source that can be read only once. */function stack(source) {M var readers = [], buffer = [], isStopped = false, isStarted = false, reason function update() {5 if (!buffer.length || !readers.length) return nil. var resume = readers[0][0](buffer.shift())) if (false === resume) readers.shift() update() } function onNext(element) { update(buffer.push(element)) } function onStop(error) { isStopped = true reason = error var reader = readers.shift()F return reader ? onStop(error, reader[1] && reader[1](error)) : nil }& return function stream(next, stop) {: // If stream is already stopped, we notify a listener.@ if (isStopped && !buffer.length) return stop && stop(reason) readers.push([ next, stop ]) update()B // If `source` stream is not yet being read, start reading it. if (isStarted) return nil isStarted = true source(onNext, onStop) }}exports.stack = stack/**J * Returns a stream that contains all elements of each stream of the givenP * source stream. `source` is stream of streams whose elements will be containedK * by the resulting stream. Any error from any stream will propagate to theP * resulting stream. Stream is stopped when all streams from `source` and sourceO * itself are ended. Elements of the stream are position in order, all elements6 * of first stream, all elements of second stream etc. * @param {Function} sourceL * Stream of streams whose elements will be contained by resulting stream * @examples" * function async(next, stop) { * setTimeout(function() { * next('async') * stop() * }, 10) * }3 * var stream = join(list(async, list(1, 2, 3))) * stream(console.log) * // 'async' * // 1 * // 2 * // 3 */function join(source) {& return function stream(next, stop) {H var streams = stack(source), open = 0, alive = true, stopped = false stop = limit(stop) !function recur(error) { console.log('@')/ head(streams)(function onStream(stream) { open += 2 console.log(' >')+ console.log(' + ', stream.name), stream(function onElement(element) {* console.log(' |- ', element)J // If steam is still open and read is not interrupted we deliverB // element to the reader, otherwise we interrupt source.6 return !stopped && open && false !== alive ?. alive = next(element) : false$ }, function onStop(error) { open --+ console.log(' - ', stream.name) if (error) stop(error)! else if (!open) recur() })! }, function onStop(error) { open -- console.log(' <') if (error) stop(error) if (open === 0) recur()$ else if (open === -1) stop() }) }() }}exports.join = join});5_)+*P]],v,NRXPRm PRl5_*,+Q^^,v,NRXPRm console.log()5_+-,g^^,v,NRXgin gim5_,.-h^^,v,NRXgin console.loc()5_-/.h^^,v,NRXgin console.loc()5_.0/h^^,v,NRXgin console.log()5_/10h^^,v,NRXgin console.log('')5_021^^,v,NRY!n'/* vim:set ts=2 sw=2 sts=2 expandtab */?/*jshint asi: true undef: true es5: true node: true devel: true' forin: false latedef: false *//*global define: true */!(typeof(define) !== "function" ? function($){ $(typeof(require) !== 'function' ? (function() { throw Error('require unsupported'); }) : require, typeof(exports) === 'undefined' ? this : exports); } : define)(function(require, exports) { 'use strict';"var nil // Shortcut for undefined./**H * Internal utility function that takes a `source` function and optionalG * `number` arguments and returns a function that calls `source` with aG * given arguments only first `number` of times it's called. Useful for@ * wrapping callbacks that must be called only ones for example. */ function limit(source, number) { number = number || 1 return function limited() {G return number-- > 0 && source ? source.apply(this, arguments) : nil }}/**K * Utility function that returns streams of elements of given `array`. ThisI * function is dangerous as array mutations will have side effects on theJ * returned stream so it should be used with a care, reader of such streamL * **MUST NOT** mutate source array, this is also reason why we don't export * this function. */ function streamArray(elements) {& return function stream(next, stop) { var index = 0# while (index < elements.length)< // If stream reader interrupts reading we just return.9 if (false === next(elements[index++])) return falseK // Once all elements were yielded we stop a stream if such callback was // passed. if (stop) stop() }}/**$ * Creates stream of given elements. * @examples# * list('a', 2, {})(console.log) */function list() {; return streamArray(Array.prototype.slice.call(arguments))}exports.list = list/*8 * Creates empty stream. This is equivalent of `list()`. */function empty() {> return function stream(next, stop) { return stop && stop() }}exports.empty = empty/**# * Returns stream of mapped values. * @param {Function} lambda# * function that maps each value * @param {Function} input * source stream to be mapped * @examples: * var stream = list({ name: 'foo' }, { name: 'bar' })D * var names = map(function(value) { return value.name }, stream) * names(console.log) * // 'foo' * // 'bar'! * var numbers = list(1, 2, 3)N * var mapped = map(function onEach(number) { return number * 2 }, numbers) * mapped(console.log) * // 2 * // 4 * // 6 */function map(lambda, source) {& return function stream(next, stop) {( source(function onElement(element) {" return next(lambda(element)) }, stop) }}exports.map = map/**% * Returns stream of filtered values. * @param {Function} lambda" * function that filters values * @param {Function} source" * source stream to be filtered * @examples* * var numbers = list(10, 23, 2, 7, 17)+ * var digits = filter(function(value) {' * return value >= 0 && value <= 9 * }, numbers) * digits(console.log) * // 2 * // 7 */!function filter(lambda, source) {& return function stream(next, stop) {( source(function onElement(element) {3 return lambda(element) ? next(element) : true }, stop) }}exports.filter = filter/**# * Returns stream of reduced values * @param {Function} source * stream to reduce. * @param {Function} reducer * reducer function * @param initial * initial value * @examples! * var numbers = list(2, 3, 8)> * var sum = reduce(function onElement(previous, current) {( * return (previous || 0) + current * }, numbers) * sum(console.log) * // 13 */+function reduce(reducer, source, initial) {& return function stream(next, stop) { var value = initial( source(function onElement(element) {% value = reducer(value, element) }, function onStop(error) {# if (error) return stop(error) next(value) if (stop) stop() }) }}exports.reduce = reduce/**L * This function returns stream of tuples, where the n-th tuple contains theI * n-th element from each of the argument streams. The returned stream isE * truncated in length to the length of the shortest argument stream. * @params {Function}" * source steams to be combined * @examples% * var a = list([ 'a', 'b', 'c' ])" * var b = list([ 1, 2, 3, 4 ])/ * var c = list([ '!', '@', '#', '$', '%' ]) * var abc = zip(a, b, c) * abs(console.log) * // [ 'a', 1, '!' ] * // [ 'b', 2, '@' ] * // [ 'c', 3, '#' ] */var zip = (function Zip() {+ // Returns weather array is empty or not.2 function isEmpty(array) { return !array.length }G // Utility function that check if each array in given array of arraysA // has at least one element (in which case we do have a tuple).: function hasTuple(array) { return !array.some(isEmpty) }F // Utility function that creates tuple by shifting element from each // array of arrays. function shiftTuple(array) {( var index = array.length, tuple = []< while (0 <= --index) tuple.unshift(array[index].shift()) return tuple } return function zip() {7 var sources = Array.prototype.slice.call(arguments)( return function stream(next, stop) {? var buffers = [], id, reason, isStopped = false, shortest' function onElement(id, element) {N // If resulting stream is already stopped (we are in truncate mode) orP // if this stream is stopped (we deal with badly implemented stream that> // yields value after it's stopped) we ignore element." if (isStopped) return null* // Otherwise we buffer an element.! buffers[id].push(element)) // If tuple is ready we yield it.C return hasTuple(buffers) ? next(shiftTuple(buffers)) : true }" function onStop(id, error) {N // If shortest stream was already stopped then we are in truncate mode@ // which means we ignore all the following stream stops." if (isStopped) return nullL // If stream being stopped is the first one to be stopped or if it'sK // shorter then the shortest one stopped, we update stop reason and- // shortest stopped stream reference.@ if (!shortest || shortest.length > buffers[id].length) { shortest = buffers[id] reason = error }P // If shortest stream has no buffered elements, we stop resulting stream // & do some clean up. if (!shortest.length) {' // Marking stream as stopped. isStopped = true // Stopping a stream. stop(reason)K // Setting all closure captured elements to `null` so that gc can // collect them.# buffers = shortest = null } } // Initializing buffers. id = sources.length( while (0 <= --id) buffers.push([]) // Start reading streams. id = sources.length while (0 <= --id)D sources[id](onElement.bind(null, id), onStop.bind(null, id)) } }})()exports.zip = zip/**K * Returns stream containing first `n` elements of given `source`, on which * given lambda returns `true`. * * @param {Function} lambda# * function that takes elements. * @param {Function} source* * source stream to take elements from. * @examples* * var numbers = list(10, 23, 2, 7, 17)) * var digits = take(function(value) { * return value >= 10 * }, numbers) * digits(console.log) * // 10 * // 23 */function take(lambda, source) {& return function stream(next, stop) {( source(function onElement(element) {> return lambda(element) ? next(element) : stop() && false }, stop) }}exports.take = take/**M * Returns a stream consisting of the given `source` stream elements startingL * form the `start` zero-based index till `end` zero-based index element. If5 * `end` is not passed all elements will be included. */$function slice(source, start, end) {3 // Zero-based index at which to begin extraction. start = start || 00 // Zero-based index at which to end extraction end = end || Infinity& return function stream(next, stop) { var index = -1, interrupt( source(function onElement(element) {D // Skip elements until we reach start of the extraction range.& if (++index < start) return trueA // If index is in range we want to extract from then yield.0 if (index < end) interrupt = next(element)E // If this is last element we stop stream and interrupt reading; return index + 1 >= end ? (stop(), false) : interrupt }, stop = limit(stop)) }}exports.slice = slice/**K * Returns a stream containing only first `number` of elements of the givenM * `source` stream or all elements, if `source` stream has less than `number`= * of elements. If `number` is not passed it defaults to `1`. * @param {Function} source * source stream * @param {Number} number=1, * number of elements to take from stream */function head(source, number) {= return slice(source, 0, number && number >= 0 ? number : 1)}exports.head = head/**N * Returns a stream equivalent to given `source` stream, except that the firstN * `number` of elements are omitted. If `source` stream has less than `number`O * of elements, then empty stream is returned. `number` defaults to `1` if it's * not passed. * @param {Function} source& * source stream to return tail of. * @param {Number} number=1. * Number of elements that will be omitted. */function tail(source, number) {: return slice(source, number && number >= 0 ? number : 1)}exports.tail = tail/**O * Returns a stream that contains all elements of each stream in the order theyL * appear in the original streams. If any of the `source` streams is stoppedM * with an error than it propagates to the resulting stream and it also get's * stopped. * @examples5 * var stream = append(list(1, 2), list('a', 'b')) * stream(console.log) * // 1 * // 2 * // 'a' * // 'b' */function append() {8 var streams = Array.prototype.slice.call(arguments, 0)& return function stream(next, stop) {* var source, sources = streams.slice(0) function onStop(error) {+ if (error) return stop && stop(error): if ((source = sources.shift())) source(next, onStop) else return stop && stop() } onStop() }}exports.append = append/**J * Returns a stream that contains all elements of each stream of the givenP * source stream. `source` is stream of streams whose elements will be containedK * by the resulting stream. Any error from any stream will propagate to theP * resulting stream. Stream is stopped when all streams from `source` and sourceI * itself is ended. Elements of the stream are position in order they areL * delivered so it could happen that elements from second stream will appear2 * before or between elements of the first stream. * @param {Function} sourceL * Stream of streams whose elements will be contained by resulting stream * @examples" * function async(next, stop) { * setTimeout(function() { * next('async') * stop() * }, 10) * }4 * var stream = merge(list(async, list(1, 2, 3))) * stream(console.log) * // 1 * // 2 * // 3 * // 'async' */function merge(source) {& return function stream(next, stop) { var open = 1, alive function onStop(error) {0 if (!open || false === alive) return false if (error) open = 0 else open -- if (!open) stop(error) }& source(function onStream(stream) { open ++% stream(function onNext(value) {D return open && false !== alive ? alive = next(value) : false }, onStop) }, onStop) }}exports.merge = merge/**% * Utility function to print streams. * @param {Function} stream * stream to print * @examples# * print(list('Hello', 'world')) */function print(stream) { console.log('>>')< stream(console.log.bind(console), function onStop(error) {# if (error) console.error(error) else console.log('<<') })}exports.print = print/**H * Returns a stream equivalent to a given `source`, with difference thatK * all the consumers will start reading it from the point it's at the givenM * moment. This is useful with streams such as user generated events (clicks,M * keypress, etc..) where multiple stream readers might need to read from the, * same source. In other words, this is yourK * [pub / sub](http://en.wikipedia.org/wiki/Publish/subscribe) for streams. * @param {Function} source; * Stream whose elements get published to a subscribers. * @return {Function}5 * Stream that multiple subscribers can read from. * @examples" * function range(start, end) {, * return function stream(next, stop) { * var number = start - 1( * setTimeout(function onNext() { * if (++number >= end) * return stop()' * if (false !== next(number))# * setTimeout(onNext, 2) * }, 2) * } * } * function printer(index) {' * return function print(stream) {> * stream(console.log.bind(console, '#' + index + '>'),9 * console.log.bind(console, '<#' + index)) * } * } * var numbers = range(1, 5) * printer(1)(numbers)8 * setTimeout(function () { printer(2)(numbers) }, 5) *. * // Output will look something like this: * #1> 1 * #1> 2 * #1> 3 * #2> 1 * #1> 4 * #2> 2 * <#1 * #2> 3 * #2> 4 * <#2 *L * // If you noticed second print started form the first `1` element. Now* * // lets do similar thing with a hub. *$ * var numbers = hub(range(1, 5)) * printer(1)(numbers)8 * setTimeout(function () { printer(2)(numbers) }, 5) */ * // In this case output will be different: * * #1> 1 * #1> 2 * #1> 3 * #1> 4 * #2> 4 * <#1 * <#2 *L * // Notice this time second print only printed only following elements. */function hub(source) {/ var listeners = [], isStopped = false, reason# source(function onNext(element) { var index = 0E // Maybe it'd be better to just iterate on sliced array instead ?& while (index < listeners.length) {3 if (listeners[index++][0](element) === false)$ listeners.splice(--index, 1) } }, function onStop(error) { isStopped = true reason = error var listener, stop- while ((listener = listeners.shift())) {, if ((stop = listener[1])) stop(reason) } })& return function stream(next, stop) {: // If stream is already stopped, we notify a listener.' if (isStopped && stop) stop(reason)! // Else we register listener.' else listeners.push([ next, stop ]) }}exports.hub = hub/**O * Returns a stream equivalent to a given `source` by caching all it's elementsN * into memory for faster reads. This is useful with `source` streams that areL * expensive to compute (requires access to the network for example). Use itD * carefully though, do not cache infinite streams and be aware thatB * asynchronous stream when cached will yield some or all elementsL * synchronously. Also be aware, that unlike other functions, this is greedyF * which means that it will start reading `source` stream immediately. * @param {Function} source * source stream to cache. * @returns {Function}B * cached equivalent of source that can be read multiple times. */function cache(source) { var buffer = []@ // Creating a stream that streams element of the buffer array. function cached(next, stop) { var index = 0! while (index < buffer.length)7 if (false === next(buffer[index++])) return false stop() }9 return append(cached, hub(function stream(next, stop) {( source(function onElement(element) { buffer.push(element) return next(element) }, stop) }));}exports.cache = cache/**N * Returns stream equivalent to a given `source` with a difference that it hasL * a state, meaning that if reader stops reading on n-th element next readerM * will continue reading from n-th element. Purpose is to wrap any other typeL * of stream, such that each element of `source` can be read only once. ThisO * allow element distribution across different consumers with a help of `head`, * `tail` and similars. * @param {Function} source0 * source stream to create stack stream from. * @returns {Function}< * stack equivalent of source that can be read only once. */function stack(source) {M var readers = [], buffer = [], isStopped = false, isStarted = false, reason function update() {5 if (!buffer.length || !readers.length) return nil. var resume = readers[0][0](buffer.shift())) if (false === resume) readers.shift() update() } function onNext(element) { update(buffer.push(element)) } function onStop(error) { isStopped = true reason = error var reader = readers.shift()F return reader ? onStop(error, reader[1] && reader[1](error)) : nil }& return function stream(next, stop) {: // If stream is already stopped, we notify a listener.@ if (isStopped && !buffer.length) return stop && stop(reason) readers.push([ next, stop ]) update()B // If `source` stream is not yet being read, start reading it. if (isStarted) return nil isStarted = true source(onNext, onStop) }}exports.stack = stack/**J * Returns a stream that contains all elements of each stream of the givenP * source stream. `source` is stream of streams whose elements will be containedK * by the resulting stream. Any error from any stream will propagate to theP * resulting stream. Stream is stopped when all streams from `source` and sourceO * itself are ended. Elements of the stream are position in order, all elements6 * of first stream, all elements of second stream etc. * @param {Function} sourceL * Stream of streams whose elements will be contained by resulting stream * @examples" * function async(next, stop) { * setTimeout(function() { * next('async') * stop() * }, 10) * }3 * var stream = join(list(async, list(1, 2, 3))) * stream(console.log) * // 'async' * // 1 * // 2 * // 3 */function join(source) {& return function stream(next, stop) {H var streams = stack(source), open = 0, alive = true, stopped = false stop = limit(stop) !function recur(error) { console.log('@')/ head(streams)(function onStream(stream) { console.log(stream) open += 2 console.log(' >')+ console.log(' + ', stream.name), stream(function onElement(element) {* console.log(' |- ', element)J // If steam is still open and read is not interrupted we deliverB // element to the reader, otherwise we interrupt source.6 return !stopped && open && false !== alive ?. alive = next(element) : false$ }, function onStop(error) { open --+ console.log(' - ', stream.name) if (error) stop(error)! else if (!open) recur() })! }, function onStop(error) { open -- console.log(' <') if (error) stop(error) if (open === 0) recur()$ else if (open === -1) stop() }) console.log('#') }() }}exports.join = join});5_132q^^,v,NRY2qsx qsw5_243r^^,v,NRY6qsx console.log()5_354r^^,v,NRY6qsx console.log('')5_465r^^,v,NRY8qsx console.log('>')5_576[^^,v,NRYP[]y []x5_687\__,v,NRYS[]y console.log()5_798V__,v,NRYVXz VXy5_8:9W ``,v,NRYVXz var index5_9;:\ ``,v,NRY[]z/ head(streams)(function onStream(stream) {5_:<;\``,v,NRY[]z0 slice(streams)(function onStream(stream) {5_;=<\``,v,NRY[]z: slice(streams, index, 1)(function onStream(stream) {5_<>=W``,v,NRYVXz var index = -15_=?>V``,v,NRYUWzH var streams = stack(source), open = 0, alive = true, stopped = false5_>A?V``,v,NRYUWzB var streams = source), open = 0, alive = true, stopped = false5_?B@A\``,v,NRZ[]z< slice(streams, index++, 1)(function onStream(stream) {5_ACB\``,v,NRZ[]z: slice(streams, index, 1)(function onStream(stream) {5_BDCo``,v,NR[no console.log(' <')5_CEDs``,v,NR[rs console.log('#')5_DFE_``,v,NR[^_ console.log(' >')5_EGF___,v,NR[^_+ console.log(' + ', stream.name)5_FHG[__,v,NR[Z[ console.log('@')5_GIH\^^,v,NR[[\ console.log(stream)5_HJI^]],v,NR[]^* console.log(' |- ', element)5_IKJd ]],v,NR[cd+ console.log(' - ', stream.name)5_JLKV!]],v,NR\"UWrA var streams = source, open = 0, alive = true, stopped = false5_KMLe]],v,NR\(dfr! else if (!open) recur()5_LNMj]],v,NR\-ij if (open === 0) recur()5_MONj ]],v,NR\/ikq$ else if (open === -1) stop()5_NPOj]],v,NR\2ikq if (open === -1) stop()5_OQPj]],v,NR\5ikq$ else if (open === -1) stop()5_PRQj]],v,NR\7ikq% else if (!open === -1) stop()5_QSRd]],v,NR\;dfr dfq5_RTSe]],v,NR\>dfr if ()5_SUTe ]],v,NR\Adfr if (!open)5_TVUe]],v,NR\Bdfr else if (!open)5_UWVY]],v,NR\LY[s Y[r5_VXWZ^^,v,NR\cY[s function onStop()5_WYXZ^^,v,NR\cY\s function onStop() {}5_XZYkkmvNR\jjlt open -- if (error) stop(error) else if (!open) stop()5_Y[ZZkk%vNR\kZ^s Z\r5_Z\[\nn%vNR\m[]u if (error) stop(error)5_[]\]nn%vNR\o\^u else if (!open) stop()5_\^]m m ovNR\lnu! }, function onStop(error) {  })5_]_^m m mvNR\lns }, )5_^`_h m mvNR\gh open --5__a`h l lvNR\gh if (error) stop(error)5_`bah k kvNR\gh else if (!open) stop()5_acbg$j jvNR\fhp$ }, function onStop(error) {5_bdcgj jvNR\fhp }, function stopped()5_cedg j jvNR\fip! }, function stopped() {}5_dfehk kvNR\gh }5_egfgj jvNR\fhp }, function stopped() {5_fhghj jvNR\gip else recur()5_gihg j jvNR\giq gip5_hjihk kvNR\giq onStop()5_ikjhk kvNR\giq onStop(exports)5_jlkZk kvNR\Y[q function onStop() {5_kmlh k kvNR\fhq% }, function stopped(error) { onStop(error)giq onStop(error)5_lnmg3j jvNR\fhp3 }, function stopped(error) { onStop(error)5_monh j jvNR\fhp5 }, function stopped(error) { onStop(error), recur()gip recur()5_npohi ivNR\fho< }, function stopped(error) { onStop(error), recur()})gio })5_oqp_h hvNR\_ao _an5_prq`i ivNR\_ao onStream()5_qsr`i ivNR\_ao onStop())5_rts`i ivNR\_ao onStop()i5_sut` i ivNR\_ao onStop()5_tvuh h h=v=NR\gio? }, function stopped(error) { onStop(error), recur() })5_uwvh h h=v=NR\gio }, )5_vywh h h=v=NR]gio }, recur)5_wzxyV!h h=v=NR]UWoA var streams = source, open = 1, alive = true, stopped = false5_y{z\h h=v=NR]E\^o5_z|{]i i=v=NR]F[]p if (error) stop(error)\^p5_{|\h h=v=NR]L[]o if (error) stop(error)5_|}WV2V8v8NR]UWoA var streams = source, open = 2, alive = true, stopped = false index = 0VXo var index = 05_XV2V8v8NR]WX stop = limit(stop)5_ZV2V8v8NR]Y[m* if (error) open = false, stop(error)5_ZV2V8v8NR]Y[m* if (error) open = false, stop(error)5_ZV2V8v8NR]Y[m* if (error) open = false, stop(error)5_Z*V2V8v8NR]Y[m6 if (error && !stopped) open = false, stop(error)5_[V2V8v8NR]Z\m else if (!open) stop()5_["V2V8v8NR]Z\m( else if (!open && !stopped) stop()5_Z:V2V8v8NR]Y[mG if (error && !stopped) open = false, stopped = error, stop(error)5_eV2V8v8NR^cem6 return !stopped && open && false !== alive ?alive = next(element) : falsedfm. alive = next(element) : false5_d7V2V8v8NR^cflT return !stopped && open && false !== alive ? alive = next(element) : false5_e V2V8v8NR^dfm' alive = next(element) : false5_bJV2V8v8NR^RacmJ // If steam is still open and read is not interrupted we deliver5_cV2V8v8NR^WbdmB // element to the reader, otherwise we interrupt source.5_c#V2V8v8NR^]bdmC // elements to the reader, otherwise we interrupt source.5_c#V2V8v8NR^^bdm# // elements to the reader5_c#V2V8v8NR^`cem5_d V2V8v8NR^acd //5_c$V2V8v8NR^dbdm$ // elements to the reader.5_`V2V8v8NR^z_am open += 25_`V2V8v8NR^_am open += 2 // Increment 5_`MV2V8v8NR^_amM open += 2 // Increment number of open steams (2 cause each is closed 5_`5V2V8v8NR^_bmR open += 2 // Increment number of open steams (2 cause each is closed twice5__V2V8v8NR^_ao _an5_aaa3v3NR^`bo4 open += 2 // Increment number of open steams5_` aa3v3NR^_ao // 5_`aa3v3NR^_ao- // // Increment number of open steams5_bbb$v$NR^aco% (2 cause each is closed twice5_bbb$v$NR^ab 5_`*bb$v$NR^_an* // Increment number of open steams5_`,bb$v$NR^_anH // Increment number of open steams (2 cause each is closed twice5_`/bb$v$NR^_anJ // Increment number of open steams by 2 cause each is closed twice5_`0bb$v$NR^_anK // Increment number of open steams by 2, cause each is closed twice5_`+bb$v$NR^_anJ // Increment number of open steams by 2 cause each is closed twice5_`:bb$v$NR^_anN // Increment number of open steams (twice 2 cause each is closed twice5_`Lbb$v$NR^_anL // Increment number of open steams (twice since each is closed twice5_`;bb$v$NR^_aE // Increment number of open steams (twice since we decriment 5_`Ebb$v$NR^_bnE // Increment number of open steams (twice since we decrement 5_$ $vNReo5_M% %vNRe pM var readers = [], buffer = [], isStopped = false, isStarted = false, reason5_& &vNReq updating5_& &vNReq5_& &vNRe if5_% %vNRep5 if (!buffer.length || !readers.length) return nil5_! % %vNRe- "p update()5_% %vNRe7p updating = true5_% %vNRe; q  p5_& &vNReAq updating = true5_a" "vNRh`bq@ slice(streams, index, ++index)(function onStream(stream) {5_a a avNRh`bqE head(slice(streams, index, ++index)(function onStream(stream) {5_aa avNRh`bq? head(streams, index, ++index)(function onStream(stream) {5_Xa avNRhWYqL var streams = source, open = 2, alive = true, stopped = false, index = 05_Xa avNRhWYqR var streams = stack(source, open = 2, alive = true, stopped = false, index = 05_XSa avNRhWYqS var streams = stack(source), open = 2, alive = true, stopped = false, index = 05_XGa avNRhWYqH var streams = stack(source), open = 2, alive = true, stopped = false5_da avNRqhce open += 2 5_a avNRt q return index <= end ?5_a avNRt q return 8next(element), index === end ? (stop(), false) : true) :qF (next(element), index === end ? (stop(), false) : true) :5_$` `vNRt!pE return next(element), index === end ? (stop(), false) : true) :5_D` `vNRt.pD return next(element), index <= end ? (stop(), false) : true) :5_ ` `vNRt/ (stop(), false)5_#_ _vNRtoA return next(element), index <= end ? (stop(), false) : true5_a avNRsq return next()5_a avNRsq 5_a avNRi=q5 if (!buffer.length || !readers.length) return nil5_"a avNRi@!#q update()5_" " "vNRh!#q update()5_! % %vNRh!"q !#rH assert.deepEqual(buffer, [ 1, 2, 3 ], 'all elements were yielded')\ assert.deepEqual(stops, [ undefined, undefined, undefined, undefined ], 'stopped 3 times')5_! % %vNRe# "p update(up)5_gcc$v$NR^gho5_|~}VAV2V8v8NR]kUWo0 var streams = source, open = 2, alive = true5_}~WV2V8v8NR]oVXo index = 0UXo; var streams = source, open = 2, alive = true, index = 05_wyxWg g=v=NR]VX5_?A@\``,v,NRY[]zD slice(streams, index++, index + 1)(function onStream(stream) {5_"$# \\,v,NRVcw9(next(element), index === end ? (stop(), false) : true) :wU return index <= end ? (next(element), index === end ? (stop(), false) : true) :5_\\,v,NRUv# if (index end) next(element)5_\\,v,NRTuu v index >= end ? ()5_\\,v,NRTv index >= end ? (stop())5_\\,v,NRTv$ index >= end ? (stop(), false)5_$\\,v,NRTv- index >= end ? (stop(), false) : next()5_,\\,v,NRTv4 index >= end ? (stop(), false) : next(element)5_\\,v,NRTv; return index >= end ? (stop(), false) : next(element)5_ [[,v,NRT5_  )v)NRTu: return index < end ? (stop(), false) : next(element)5_   )v)NRTu+ return index < end ? : next(element)5_   )v)NRTu* return index < end ? ; next(element)5_   )v)NRTu* return index < end ? : next(element)5_  *)v)NRTu+ return index < end ? : next(element) 5_ )v)NRTu) return index < end ? next(element) 5_))v)NRTu: return index < end ? next(element) : (stop(), false)5_ [[,v,NRTu< return index === end ? (stop(), false) : next(element)5_\\,v,NRQu v next()5_ \\,v,NRQv next(element)5_\\,v,NRQv/ if (index === end ? (stop(), false) : nil5_\\,v,NRQv0 if (index === end) ? (stop(), false) : nil5_]],v,NRQv if (index === end) { stop(), false) : nil5_]],v,NRQw stop() false) : nil5_^^,v,NRQw stop() return false) : nil5___,v,NRQx return false }) : nil5_yVNRQy }5_i%yVNRRGhjy+ console.log(' - ', strict.name)5_i%yVNRRHhjy+ console.log(' - ', stream.name)5_yVNRSy if (index => end) {5_yVNRSy if (index > end) {5_yVNRSy if (index >= end) {5_yVNRT"y$ var index = 0, interrupt = false5_yVNRT+y& var index = 0, interrupted = false5_yVNRT7y& return interrupted next(element)5_yVNRT?y) return interrupted || next(element)5_VNRT2y return next(element)yy'/* vim:set ts=2 sw=2 sts=2 expandtab */?/*jshint asi: true undef: true es5: true node: true devel: true' forin: false latedef: false *//*global define: true */!(typeof(define) !== "function" ? function($){ $(typeof(require) !== 'function' ? (function() { throw Error('require unsupported'); }) : require, typeof(exports) === 'undefined' ? this : exports); } : define)(function(require, exports) { 'use strict';"var nil // Shortcut for undefined./**H * Internal utility function that takes a `source` function and optionalG * `number` arguments and returns a function that calls `source` with aG * given arguments only first `number` of times it's called. Useful for@ * wrapping callbacks that must be called only ones for example. */ function limit(source, number) { number = number || 1 return function limited() {G return number-- > 0 && source ? source.apply(this, arguments) : nil }}function normalize(source) {& return function stream(next, stop) {' var stopped = false, reading = true( source(function onElement(element) {( if (!stopped && false !== reading)( return (reading = next(element)) }, function onStop(reason) {; return stopped ? nil : (stopped = true, stop(reason)) }) }}/**K * Utility function that returns streams of elements of given `array`. ThisI * function is dangerous as array mutations will have side effects on theJ * returned stream so it should be used with a care, reader of such streamL * **MUST NOT** mutate source array, this is also reason why we don't export * this function. */ function streamArray(elements) {& return function stream(next, stop) { var index = 0# while (index < elements.length)< // If stream reader interrupts reading we just return.9 if (false === next(elements[index++])) return falseK // Once all elements were yielded we stop a stream if such callback was // passed. if (stop) stop() }}/**$ * Creates stream of given elements. * @examples# * list('a', 2, {})(console.log) */function list() {; return streamArray(Array.prototype.slice.call(arguments))}exports.list = list/*8 * Creates empty stream. This is equivalent of `list()`. */function empty() {> return function stream(next, stop) { return stop && stop() }}exports.empty = empty/**# * Returns stream of mapped values. * @param {Function} lambda# * function that maps each value * @param {Function} input * source stream to be mapped * @examples: * var stream = list({ name: 'foo' }, { name: 'bar' })D * var names = map(function(value) { return value.name }, stream) * names(console.log) * // 'foo' * // 'bar'! * var numbers = list(1, 2, 3)N * var mapped = map(function onEach(number) { return number * 2 }, numbers) * mapped(console.log) * // 2 * // 4 * // 6 */function map(lambda, source) {& return function stream(next, stop) {( source(function onElement(element) {" return next(lambda(element)) }, stop) }}exports.map = map/**% * Returns stream of filtered values. * @param {Function} lambda" * function that filters values * @param {Function} source" * source stream to be filtered * @examples* * var numbers = list(10, 23, 2, 7, 17)+ * var digits = filter(function(value) {' * return value >= 0 && value <= 9 * }, numbers) * digits(console.log) * // 2 * // 7 */!function filter(lambda, source) {& return function stream(next, stop) {( source(function onElement(element) {3 return lambda(element) ? next(element) : true }, stop) }}exports.filter = filter/**# * Returns stream of reduced values * @param {Function} source * stream to reduce. * @param {Function} reducer * reducer function * @param initial * initial value * @examples! * var numbers = list(2, 3, 8)> * var sum = reduce(function onElement(previous, current) {( * return (previous || 0) + current * }, numbers) * sum(console.log) * // 13 */+function reduce(reducer, source, initial) {& return function stream(next, stop) { var value = initial( source(function onElement(element) {% value = reducer(value, element) }, function onStop(error) {# if (error) return stop(error) next(value) if (stop) stop() }) }}exports.reduce = reduce/**L * This function returns stream of tuples, where the n-th tuple contains theI * n-th element from each of the argument streams. The returned stream isE * truncated in length to the length of the shortest argument stream. * @params {Function}" * source steams to be combined * @examples% * var a = list([ 'a', 'b', 'c' ])" * var b = list([ 1, 2, 3, 4 ])/ * var c = list([ '!', '@', '#', '$', '%' ]) * var abc = zip(a, b, c) * abs(console.log) * // [ 'a', 1, '!' ] * // [ 'b', 2, '@' ] * // [ 'c', 3, '#' ] */var zip = (function Zip() {+ // Returns weather array is empty or not.2 function isEmpty(array) { return !array.length }G // Utility function that check if each array in given array of arraysA // has at least one element (in which case we do have a tuple).: function hasTuple(array) { return !array.some(isEmpty) }F // Utility function that creates tuple by shifting element from each // array of arrays. function shiftTuple(array) {( var index = array.length, tuple = []< while (0 <= --index) tuple.unshift(array[index].shift()) return tuple } return function zip() {7 var sources = Array.prototype.slice.call(arguments)( return function stream(next, stop) {? var buffers = [], id, reason, isStopped = false, shortest' function onElement(id, element) {N // If resulting stream is already stopped (we are in truncate mode) orP // if this stream is stopped (we deal with badly implemented stream that> // yields value after it's stopped) we ignore element." if (isStopped) return null* // Otherwise we buffer an element.! buffers[id].push(element)) // If tuple is ready we yield it.C return hasTuple(buffers) ? next(shiftTuple(buffers)) : true }" function onStop(id, error) {N // If shortest stream was already stopped then we are in truncate mode@ // which means we ignore all the following stream stops." if (isStopped) return nullL // If stream being stopped is the first one to be stopped or if it'sK // shorter then the shortest one stopped, we update stop reason and- // shortest stopped stream reference.@ if (!shortest || shortest.length > buffers[id].length) { shortest = buffers[id] reason = error }P // If shortest stream has no buffered elements, we stop resulting stream // & do some clean up. if (!shortest.length) {' // Marking stream as stopped. isStopped = true // Stopping a stream. stop(reason)K // Setting all closure captured elements to `null` so that gc can // collect them.# buffers = shortest = null } } // Initializing buffers. id = sources.length( while (0 <= --id) buffers.push([]) // Start reading streams. id = sources.length while (0 <= --id)D sources[id](onElement.bind(null, id), onStop.bind(null, id)) } }})()exports.zip = zip/**K * Returns stream containing first `n` elements of given `source`, on which * given lambda returns `true`. * * @param {Function} lambda# * function that takes elements. * @param {Function} source* * source stream to take elements from. * @examples* * var numbers = list(10, 23, 2, 7, 17)) * var digits = take(function(value) { * return value >= 10 * }, numbers) * digits(console.log) * // 10 * // 23 */function take(lambda, source) {& return function stream(next, stop) {( source(function onElement(element) {> return lambda(element) ? next(element) : stop() && false }, stop = limit(stop)) }}exports.take = take/**M * Returns a stream consisting of the given `source` stream elements startingL * form the `start` zero-based index till `end` zero-based index element. If5 * `end` is not passed all elements will be included. */$function slice(source, start, end) {3 // Zero-based index at which to begin extraction. start = start || 00 // Zero-based index at which to end extraction end = end || Infinity& return function stream(next, stop) { var index = 0 filter(function(element) { return start <= index ++, }, source)(function onElement(element) { next(element) if (index === end) { stop() return false } }, stop = limit(stop)) }}exports.slice = slice/**K * Returns a stream containing only first `number` of elements of the givenM * `source` stream or all elements, if `source` stream has less than `number`= * of elements. If `number` is not passed it defaults to `1`. * @param {Function} source * source stream * @param {Number} number=1, * number of elements to take from stream */function head(source, number) {= return slice(source, 0, number && number >= 0 ? number : 1)}exports.head = head/**N * Returns a stream equivalent to given `source` stream, except that the firstN * `number` of elements are omitted. If `source` stream has less than `number`O * of elements, then empty stream is returned. `number` defaults to `1` if it's * not passed. * @param {Function} source& * source stream to return tail of. * @param {Number} number=1. * Number of elements that will be omitted. */function tail(source, number) {: return slice(source, number && number >= 0 ? number : 1)}exports.tail = tail/**O * Returns a stream that contains all elements of each stream in the order theyL * appear in the original streams. If any of the `source` streams is stoppedM * with an error than it propagates to the resulting stream and it also get's * stopped. * @examples5 * var stream = append(list(1, 2), list('a', 'b')) * stream(console.log) * // 1 * // 2 * // 'a' * // 'b' */function append() {8 var streams = Array.prototype.slice.call(arguments, 0)& return function stream(next, stop) {* var source, sources = streams.slice(0) function onStop(error) {+ if (error) return stop && stop(error): if ((source = sources.shift())) source(next, onStop) else return stop && stop() } onStop() }}exports.append = append/**J * Returns a stream that contains all elements of each stream of the givenP * source stream. `source` is stream of streams whose elements will be containedK * by the resulting stream. Any error from any stream will propagate to theP * resulting stream. Stream is stopped when all streams from `source` and sourceI * itself is ended. Elements of the stream are position in order they areL * delivered so it could happen that elements from second stream will appear2 * before or between elements of the first stream. * @param {Function} sourceL * Stream of streams whose elements will be contained by resulting stream * @examples" * function async(next, stop) { * setTimeout(function() { * next('async') * stop() * }, 10) * }4 * var stream = merge(list(async, list(1, 2, 3))) * stream(console.log) * // 1 * // 2 * // 3 * // 'async' */function merge(source) {& return function stream(next, stop) { var open = 1, alive function onStop(error) {0 if (!open || false === alive) return false if (error) open = 0 else open -- if (!open) stop(error) }& source(function onStream(stream) { open ++% stream(function onNext(value) {D return open && false !== alive ? alive = next(value) : false }, onStop) }, onStop) }}exports.merge = merge/**% * Utility function to print streams. * @param {Function} stream * stream to print * @examples# * print(list('Hello', 'world')) */function print(stream) { console.log('>>')< stream(console.log.bind(console), function onStop(error) {# if (error) console.error(error) else console.log('<<') })}exports.print = print/**H * Returns a stream equivalent to a given `source`, with difference thatK * all the consumers will start reading it from the point it's at the givenM * moment. This is useful with streams such as user generated events (clicks,M * keypress, etc..) where multiple stream readers might need to read from the, * same source. In other words, this is yourK * [pub / sub](http://en.wikipedia.org/wiki/Publish/subscribe) for streams. * @param {Function} source; * Stream whose elements get published to a subscribers. * @return {Function}5 * Stream that multiple subscribers can read from. * @examples" * function range(start, end) {, * return function stream(next, stop) { * var number = start - 1( * setTimeout(function onNext() { * if (++number >= end) * return stop()' * if (false !== next(number))# * setTimeout(onNext, 2) * }, 2) * } * } * function printer(index) {' * return function print(stream) {> * stream(console.log.bind(console, '#' + index + '>'),9 * console.log.bind(console, '<#' + index)) * } * } * var numbers = range(1, 5) * printer(1)(numbers)8 * setTimeout(function () { printer(2)(numbers) }, 5) *. * // Output will look something like this: * #1> 1 * #1> 2 * #1> 3 * #2> 1 * #1> 4 * #2> 2 * <#1 * #2> 3 * #2> 4 * <#2 *L * // If you noticed second print started form the first `1` element. Now* * // lets do similar thing with a hub. *$ * var numbers = hub(range(1, 5)) * printer(1)(numbers)8 * setTimeout(function () { printer(2)(numbers) }, 5) */ * // In this case output will be different: * * #1> 1 * #1> 2 * #1> 3 * #1> 4 * #2> 4 * <#1 * <#2 *L * // Notice this time second print only printed only following elements. */function hub(source) {/ var listeners = [], isStopped = false, reason# source(function onNext(element) { var index = 0E // Maybe it'd be better to just iterate on sliced array instead ?& while (index < listeners.length) {3 if (listeners[index++][0](element) === false)$ listeners.splice(--index, 1) } }, function onStop(error) { isStopped = true reason = error var listener, stop- while ((listener = listeners.shift())) {, if ((stop = listener[1])) stop(reason) } })& return function stream(next, stop) {: // If stream is already stopped, we notify a listener.' if (isStopped && stop) stop(reason)! // Else we register listener.' else listeners.push([ next, stop ]) }}exports.hub = hub/**O * Returns a stream equivalent to a given `source` by caching all it's elementsN * into memory for faster reads. This is useful with `source` streams that areL * expensive to compute (requires access to the network for example). Use itD * carefully though, do not cache infinite streams and be aware thatB * asynchronous stream when cached will yield some or all elementsL * synchronously. Also be aware, that unlike other functions, this is greedyF * which means that it will start reading `source` stream immediately. * @param {Function} source * source stream to cache. * @returns {Function}B * cached equivalent of source that can be read multiple times. */function cache(source) { var buffer = []@ // Creating a stream that streams element of the buffer array. function cached(next, stop) { var index = 0! while (index < buffer.length)7 if (false === next(buffer[index++])) return false stop() }9 return append(cached, hub(function stream(next, stop) {( source(function onElement(element) { buffer.push(element) return next(element) }, stop) }));}exports.cache = cache/**N * Returns stream equivalent to a given `source` with a difference that it hasL * a state, meaning that if reader stops reading on n-th element next readerM * will continue reading from n-th element. Purpose is to wrap any other typeL * of stream, such that each element of `source` can be read only once. ThisO * allow element distribution across different consumers with a help of `head`, * `tail` and similars. * @param {Function} source0 * source stream to create stack stream from. * @returns {Function}< * stack equivalent of source that can be read only once. */function stack(source) {M var readers = [], buffer = [], isStopped = false, isStarted = false, reason function update() {5 if (!buffer.length || !readers.length) return nil. var resume = readers[0][0](buffer.shift())) if (false === resume) readers.shift() update() } function onNext(element) { update(buffer.push(element)) } function onStop(error) { isStopped = true reason = error var reader = readers.shift()F return reader ? onStop(error, reader[1] && reader[1](error)) : nil }& return function stream(next, stop) {: // If stream is already stopped, we notify a listener.@ if (isStopped && !buffer.length) return stop && stop(reason) readers.push([ next, stop ]) update()B // If `source` stream is not yet being read, start reading it. if (isStarted) return nil isStarted = true source(onNext, onStop) }}exports.stack = stack/**J * Returns a stream that contains all elements of each stream of the givenP * source stream. `source` is stream of streams whose elements will be containedK * by the resulting stream. Any error from any stream will propagate to theP * resulting stream. Stream is stopped when all streams from `source` and sourceO * itself are ended. Elements of the stream are position in order, all elements6 * of first stream, all elements of second stream etc. * @param {Function} sourceL * Stream of streams whose elements will be contained by resulting stream * @examples" * function async(next, stop) { * setTimeout(function() { * next('async') * stop() * }, 10) * }3 * var stream = join(list(async, list(1, 2, 3))) * stream(console.log) * // 'async' * // 1 * // 2 * // 3 */function join(source) {& return function stream(next, stop) {H var streams = stack(source), open = 0, alive = true, stopped = false stop = limit(stop) !function recur(error) {/ head(streams)(function onStream(stream) { console.log('!!!!!!') open += 2 console.log(' >')+ console.log(' + ', stream.name), stream(function onElement(element) {* console.log(' |- ', element)J // If steam is still open and read is not interrupted we deliverB // element to the reader, otherwise we interrupt source.6 return !stopped && open && false !== alive ?. alive = next(element) : false$ }, function onStop(error) { open --+ console.log(' - ', stream.name) if (error) stop(error)! else if (!open) recur() })! }, function onStop(error) { open -- console.log('') if (error) stop(error) if (open === 0) recur()$ else if (open === -1) stop() }) }() }}exports.join = join});5_k[[,v,NRKzjlu console.log(' <')5_e%uVNRKdfu+ console.log(' - ', stream.name)5_-'[[,v,NRL,.uK // If stream is already stopped, and buffer is empty notify a listener.5_-K[[,v,NRL},.uJ // If stream is already stopped, and buffer is empty we stop a reader.5_/\\,v,NRL'.0u  // 5_/\\,v,NRL*.0v5_0\\,v,NRL+/1v // otherwise wi 5_0\\,v,NRL0/1v // Otherwise wi 5_0\\,v,NRL1~/1v" // Otherwise we save a reader.5_5\\,v,NRLX46v if (!isStarted) return nil5_5\\,v,NRLY46v if (!isStarted) {}5_578vNRLZ46v if (!isStarted) { }5_777vNRL_69w 5_777vNRL`685_599vNRL`56u 57v isStarted = true source(onNext, onStop)5_7" "vNRLb68w source(onNext, onStop)5_" " "vNRL!#w update()5_! # #vNRL!"w !#x buffer.push(element)5_,$ $vNRMx y reader5_ % %vNRMy z var reason5_% %vNRMz var reader = readers.shift()5_$ $vNRM5_( # #vNRM()x (*y if ()5_)# #vNRM(*y if (readers.length)5_)# #vNRM(*y if (readers.length) {}5_)# #vNRM(*y if (readers.length) { }5_)# #vNRL)*x5_599vNRLt46w return if (!isStarted) {5_T \\,v,NRJ TUt TVu var task5_X ]],v,NRJ)XYu XZv task = head()5_Y]],v,NRJ0XZv task = head(streams)5_Z]],v,NRJ8Y[v& task(function onStream(stream) {5_XZZ0v0NRF|WYq< var stream = head(streams)(function onStream(stream) {5_e ZZ0v0NREdf5__5ZZ0v0NREv^`r4 return !stopped && open && false !== alive/ ? alive = next(element) : false5_bZZ0v0NRCacr6 console.log(' < close', stream.name, open)5_xzyQ\\0v0NRCQRrQSsopen  5_   vNPv!(typeof(define) === "undefined" ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error('require unsupported') } : require , typeof(exports) === 'undefined' ? this : export); } : define)(function(require, exports) {5_  vNPv!(typeof(define) === "undefined' ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error('require unsupported') } : require , typeof(exports) === 'undefined' ? this : export); } : define)(function(require, exports) {5_ vNPv!(typeof(define) === 'undefined' ? function($){ $(typeof(require) === 'undefined' ? function() { throw Error('require unsupported') } : require , typeof(exports) === 'undefined' ? this : export); } : define)(function(require, exports) {5__vNP^`q/ head(streams)(function jnStream(stream) {5_pvNPK oqq var open = 0, alive5_tvNPKsu5_uvNPKuvp uwq else open--5_qvNPKqrq qsr console.log()5_rvNPKqsr console.log('')5_rvNPKqsr console.log('>>')5_rvNPKqsr console.log('!!')5_rvNPKqsr console.log('!!', open)5_svNPLMrtr' if (false === alive) return false5_tvNPKsu5_uvNPK uvp uwq else open --5_vNPJFq var index = 0, tail = 5_vNPJOq 5_vNPJPq5 var index = 0, tail = filter(function(element) { 5_vNPJTq 5_5vNPJVqQ var index = 0, tail = filter(function(element) { return start <= index ++ }, 5_vNPJ_q var index = 0, tailB tail = filter(function(element) { return start <= index ++ }, 5_BvNPJbrI tail = filter(function(element) { return start <= index ++ }, source)5_vNPJe5_vNPJg5_vNPJkp& tail(function onElement(element) {5_vNPJp q stop = limit()5_vNPJq stop = limit(stop)5_vNPJq }, stop)5_vNPJp var index = 0, tail, stop5_X[YZ*vNPGq8 return next(element), index === end ? stop() : nil5_Z\[vNPHXq(function take(lambda, source, include) {5_[]\.vNPHfqG return lambda(element) ? next(element) : include stop() && false5_\^]/vNPHyq. return lambda(element) ? next(element) :% include stop() && false5_]_^vNPH|r. include ? next() stop() && false5_^`_vNPHr6 include ? next(elements) stop() && false5__a`$vNPHr5 include ? next(element) stop() && false5_`ba$vNPHr8 include ? next(element) && stop() && false5_acb)vNPHr3 include ? next(element)stop() && false5_bdc$vNPHr4 include ? next(element) stop() && false5_cedvNPHr5 include ? (next(element) stop() && false5_dfe%vNPHr6 include ? (next(element), stop() && false5_egf-vNPHr7 include ? (next(element), stop(), && false5_fhg2vNPHr4 include ? (next(element), stop(), false5_gih4vNPHr5 include ? (next(element), stop(), false)5_hji vNPHr6 (include ? (next(element), stop(), false)5_ikjvNPHr5 (include ? next(element), stop(), false)5_jlk%vNPHr; (include ? next(element) : nil, stop(), false)5_kml vNPHr.(include ? next(element) : nil, stop(), false)r\ return lambda(element) ? next(element) :(include ? next(element) : nil, stop(), false)5_lnm-vNPHq, return lambda(element) ? next(element)L :(include ? next(element) : nil, stop(), false)5_monvNPHrM : (include ? next(element) : nil, stop(), false)5_npovNPIr take(function() {! }, filter(function(element) {5_oqpvNPIs }, )5_prqvNPIs }, true)5_qsrvNPI!s3 }, source), true)(function onElement(element) {5_rtsvNPI&s }, source), true)" (function onElement(element) {5_sutvNPI'5_tvuvNPI'5_uwvvNPI(5_vxwvNPI,qreturn start <= index ++q: }, filter(function(element) { return start <= index ++5_wyxvNPI.p}, source), true)pL }, filter(function(element) { return start <= index ++ }, source), true)5_xzyvNPI@o take(function(element) {5_y{zvNPICo p index < end5_z}{vNPIXp return index < end5_{~|}"vNPIp! }, filter(function(element) {0 return start <= index ++ }, source), true)5_}~vNPIq return start <= index ++ }, source), true)5_~vNPIr }, source), true)()5_vNPIr! }, source), true)(next, stop)5_vNPIr * s * @param {Boolean} include5_vNPIs * t) * if true will include first element 5_{}|GvNPIpF }, filter(function(element) { return start <= index ++ }, source), true)5_XZY vNPGq: return (next(element), index === stop ? stop() : nil5_57V6vNPEq r if ()5_6P7 vNPE r if (index === ended)5_7QOPvNPG7r if (index === end)5_PRQvNPG9r if (index === end) {}5_QSRvNPG:r if (index === end) { }5_RTSvNPG;s t stop()5_SUT vNPG>t u return false5_TUvNPGHu }, stop)5_78POvNPG2r if (index === ended) {}5_79O8vNPEr if (index === end)5_8:9vNPEr if (index === end) stop()5_9;:vNPFbr }, stop)5_:<;vNPFir& return if (index === end) stop()5_;=<vNPFor" return index === end) stop()5_<>=vNPFrr# return index === end ? stop()5_=?>vNPF{r$ return index === end ? (stop()5_>@?$vNPF|r2 return index === end ? (stop(), false) : nil5_?A@%vNPFr4 return index === end ? (stop() && false) : nil5_@BAvNPFr3 return index === end ? stop() && false) : nil5_ACB-vNPFr2 return index === end ? stop() && false : nil5_BDC&vNPFr2 return index === end ? stop() \\ false : nil5_CED&vNPFr2 return index === end ? stop() || false : nil5_DFE&vNPFr0 return index === end ? stop(), false : nil5_EGFvNPFr1 return index === end ? (stop(), false : nil5_FHG+vNPFr2 return index === end ? (stop(), false) : nil5_GIH vNPFr3 var val index === end ? (stop(), false) : nil5_HJI vNPFr5 var val = index === end ? (stop(), false) : nil5_IKJvNPFr s console.log()5_JLKvNPFs console.log(val)5_KMLvNPFs t return val5_LNMvNPFt u console.log()5_MNvNPFu console.log(index === end)5_*,3+ vNPDq+ index <= end ? stop() : next(element)5_+-,vNPDq% index <= end ? : next(element)5_,.-vNPDq" index <= end ? next(element)5_-/."vNPDq" index <= end ? next(element)5_.1/vNPDq# iindex <= end ? next(element)5_/201vNPDq& if (index <= end ? next(element)5_12vNPDq' if (index <= end) ? next(element)5_/10 vNPDq end = endf || Infinity5_(*)vNPDq. index + 1 < end ? stop() : next(element)5_vNPDq return index < end5_vNPDq return index < end 5_vNPC&q return index + 1<= end5_vNPC(q return index + 1 <= end5_vNPC)q return index + 1 < end5_    vNPBq return end > index + 15_  vNPBq return end > index5_  vNPBq return end > index5_ vNPB q var start = 05_ vNPBq var startIndex = 05_vNPB q var startIndex = 0, 5_vNPB*q! var startIndex = 0, stopIndex5_vNPB;5_vNPB>p return end >= index5_vNPAq return end >= ++ index - 15_vNP@q return start <= index5_vNP@q return start <= ++index5_vNP@q return start < index ++5_vNP@q return start < index ++5_vNP@p return end >= index ++# }, filter(function(element) { return start <= index ++ }, source))5_vNP@p source))m source))n 5_vNP@1o return end > index ++5_vNP?o return index < end5_vNP?o return index++ < end5_vNP?o return ++ index <= end5_ppvNP>x return (function(element) {5_[jjvNP9$Z\5_xzyW(XXvNP0VXnH var streams = stack(source), open = 1, alive = true, stopped = false5_lmonYXXvNP0YZp Y[q 5_lnmZXXvNP0Y[pK error || !open ? (open = false, stopped = true, stop(error)) :5_jlkZ XXvNP/Y[pA error ? (open = fale, stopped = true, stop(error)) :5_cefdY XXvNP/XZp return !stopped ? nil :5_deYXXvNP/XZp& return !stopped && !open ? nil :5_"$#_ff!vNP-{{^`5_   ZZZ!vNP+*Y\5_Ypp'v'NP*/XZx console.log('sto')5_j J JvNP(\ik5