index.es.js 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127
  1. import { append, apply, compose, curry2, curry3, findIndex, id, map, reduce, remove } from '@most/prelude';
  2. import { asap, cancelTask, currentTime, delay, periodic, schedulerRelativeTo } from '@most/scheduler';
  3. import { disposeAll, disposeBoth, disposeNone, disposeOnce, tryDispose } from '@most/disposable';
  4. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  5. /** @author Brian Cavalier */
  6. /** @author John Hann */
  7. function fatalError(e) {
  8. setTimeout(rethrow, 0, e);
  9. }
  10. function rethrow(e) {
  11. throw e;
  12. }
  13. var asyncGenerator = function () {
  14. function AwaitValue(value) {
  15. this.value = value;
  16. }
  17. function AsyncGenerator(gen) {
  18. var front, back;
  19. function send(key, arg) {
  20. return new Promise(function (resolve, reject) {
  21. var request = {
  22. key: key,
  23. arg: arg,
  24. resolve: resolve,
  25. reject: reject,
  26. next: null
  27. };
  28. if (back) {
  29. back = back.next = request;
  30. } else {
  31. front = back = request;
  32. resume(key, arg);
  33. }
  34. });
  35. }
  36. function resume(key, arg) {
  37. try {
  38. var result = gen[key](arg);
  39. var value = result.value;
  40. if (value instanceof AwaitValue) {
  41. Promise.resolve(value.value).then(function (arg) {
  42. resume("next", arg);
  43. }, function (arg) {
  44. resume("throw", arg);
  45. });
  46. } else {
  47. settle(result.done ? "return" : "normal", result.value);
  48. }
  49. } catch (err) {
  50. settle("throw", err);
  51. }
  52. }
  53. function settle(type, value) {
  54. switch (type) {
  55. case "return":
  56. front.resolve({
  57. value: value,
  58. done: true
  59. });
  60. break;
  61. case "throw":
  62. front.reject(value);
  63. break;
  64. default:
  65. front.resolve({
  66. value: value,
  67. done: false
  68. });
  69. break;
  70. }
  71. front = front.next;
  72. if (front) {
  73. resume(front.key, front.arg);
  74. } else {
  75. back = null;
  76. }
  77. }
  78. this._invoke = send;
  79. if (typeof gen.return !== "function") {
  80. this.return = undefined;
  81. }
  82. }
  83. if (typeof Symbol === "function" && Symbol.asyncIterator) {
  84. AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
  85. return this;
  86. };
  87. }
  88. AsyncGenerator.prototype.next = function (arg) {
  89. return this._invoke("next", arg);
  90. };
  91. AsyncGenerator.prototype.throw = function (arg) {
  92. return this._invoke("throw", arg);
  93. };
  94. AsyncGenerator.prototype.return = function (arg) {
  95. return this._invoke("return", arg);
  96. };
  97. return {
  98. wrap: function (fn) {
  99. return function () {
  100. return new AsyncGenerator(fn.apply(this, arguments));
  101. };
  102. },
  103. await: function (value) {
  104. return new AwaitValue(value);
  105. }
  106. };
  107. }();
  108. var classCallCheck = function (instance, Constructor) {
  109. if (!(instance instanceof Constructor)) {
  110. throw new TypeError("Cannot call a class as a function");
  111. }
  112. };
  113. var inherits = function (subClass, superClass) {
  114. if (typeof superClass !== "function" && superClass !== null) {
  115. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  116. }
  117. subClass.prototype = Object.create(superClass && superClass.prototype, {
  118. constructor: {
  119. value: subClass,
  120. enumerable: false,
  121. writable: true,
  122. configurable: true
  123. }
  124. });
  125. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  126. };
  127. var possibleConstructorReturn = function (self, call) {
  128. if (!self) {
  129. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  130. }
  131. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  132. };
  133. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  134. /** @author Brian Cavalier */
  135. /** @author John Hann */
  136. var propagateTask$1 = function propagateTask(run, value, sink) {
  137. return new PropagateTask(run, value, sink);
  138. };
  139. var propagateEventTask$1 = function propagateEventTask(value, sink) {
  140. return propagateTask$1(runEvent, value, sink);
  141. };
  142. var propagateEndTask = function propagateEndTask(sink) {
  143. return propagateTask$1(runEnd, undefined, sink);
  144. };
  145. var propagateErrorTask$1 = function propagateErrorTask(value, sink) {
  146. return propagateTask$1(runError, value, sink);
  147. };
  148. var PropagateTask = /*#__PURE__*/function () {
  149. function PropagateTask(run, value, sink) {
  150. classCallCheck(this, PropagateTask);
  151. this._run = run;
  152. this.value = value;
  153. this.sink = sink;
  154. this.active = true;
  155. }
  156. PropagateTask.prototype.dispose = function dispose() {
  157. this.active = false;
  158. };
  159. PropagateTask.prototype.run = function run(t) {
  160. if (!this.active) {
  161. return;
  162. }
  163. var run = this._run;
  164. run(t, this.value, this.sink);
  165. };
  166. PropagateTask.prototype.error = function error(t, e) {
  167. // TODO: Remove this check and just do this.sink.error(t, e)?
  168. if (!this.active) {
  169. return fatalError(e);
  170. }
  171. this.sink.error(t, e);
  172. };
  173. return PropagateTask;
  174. }();
  175. var runEvent = function runEvent(t, x, sink) {
  176. return sink.event(t, x);
  177. };
  178. var runEnd = function runEnd(t, _, sink) {
  179. return sink.end(t);
  180. };
  181. var runError = function runError(t, e, sink) {
  182. return sink.error(t, e);
  183. };
  184. /** @license MIT License (c) copyright 2010-2017 original author or authors */
  185. var empty = function empty() {
  186. return EMPTY;
  187. };
  188. var isCanonicalEmpty = function isCanonicalEmpty(stream) {
  189. return stream === EMPTY;
  190. };
  191. var containsCanonicalEmpty = function containsCanonicalEmpty(streams) {
  192. return streams.some(isCanonicalEmpty);
  193. };
  194. var Empty = /*#__PURE__*/function () {
  195. function Empty() {
  196. classCallCheck(this, Empty);
  197. }
  198. Empty.prototype.run = function run(sink, scheduler$$1) {
  199. return asap(propagateEndTask(sink), scheduler$$1);
  200. };
  201. return Empty;
  202. }();
  203. var EMPTY = /*#__PURE__*/new Empty();
  204. /** @license MIT License (c) copyright 2010-2017 original author or authors */
  205. var never = function never() {
  206. return NEVER;
  207. };
  208. var Never = /*#__PURE__*/function () {
  209. function Never() {
  210. classCallCheck(this, Never);
  211. }
  212. Never.prototype.run = function run() {
  213. return disposeNone();
  214. };
  215. return Never;
  216. }();
  217. var NEVER = /*#__PURE__*/new Never();
  218. /** @license MIT License (c) copyright 2010-2017 original author or authors */
  219. var at = function at(t, x) {
  220. return new At(t, x);
  221. };
  222. var At = /*#__PURE__*/function () {
  223. function At(t, x) {
  224. classCallCheck(this, At);
  225. this.time = t;
  226. this.value = x;
  227. }
  228. At.prototype.run = function run(sink, scheduler$$1) {
  229. return delay(this.time, propagateTask$1(runAt, this.value, sink), scheduler$$1);
  230. };
  231. return At;
  232. }();
  233. function runAt(t, x, sink) {
  234. sink.event(t, x);
  235. sink.end(t);
  236. }
  237. /** @license MIT License (c) copyright 2010-2017 original author or authors */
  238. var now = function now(x) {
  239. return at(0, x);
  240. };
  241. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  242. /** @author Brian Cavalier */
  243. /** @author John Hann */
  244. /**
  245. * Create a stream of events that occur at a regular period
  246. * @param {Number} period periodicity of events
  247. * @returns {Stream} new stream of periodic events, the event value is undefined
  248. */
  249. var periodic$1 = function periodic$$1(period) {
  250. return new Periodic(period);
  251. };
  252. var Periodic = /*#__PURE__*/function () {
  253. function Periodic(period) {
  254. classCallCheck(this, Periodic);
  255. this.period = period;
  256. }
  257. Periodic.prototype.run = function run(sink, scheduler$$1) {
  258. return periodic(this.period, propagateEventTask$1(undefined, sink), scheduler$$1);
  259. };
  260. return Periodic;
  261. }();
  262. /** @license MIT License (c) copyright 2010-2017 original author or authors */
  263. var newStream = function newStream(run) {
  264. return new Stream(run);
  265. };
  266. var Stream = function Stream(run) {
  267. classCallCheck(this, Stream);
  268. this.run = run;
  269. };
  270. /** @license MIT License (c) copyright 2010-2017 original author or authors */
  271. /** @author Brian Cavalier */
  272. var Pipe = /*#__PURE__*/function () {
  273. function Pipe(sink) {
  274. classCallCheck(this, Pipe);
  275. this.sink = sink;
  276. }
  277. Pipe.prototype.event = function event(t, x) {
  278. return this.sink.event(t, x);
  279. };
  280. Pipe.prototype.end = function end(t) {
  281. return this.sink.end(t);
  282. };
  283. Pipe.prototype.error = function error(t, e) {
  284. return this.sink.error(t, e);
  285. };
  286. return Pipe;
  287. }();
  288. /** @license MIT License (c) copyright 2010 original author or authors */
  289. // A slice Bounds type that narrows min values via accumulation
  290. // and max values via Math.min.
  291. // type Bounds = { min: number, max: number }
  292. // Notes:
  293. // 0 <= min <= max
  294. // slice(min2, max2, slice(min1, max1, s)) ~ slice(min1 + min2, Math.min(max1, min1 + max2), s)
  295. // A bounds has a 1d coord system with origin 0, extending to Infinity. Both min and max
  296. // are relative to the origin (0). However, when merging bounds b1 and b2, we
  297. // *interpret* b2 as being relative to b1, hence adding min1 to *both* min2 and max2.
  298. // This essentially translates b2's coordinates back into origin coordinates
  299. // as bounds are merged.
  300. // Construct a constrained bounds
  301. var boundsFrom = function boundsFrom(unsafeMin, unsafeMax) {
  302. var min = Math.max(0, unsafeMin);
  303. var max = Math.max(min, unsafeMax);
  304. return { min: min, max: max };
  305. };
  306. // Combine 2 bounds by narrowing min and max
  307. var mergeBounds = function mergeBounds(b1, b2) {
  308. return boundsFrom(b1.min + b2.min, Math.min(b1.max, b1.min + b2.max));
  309. };
  310. // Nil bounds excludes all slice indices
  311. var isNilBounds = function isNilBounds(b) {
  312. return b.min >= b.max;
  313. };
  314. // Infinite bounds includes all slice indices
  315. var isInfiniteBounds = function isInfiniteBounds(b) {
  316. return b.min <= 0 && b.max === Infinity;
  317. };
  318. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  319. /** @author Brian Cavalier */
  320. /** @author John Hann */
  321. var Filter = /*#__PURE__*/function () {
  322. function Filter(p, source) {
  323. classCallCheck(this, Filter);
  324. this.p = p;
  325. this.source = source;
  326. }
  327. Filter.prototype.run = function run(sink, scheduler$$1) {
  328. return this.source.run(new FilterSink(this.p, sink), scheduler$$1);
  329. };
  330. /**
  331. * Create a filtered source, fusing adjacent filter.filter if possible
  332. * @param {function(x:*):boolean} p filtering predicate
  333. * @param {{run:function}} source source to filter
  334. * @returns {Filter} filtered source
  335. */
  336. Filter.create = function create(p, source) {
  337. if (isCanonicalEmpty(source)) {
  338. return source;
  339. }
  340. if (source instanceof Filter) {
  341. return new Filter(and(source.p, p), source.source);
  342. }
  343. return new Filter(p, source);
  344. };
  345. return Filter;
  346. }();
  347. var FilterSink = /*#__PURE__*/function (_Pipe) {
  348. inherits(FilterSink, _Pipe);
  349. function FilterSink(p, sink) {
  350. classCallCheck(this, FilterSink);
  351. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  352. _this.p = p;
  353. return _this;
  354. }
  355. FilterSink.prototype.event = function event(t, x) {
  356. var p = this.p;
  357. p(x) && this.sink.event(t, x);
  358. };
  359. return FilterSink;
  360. }(Pipe);
  361. var and = function and(p, q) {
  362. return function (x) {
  363. return p(x) && q(x);
  364. };
  365. };
  366. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  367. /** @author Brian Cavalier */
  368. /** @author John Hann */
  369. var FilterMap = /*#__PURE__*/function () {
  370. function FilterMap(p, f, source) {
  371. classCallCheck(this, FilterMap);
  372. this.p = p;
  373. this.f = f;
  374. this.source = source;
  375. }
  376. FilterMap.prototype.run = function run(sink, scheduler$$1) {
  377. return this.source.run(new FilterMapSink(this.p, this.f, sink), scheduler$$1);
  378. };
  379. return FilterMap;
  380. }();
  381. var FilterMapSink = /*#__PURE__*/function (_Pipe) {
  382. inherits(FilterMapSink, _Pipe);
  383. function FilterMapSink(p, f, sink) {
  384. classCallCheck(this, FilterMapSink);
  385. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  386. _this.p = p;
  387. _this.f = f;
  388. return _this;
  389. }
  390. FilterMapSink.prototype.event = function event(t, x) {
  391. var f = this.f;
  392. var p = this.p;
  393. p(x) && this.sink.event(t, f(x));
  394. };
  395. return FilterMapSink;
  396. }(Pipe);
  397. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  398. /** @author Brian Cavalier */
  399. /** @author John Hann */
  400. var Map = /*#__PURE__*/function () {
  401. function Map(f, source) {
  402. classCallCheck(this, Map);
  403. this.f = f;
  404. this.source = source;
  405. }
  406. Map.prototype.run = function run(sink, scheduler$$1) {
  407. // eslint-disable-line no-extend-native
  408. return this.source.run(new MapSink(this.f, sink), scheduler$$1);
  409. };
  410. /**
  411. * Create a mapped source, fusing adjacent map.map, filter.map,
  412. * and filter.map.map if possible
  413. * @param {function(*):*} f mapping function
  414. * @param {{run:function}} source source to map
  415. * @returns {Map|FilterMap} mapped source, possibly fused
  416. */
  417. Map.create = function create(f, source) {
  418. if (isCanonicalEmpty(source)) {
  419. return empty();
  420. }
  421. if (source instanceof Map) {
  422. return new Map(compose(f, source.f), source.source);
  423. }
  424. if (source instanceof Filter) {
  425. return new FilterMap(source.p, f, source.source);
  426. }
  427. return new Map(f, source);
  428. };
  429. return Map;
  430. }();
  431. var MapSink = /*#__PURE__*/function (_Pipe) {
  432. inherits(MapSink, _Pipe);
  433. function MapSink(f, sink) {
  434. classCallCheck(this, MapSink);
  435. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  436. _this.f = f;
  437. return _this;
  438. }
  439. MapSink.prototype.event = function event(t, x) {
  440. var f = this.f;
  441. this.sink.event(t, f(x));
  442. };
  443. return MapSink;
  444. }(Pipe);
  445. /** @license MIT License (c) copyright 2010-2017 original author or authors */
  446. var SettableDisposable = /*#__PURE__*/function () {
  447. function SettableDisposable() {
  448. classCallCheck(this, SettableDisposable);
  449. this.disposable = undefined;
  450. this.disposed = false;
  451. }
  452. SettableDisposable.prototype.setDisposable = function setDisposable(disposable$$1) {
  453. if (this.disposable !== void 0) {
  454. throw new Error('setDisposable called more than once');
  455. }
  456. this.disposable = disposable$$1;
  457. if (this.disposed) {
  458. disposable$$1.dispose();
  459. }
  460. };
  461. SettableDisposable.prototype.dispose = function dispose() {
  462. if (this.disposed) {
  463. return;
  464. }
  465. this.disposed = true;
  466. if (this.disposable !== void 0) {
  467. this.disposable.dispose();
  468. }
  469. };
  470. return SettableDisposable;
  471. }();
  472. /**
  473. * @param {number} n
  474. * @param {Stream} stream
  475. * @returns {Stream} new stream containing only up to the first n items from stream
  476. */
  477. var take$1 = function take(n, stream) {
  478. return slice$1(0, n, stream);
  479. };
  480. /**
  481. * @param {number} n
  482. * @param {Stream} stream
  483. * @returns {Stream} new stream with the first n items removed
  484. */
  485. var skip$1 = function skip(n, stream) {
  486. return slice$1(n, Infinity, stream);
  487. };
  488. /**
  489. * Slice a stream by index. Negative start/end indexes are not supported
  490. * @param {number} start
  491. * @param {number} end
  492. * @param {Stream} stream
  493. * @returns {Stream} stream containing items where start <= index < end
  494. */
  495. var slice$1 = function slice(start, end, stream) {
  496. return sliceBounds(boundsFrom(start, end), stream);
  497. };
  498. var sliceBounds = function sliceBounds(bounds, stream) {
  499. return isSliceEmpty(bounds, stream) ? empty() : stream instanceof Map ? commuteMapSlice(bounds, stream) : stream instanceof Slice ? fuseSlice(bounds, stream) : createSlice(bounds, stream);
  500. };
  501. var isSliceEmpty = function isSliceEmpty(bounds, stream) {
  502. return isCanonicalEmpty(stream) || isNilBounds(bounds);
  503. };
  504. var createSlice = function createSlice(bounds, stream) {
  505. return isInfiniteBounds(bounds) ? stream : new Slice(bounds, stream);
  506. };
  507. var commuteMapSlice = function commuteMapSlice(bounds, mapStream) {
  508. return Map.create(mapStream.f, sliceBounds(bounds, mapStream.source));
  509. };
  510. var fuseSlice = function fuseSlice(bounds, sliceStream) {
  511. return sliceBounds(mergeBounds(sliceStream.bounds, bounds), sliceStream.source);
  512. };
  513. var Slice = /*#__PURE__*/function () {
  514. function Slice(bounds, source) {
  515. classCallCheck(this, Slice);
  516. this.source = source;
  517. this.bounds = bounds;
  518. }
  519. Slice.prototype.run = function run(sink, scheduler$$1) {
  520. var disposable$$1 = new SettableDisposable();
  521. var sliceSink = new SliceSink(this.bounds.min, this.bounds.max - this.bounds.min, sink, disposable$$1);
  522. disposable$$1.setDisposable(this.source.run(sliceSink, scheduler$$1));
  523. return disposable$$1;
  524. };
  525. return Slice;
  526. }();
  527. var SliceSink = /*#__PURE__*/function (_Pipe) {
  528. inherits(SliceSink, _Pipe);
  529. function SliceSink(skip, take, sink, disposable$$1) {
  530. classCallCheck(this, SliceSink);
  531. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  532. _this.skip = skip;
  533. _this.take = take;
  534. _this.disposable = disposable$$1;
  535. return _this;
  536. }
  537. SliceSink.prototype.event = function event(t, x) {
  538. /* eslint complexity: [1, 4] */
  539. if (this.skip > 0) {
  540. this.skip -= 1;
  541. return;
  542. }
  543. if (this.take === 0) {
  544. return;
  545. }
  546. this.take -= 1;
  547. this.sink.event(t, x);
  548. if (this.take === 0) {
  549. this.disposable.dispose();
  550. this.sink.end(t);
  551. }
  552. };
  553. return SliceSink;
  554. }(Pipe);
  555. var takeWhile$1 = function takeWhile(p, stream) {
  556. return isCanonicalEmpty(stream) ? empty() : new TakeWhile(p, stream);
  557. };
  558. var TakeWhile = /*#__PURE__*/function () {
  559. function TakeWhile(p, source) {
  560. classCallCheck(this, TakeWhile);
  561. this.p = p;
  562. this.source = source;
  563. }
  564. TakeWhile.prototype.run = function run(sink, scheduler$$1) {
  565. var disposable$$1 = new SettableDisposable();
  566. var takeWhileSink = new TakeWhileSink(this.p, sink, disposable$$1);
  567. disposable$$1.setDisposable(this.source.run(takeWhileSink, scheduler$$1));
  568. return disposable$$1;
  569. };
  570. return TakeWhile;
  571. }();
  572. var TakeWhileSink = /*#__PURE__*/function (_Pipe2) {
  573. inherits(TakeWhileSink, _Pipe2);
  574. function TakeWhileSink(p, sink, disposable$$1) {
  575. classCallCheck(this, TakeWhileSink);
  576. var _this2 = possibleConstructorReturn(this, _Pipe2.call(this, sink));
  577. _this2.p = p;
  578. _this2.active = true;
  579. _this2.disposable = disposable$$1;
  580. return _this2;
  581. }
  582. TakeWhileSink.prototype.event = function event(t, x) {
  583. if (!this.active) {
  584. return;
  585. }
  586. var p = this.p;
  587. this.active = p(x);
  588. if (this.active) {
  589. this.sink.event(t, x);
  590. } else {
  591. this.disposable.dispose();
  592. this.sink.end(t);
  593. }
  594. };
  595. return TakeWhileSink;
  596. }(Pipe);
  597. var skipWhile$1 = function skipWhile(p, stream) {
  598. return isCanonicalEmpty(stream) ? empty() : new SkipWhile(p, stream);
  599. };
  600. var SkipWhile = /*#__PURE__*/function () {
  601. function SkipWhile(p, source) {
  602. classCallCheck(this, SkipWhile);
  603. this.p = p;
  604. this.source = source;
  605. }
  606. SkipWhile.prototype.run = function run(sink, scheduler$$1) {
  607. return this.source.run(new SkipWhileSink(this.p, sink), scheduler$$1);
  608. };
  609. return SkipWhile;
  610. }();
  611. var SkipWhileSink = /*#__PURE__*/function (_Pipe3) {
  612. inherits(SkipWhileSink, _Pipe3);
  613. function SkipWhileSink(p, sink) {
  614. classCallCheck(this, SkipWhileSink);
  615. var _this3 = possibleConstructorReturn(this, _Pipe3.call(this, sink));
  616. _this3.p = p;
  617. _this3.skipping = true;
  618. return _this3;
  619. }
  620. SkipWhileSink.prototype.event = function event(t, x) {
  621. if (this.skipping) {
  622. var p = this.p;
  623. this.skipping = p(x);
  624. if (this.skipping) {
  625. return;
  626. }
  627. }
  628. this.sink.event(t, x);
  629. };
  630. return SkipWhileSink;
  631. }(Pipe);
  632. var skipAfter$1 = function skipAfter(p, stream) {
  633. return isCanonicalEmpty(stream) ? empty() : new SkipAfter(p, stream);
  634. };
  635. var SkipAfter = /*#__PURE__*/function () {
  636. function SkipAfter(p, source) {
  637. classCallCheck(this, SkipAfter);
  638. this.p = p;
  639. this.source = source;
  640. }
  641. SkipAfter.prototype.run = function run(sink, scheduler$$1) {
  642. return this.source.run(new SkipAfterSink(this.p, sink), scheduler$$1);
  643. };
  644. return SkipAfter;
  645. }();
  646. var SkipAfterSink = /*#__PURE__*/function (_Pipe4) {
  647. inherits(SkipAfterSink, _Pipe4);
  648. function SkipAfterSink(p, sink) {
  649. classCallCheck(this, SkipAfterSink);
  650. var _this4 = possibleConstructorReturn(this, _Pipe4.call(this, sink));
  651. _this4.p = p;
  652. _this4.skipping = false;
  653. return _this4;
  654. }
  655. SkipAfterSink.prototype.event = function event(t, x) {
  656. if (this.skipping) {
  657. return;
  658. }
  659. var p = this.p;
  660. this.skipping = p(x);
  661. this.sink.event(t, x);
  662. if (this.skipping) {
  663. this.sink.end(t);
  664. }
  665. };
  666. return SkipAfterSink;
  667. }(Pipe);
  668. /** @license MIT License (c) copyright 2017 original author or authors */
  669. var withItems$1 = function withItems(items, stream) {
  670. return zipItems$1(keepLeft, items, stream);
  671. };
  672. var zipItems$1 = function zipItems(f, items, stream) {
  673. return isCanonicalEmpty(stream) || items.length === 0 ? empty() : new ZipItems(f, items, take$1(items.length, stream));
  674. };
  675. var keepLeft = function keepLeft(a, _) {
  676. return a;
  677. };
  678. var ZipItems = /*#__PURE__*/function () {
  679. function ZipItems(f, items, source) {
  680. classCallCheck(this, ZipItems);
  681. this.f = f;
  682. this.items = items;
  683. this.source = source;
  684. }
  685. ZipItems.prototype.run = function run(sink, scheduler$$1) {
  686. return this.source.run(new ZipItemsSink(this.f, this.items, sink), scheduler$$1);
  687. };
  688. return ZipItems;
  689. }();
  690. var ZipItemsSink = /*#__PURE__*/function (_Pipe) {
  691. inherits(ZipItemsSink, _Pipe);
  692. function ZipItemsSink(f, items, sink) {
  693. classCallCheck(this, ZipItemsSink);
  694. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  695. _this.f = f;
  696. _this.items = items;
  697. _this.index = 0;
  698. return _this;
  699. }
  700. ZipItemsSink.prototype.event = function event(t, b) {
  701. var f = this.f;
  702. this.sink.event(t, f(this.items[this.index], b));
  703. this.index += 1;
  704. };
  705. return ZipItemsSink;
  706. }(Pipe);
  707. /** @license MIT License (c) copyright 2010-2017 original author or authors */
  708. var runEffects$1 = /*#__PURE__*/curry2(function (stream, scheduler$$1) {
  709. return new Promise(function (resolve, reject) {
  710. return runStream(stream, scheduler$$1, resolve, reject);
  711. });
  712. });
  713. function runStream(stream, scheduler$$1, resolve, reject) {
  714. var disposable$$1 = new SettableDisposable();
  715. var observer = new RunEffectsSink(resolve, reject, disposable$$1);
  716. disposable$$1.setDisposable(stream.run(observer, scheduler$$1));
  717. }
  718. var RunEffectsSink = /*#__PURE__*/function () {
  719. function RunEffectsSink(end, error, disposable$$1) {
  720. classCallCheck(this, RunEffectsSink);
  721. this._end = end;
  722. this._error = error;
  723. this._disposable = disposable$$1;
  724. this.active = true;
  725. }
  726. RunEffectsSink.prototype.event = function event(t, x) {};
  727. RunEffectsSink.prototype.end = function end(t) {
  728. if (!this.active) {
  729. return;
  730. }
  731. this._dispose(this._error, this._end, undefined);
  732. };
  733. RunEffectsSink.prototype.error = function error(t, e) {
  734. this._dispose(this._error, this._error, e);
  735. };
  736. RunEffectsSink.prototype._dispose = function _dispose(error, end, x) {
  737. this.active = false;
  738. tryDispose$1(error, end, x, this._disposable);
  739. };
  740. return RunEffectsSink;
  741. }();
  742. function tryDispose$1(error, end, x, disposable$$1) {
  743. try {
  744. disposable$$1.dispose();
  745. } catch (e) {
  746. error(e);
  747. return;
  748. }
  749. end(x);
  750. }
  751. /** @license MIT License (c) copyright 2010-2017 original author or authors */
  752. // Run a Stream, sending all its events to the
  753. // provided Sink.
  754. var run$1 = function run(sink, scheduler$$1, stream) {
  755. return stream.run(sink, scheduler$$1);
  756. };
  757. var RelativeSink = /*#__PURE__*/function () {
  758. function RelativeSink(offset, sink) {
  759. classCallCheck(this, RelativeSink);
  760. this.sink = sink;
  761. this.offset = offset;
  762. }
  763. RelativeSink.prototype.event = function event(t, x) {
  764. this.sink.event(t + this.offset, x);
  765. };
  766. RelativeSink.prototype.error = function error(t, e) {
  767. this.sink.error(t + this.offset, e);
  768. };
  769. RelativeSink.prototype.end = function end(t) {
  770. this.sink.end(t + this.offset);
  771. };
  772. return RelativeSink;
  773. }();
  774. // Create a stream with its own local clock
  775. // This transforms time from the provided scheduler's clock to a stream-local
  776. // clock (which starts at 0), and then *back* to the scheduler's clock before
  777. // propagating events to sink. In other words, upstream sources will see local times,
  778. // and downstream sinks will see non-local (original) times.
  779. var withLocalTime$1 = function withLocalTime(origin, stream) {
  780. return new WithLocalTime(origin, stream);
  781. };
  782. var WithLocalTime = /*#__PURE__*/function () {
  783. function WithLocalTime(origin, source) {
  784. classCallCheck(this, WithLocalTime);
  785. this.origin = origin;
  786. this.source = source;
  787. }
  788. WithLocalTime.prototype.run = function run(sink, scheduler$$1) {
  789. return this.source.run(relativeSink(this.origin, sink), schedulerRelativeTo(this.origin, scheduler$$1));
  790. };
  791. return WithLocalTime;
  792. }();
  793. // Accumulate offsets instead of nesting RelativeSinks, which can happen
  794. // with higher-order stream and combinators like continueWith when they're
  795. // applied recursively.
  796. var relativeSink = function relativeSink(origin, sink) {
  797. return sink instanceof RelativeSink ? new RelativeSink(origin + sink.offset, sink.sink) : new RelativeSink(origin, sink);
  798. };
  799. /** @license MIT License (c) copyright 2010 original author or authors */
  800. /**
  801. * Generalized feedback loop. Call a stepper function for each event. The stepper
  802. * will be called with 2 params: the current seed and the an event value. It must
  803. * return a new { seed, value } pair. The `seed` will be fed back into the next
  804. * invocation of stepper, and the `value` will be propagated as the event value.
  805. * @param {function(seed:*, value:*):{seed:*, value:*}} stepper loop step function
  806. * @param {*} seed initial seed value passed to first stepper call
  807. * @param {Stream} stream event stream
  808. * @returns {Stream} new stream whose values are the `value` field of the objects
  809. * returned by the stepper
  810. */
  811. var loop$1 = function loop(stepper, seed, stream) {
  812. return isCanonicalEmpty(stream) ? empty() : new Loop(stepper, seed, stream);
  813. };
  814. var Loop = /*#__PURE__*/function () {
  815. function Loop(stepper, seed, source) {
  816. classCallCheck(this, Loop);
  817. this.step = stepper;
  818. this.seed = seed;
  819. this.source = source;
  820. }
  821. Loop.prototype.run = function run(sink, scheduler$$1) {
  822. return this.source.run(new LoopSink(this.step, this.seed, sink), scheduler$$1);
  823. };
  824. return Loop;
  825. }();
  826. var LoopSink = /*#__PURE__*/function (_Pipe) {
  827. inherits(LoopSink, _Pipe);
  828. function LoopSink(stepper, seed, sink) {
  829. classCallCheck(this, LoopSink);
  830. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  831. _this.step = stepper;
  832. _this.seed = seed;
  833. return _this;
  834. }
  835. LoopSink.prototype.event = function event(t, x) {
  836. var result = this.step(this.seed, x);
  837. this.seed = result.seed;
  838. this.sink.event(t, result.value);
  839. };
  840. return LoopSink;
  841. }(Pipe);
  842. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  843. /** @author Brian Cavalier */
  844. /** @author John Hann */
  845. /**
  846. * Create a stream containing successive reduce results of applying f to
  847. * the previous reduce result and the current stream item.
  848. * @param {function(result:*, x:*):*} f reducer function
  849. * @param {*} initial initial value
  850. * @param {Stream} stream stream to scan
  851. * @returns {Stream} new stream containing successive reduce results
  852. */
  853. var scan$1 = function scan(f, initial, stream) {
  854. return new Scan(f, initial, stream);
  855. };
  856. var Scan = /*#__PURE__*/function () {
  857. function Scan(f, z, source) {
  858. classCallCheck(this, Scan);
  859. this.source = source;
  860. this.f = f;
  861. this.value = z;
  862. }
  863. Scan.prototype.run = function run(sink, scheduler$$1) {
  864. var d1 = asap(propagateEventTask$1(this.value, sink), scheduler$$1);
  865. var d2 = this.source.run(new ScanSink(this.f, this.value, sink), scheduler$$1);
  866. return disposeBoth(d1, d2);
  867. };
  868. return Scan;
  869. }();
  870. var ScanSink = /*#__PURE__*/function (_Pipe) {
  871. inherits(ScanSink, _Pipe);
  872. function ScanSink(f, z, sink) {
  873. classCallCheck(this, ScanSink);
  874. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  875. _this.f = f;
  876. _this.value = z;
  877. return _this;
  878. }
  879. ScanSink.prototype.event = function event(t, x) {
  880. var f = this.f;
  881. this.value = f(this.value, x);
  882. this.sink.event(t, this.value);
  883. };
  884. return ScanSink;
  885. }(Pipe);
  886. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  887. /** @author Brian Cavalier */
  888. /** @author John Hann */
  889. var continueWith$1 = function continueWith(f, stream) {
  890. return new ContinueWith(f, stream);
  891. };
  892. var ContinueWith = /*#__PURE__*/function () {
  893. function ContinueWith(f, source) {
  894. classCallCheck(this, ContinueWith);
  895. this.f = f;
  896. this.source = source;
  897. }
  898. ContinueWith.prototype.run = function run(sink, scheduler$$1) {
  899. return new ContinueWithSink(this.f, this.source, sink, scheduler$$1);
  900. };
  901. return ContinueWith;
  902. }();
  903. var ContinueWithSink = /*#__PURE__*/function (_Pipe) {
  904. inherits(ContinueWithSink, _Pipe);
  905. function ContinueWithSink(f, source, sink, scheduler$$1) {
  906. classCallCheck(this, ContinueWithSink);
  907. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  908. _this.f = f;
  909. _this.scheduler = scheduler$$1;
  910. _this.active = true;
  911. _this.disposable = disposeOnce(source.run(_this, scheduler$$1));
  912. return _this;
  913. }
  914. ContinueWithSink.prototype.event = function event(t, x) {
  915. if (!this.active) {
  916. return;
  917. }
  918. this.sink.event(t, x);
  919. };
  920. ContinueWithSink.prototype.end = function end(t) {
  921. if (!this.active) {
  922. return;
  923. }
  924. tryDispose(t, this.disposable, this.sink);
  925. this._startNext(t, this.sink);
  926. };
  927. ContinueWithSink.prototype._startNext = function _startNext(t, sink) {
  928. try {
  929. this.disposable = this._continue(this.f, t, sink);
  930. } catch (e) {
  931. sink.error(t, e);
  932. }
  933. };
  934. ContinueWithSink.prototype._continue = function _continue(f, t, sink) {
  935. return run$1(sink, this.scheduler, withLocalTime$1(t, f()));
  936. };
  937. ContinueWithSink.prototype.dispose = function dispose() {
  938. this.active = false;
  939. return this.disposable.dispose();
  940. };
  941. return ContinueWithSink;
  942. }(Pipe);
  943. /** @license MIT License (c) copyright 2010-2017 original author or authors */
  944. var startWith$1 = function startWith(x, stream) {
  945. return continueWith$1(function () {
  946. return stream;
  947. }, now(x));
  948. };
  949. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  950. /** @author Brian Cavalier */
  951. /** @author John Hann */
  952. /**
  953. * Transform each value in the stream by applying f to each
  954. * @param {function(*):*} f mapping function
  955. * @param {Stream} stream stream to map
  956. * @returns {Stream} stream containing items transformed by f
  957. */
  958. var map$2 = function map$$1(f, stream) {
  959. return Map.create(f, stream);
  960. };
  961. /**
  962. * Replace each value in the stream with x
  963. * @param {*} x
  964. * @param {Stream} stream
  965. * @returns {Stream} stream containing items replaced with x
  966. */
  967. var constant$1 = function constant(x, stream) {
  968. return map$2(function () {
  969. return x;
  970. }, stream);
  971. };
  972. /**
  973. * Perform a side effect for each item in the stream
  974. * @param {function(x:*):*} f side effect to execute for each item. The
  975. * return value will be discarded.
  976. * @param {Stream} stream stream to tap
  977. * @returns {Stream} new stream containing the same items as this stream
  978. */
  979. var tap$1 = function tap(f, stream) {
  980. return new Tap(f, stream);
  981. };
  982. var Tap = /*#__PURE__*/function () {
  983. function Tap(f, source) {
  984. classCallCheck(this, Tap);
  985. this.source = source;
  986. this.f = f;
  987. }
  988. Tap.prototype.run = function run(sink, scheduler$$1) {
  989. return this.source.run(new TapSink(this.f, sink), scheduler$$1);
  990. };
  991. return Tap;
  992. }();
  993. var TapSink = /*#__PURE__*/function (_Pipe) {
  994. inherits(TapSink, _Pipe);
  995. function TapSink(f, sink) {
  996. classCallCheck(this, TapSink);
  997. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  998. _this.f = f;
  999. return _this;
  1000. }
  1001. TapSink.prototype.event = function event(t, x) {
  1002. var f = this.f;
  1003. f(x);
  1004. this.sink.event(t, x);
  1005. };
  1006. return TapSink;
  1007. }(Pipe);
  1008. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  1009. /** @author Brian Cavalier */
  1010. /** @author John Hann */
  1011. var IndexSink = /*#__PURE__*/function (_Sink) {
  1012. inherits(IndexSink, _Sink);
  1013. function IndexSink(i, sink) {
  1014. classCallCheck(this, IndexSink);
  1015. var _this = possibleConstructorReturn(this, _Sink.call(this, sink));
  1016. _this.index = i;
  1017. _this.active = true;
  1018. _this.value = undefined;
  1019. return _this;
  1020. }
  1021. IndexSink.prototype.event = function event(t, x) {
  1022. if (!this.active) {
  1023. return;
  1024. }
  1025. this.value = x;
  1026. this.sink.event(t, this);
  1027. };
  1028. IndexSink.prototype.end = function end(t) {
  1029. if (!this.active) {
  1030. return;
  1031. }
  1032. this.active = false;
  1033. this.sink.event(t, this);
  1034. };
  1035. return IndexSink;
  1036. }(Pipe);
  1037. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  1038. /** @author Brian Cavalier */
  1039. /** @author John Hann */
  1040. function invoke(f, args) {
  1041. /* eslint complexity: [2,7] */
  1042. switch (args.length) {
  1043. case 0:
  1044. return f();
  1045. case 1:
  1046. return f(args[0]);
  1047. case 2:
  1048. return f(args[0], args[1]);
  1049. case 3:
  1050. return f(args[0], args[1], args[2]);
  1051. case 4:
  1052. return f(args[0], args[1], args[2], args[3]);
  1053. case 5:
  1054. return f(args[0], args[1], args[2], args[3], args[4]);
  1055. default:
  1056. return f.apply(void 0, args);
  1057. }
  1058. }
  1059. /** @license MIT License (c) copyright 2010 original author or authors */
  1060. /**
  1061. * Combine latest events from two streams
  1062. * @param {function(...events):*} f function to combine most recent events
  1063. * @returns {Stream} stream containing the result of applying f to the most recent
  1064. * event of each input stream, whenever a new event arrives on any stream.
  1065. */
  1066. var combine$1 = function combine(f, stream1, stream2) {
  1067. return combineArray$1(f, [stream1, stream2]);
  1068. };
  1069. /**
  1070. * Combine latest events from all input streams
  1071. * @param {function(...events):*} f function to combine most recent events
  1072. * @param {[Stream]} streams most recent events
  1073. * @returns {Stream} stream containing the result of applying f to the most recent
  1074. * event of each input stream, whenever a new event arrives on any stream.
  1075. */
  1076. var combineArray$1 = function combineArray(f, streams) {
  1077. return streams.length === 0 || containsCanonicalEmpty(streams) ? empty() : streams.length === 1 ? map$2(f, streams[0]) : new Combine(f, streams);
  1078. };
  1079. var Combine = /*#__PURE__*/function () {
  1080. function Combine(f, sources) {
  1081. classCallCheck(this, Combine);
  1082. this.f = f;
  1083. this.sources = sources;
  1084. }
  1085. Combine.prototype.run = function run(sink, scheduler$$1) {
  1086. var l = this.sources.length;
  1087. var disposables = new Array(l);
  1088. var sinks = new Array(l);
  1089. var mergeSink = new CombineSink(disposables, sinks, sink, this.f);
  1090. for (var indexSink, i = 0; i < l; ++i) {
  1091. indexSink = sinks[i] = new IndexSink(i, mergeSink);
  1092. disposables[i] = this.sources[i].run(indexSink, scheduler$$1);
  1093. }
  1094. return disposeAll(disposables);
  1095. };
  1096. return Combine;
  1097. }();
  1098. var CombineSink = /*#__PURE__*/function (_Pipe) {
  1099. inherits(CombineSink, _Pipe);
  1100. function CombineSink(disposables, sinks, sink, f) {
  1101. classCallCheck(this, CombineSink);
  1102. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  1103. _this.disposables = disposables;
  1104. _this.sinks = sinks;
  1105. _this.f = f;
  1106. var l = sinks.length;
  1107. _this.awaiting = l;
  1108. _this.values = new Array(l);
  1109. _this.hasValue = new Array(l).fill(false);
  1110. _this.activeCount = sinks.length;
  1111. return _this;
  1112. }
  1113. CombineSink.prototype.event = function event(t, indexedValue) {
  1114. if (!indexedValue.active) {
  1115. this._dispose(t, indexedValue.index);
  1116. return;
  1117. }
  1118. var i = indexedValue.index;
  1119. var awaiting = this._updateReady(i);
  1120. this.values[i] = indexedValue.value;
  1121. if (awaiting === 0) {
  1122. this.sink.event(t, invoke(this.f, this.values));
  1123. }
  1124. };
  1125. CombineSink.prototype._updateReady = function _updateReady(index) {
  1126. if (this.awaiting > 0) {
  1127. if (!this.hasValue[index]) {
  1128. this.hasValue[index] = true;
  1129. this.awaiting -= 1;
  1130. }
  1131. }
  1132. return this.awaiting;
  1133. };
  1134. CombineSink.prototype._dispose = function _dispose(t, index) {
  1135. tryDispose(t, this.disposables[index], this.sink);
  1136. if (--this.activeCount === 0) {
  1137. this.sink.end(t);
  1138. }
  1139. };
  1140. return CombineSink;
  1141. }(Pipe);
  1142. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  1143. /** @author Brian Cavalier */
  1144. /** @author John Hann */
  1145. /**
  1146. * Assume fs is a stream containing functions, and apply the latest function
  1147. * in fs to the latest value in xs.
  1148. * fs: --f---------g--------h------>
  1149. * xs: -a-------b-------c-------d-->
  1150. * ap(fs, xs): --fa-----fb-gb---gc--hc--hd->
  1151. * @param {Stream} fs stream of functions to apply to the latest x
  1152. * @param {Stream} xs stream of values to which to apply all the latest f
  1153. * @returns {Stream} stream containing all the applications of fs to xs
  1154. */
  1155. function ap$1(fs, xs) {
  1156. return combine$1(apply, fs, xs);
  1157. }
  1158. /** @license MIT License (c) copyright 2010 original author or authors */
  1159. var mergeConcurrently$1 = function mergeConcurrently(concurrency, stream) {
  1160. return mergeMapConcurrently$1(id, concurrency, stream);
  1161. };
  1162. var mergeMapConcurrently$1 = function mergeMapConcurrently(f, concurrency, stream) {
  1163. return isCanonicalEmpty(stream) ? empty() : new MergeConcurrently(f, concurrency, stream);
  1164. };
  1165. var MergeConcurrently = /*#__PURE__*/function () {
  1166. function MergeConcurrently(f, concurrency, source) {
  1167. classCallCheck(this, MergeConcurrently);
  1168. this.f = f;
  1169. this.concurrency = concurrency;
  1170. this.source = source;
  1171. }
  1172. MergeConcurrently.prototype.run = function run(sink, scheduler$$1) {
  1173. return new Outer(this.f, this.concurrency, this.source, sink, scheduler$$1);
  1174. };
  1175. return MergeConcurrently;
  1176. }();
  1177. var Outer = /*#__PURE__*/function () {
  1178. function Outer(f, concurrency, source, sink, scheduler$$1) {
  1179. classCallCheck(this, Outer);
  1180. this.f = f;
  1181. this.concurrency = concurrency;
  1182. this.sink = sink;
  1183. this.scheduler = scheduler$$1;
  1184. this.pending = [];
  1185. this.current = [];
  1186. this.disposable = disposeOnce(source.run(this, scheduler$$1));
  1187. this.active = true;
  1188. }
  1189. Outer.prototype.event = function event(t, x) {
  1190. this._addInner(t, x);
  1191. };
  1192. Outer.prototype._addInner = function _addInner(t, x) {
  1193. if (this.current.length < this.concurrency) {
  1194. this._startInner(t, x);
  1195. } else {
  1196. this.pending.push(x);
  1197. }
  1198. };
  1199. Outer.prototype._startInner = function _startInner(t, x) {
  1200. try {
  1201. this._initInner(t, x);
  1202. } catch (e) {
  1203. this.error(t, e);
  1204. }
  1205. };
  1206. Outer.prototype._initInner = function _initInner(t, x) {
  1207. var innerSink = new Inner(t, this, this.sink);
  1208. innerSink.disposable = mapAndRun(this.f, t, x, innerSink, this.scheduler);
  1209. this.current.push(innerSink);
  1210. };
  1211. Outer.prototype.end = function end(t) {
  1212. this.active = false;
  1213. tryDispose(t, this.disposable, this.sink);
  1214. this._checkEnd(t);
  1215. };
  1216. Outer.prototype.error = function error(t, e) {
  1217. this.active = false;
  1218. this.sink.error(t, e);
  1219. };
  1220. Outer.prototype.dispose = function dispose() {
  1221. this.active = false;
  1222. this.pending.length = 0;
  1223. this.disposable.dispose();
  1224. disposeAll(this.current).dispose();
  1225. };
  1226. Outer.prototype._endInner = function _endInner(t, inner) {
  1227. var i = this.current.indexOf(inner);
  1228. if (i >= 0) {
  1229. this.current.splice(i, 1);
  1230. }
  1231. tryDispose(t, inner, this);
  1232. if (this.pending.length === 0) {
  1233. this._checkEnd(t);
  1234. } else {
  1235. this._startInner(t, this.pending.shift());
  1236. }
  1237. };
  1238. Outer.prototype._checkEnd = function _checkEnd(t) {
  1239. if (!this.active && this.current.length === 0) {
  1240. this.sink.end(t);
  1241. }
  1242. };
  1243. return Outer;
  1244. }();
  1245. var mapAndRun = function mapAndRun(f, t, x, sink, scheduler$$1) {
  1246. return f(x).run(sink, schedulerRelativeTo(t, scheduler$$1));
  1247. };
  1248. var Inner = /*#__PURE__*/function () {
  1249. function Inner(time, outer, sink) {
  1250. classCallCheck(this, Inner);
  1251. this.time = time;
  1252. this.outer = outer;
  1253. this.sink = sink;
  1254. this.disposable = disposeNone();
  1255. }
  1256. Inner.prototype.event = function event(t, x) {
  1257. this.sink.event(t + this.time, x);
  1258. };
  1259. Inner.prototype.end = function end(t) {
  1260. this.outer._endInner(t + this.time, this);
  1261. };
  1262. Inner.prototype.error = function error(t, e) {
  1263. this.outer.error(t + this.time, e);
  1264. };
  1265. Inner.prototype.dispose = function dispose() {
  1266. return this.disposable.dispose();
  1267. };
  1268. return Inner;
  1269. }();
  1270. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  1271. /** @author Brian Cavalier */
  1272. /** @author John Hann */
  1273. /**
  1274. * Map each value in the stream to a new stream, and merge it into the
  1275. * returned outer stream. Event arrival times are preserved.
  1276. * @param {function(x:*):Stream} f chaining function, must return a Stream
  1277. * @param {Stream} stream
  1278. * @returns {Stream} new stream containing all events from each stream returned by f
  1279. */
  1280. var chain$1 = function chain(f, stream) {
  1281. return mergeMapConcurrently$1(f, Infinity, stream);
  1282. };
  1283. /**
  1284. * Monadic join. Flatten a Stream<Stream<X>> to Stream<X> by merging inner
  1285. * streams to the outer. Event arrival times are preserved.
  1286. * @param {Stream<Stream<X>>} stream stream of streams
  1287. * @returns {Stream<X>} new stream containing all events of all inner streams
  1288. */
  1289. var join = function join(stream) {
  1290. return mergeConcurrently$1(Infinity, stream);
  1291. };
  1292. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  1293. /** @author Brian Cavalier */
  1294. /** @author John Hann */
  1295. /**
  1296. * Map each value in stream to a new stream, and concatenate them all
  1297. * stream: -a---b---cX
  1298. * f(a): 1-1-1-1X
  1299. * f(b): -2-2-2-2X
  1300. * f(c): -3-3-3-3X
  1301. * stream.concatMap(f): -1-1-1-1-2-2-2-2-3-3-3-3X
  1302. * @param {function(x:*):Stream} f function to map each value to a stream
  1303. * @param {Stream} stream
  1304. * @returns {Stream} new stream containing all events from each stream returned by f
  1305. */
  1306. var concatMap$1 = function concatMap(f, stream) {
  1307. return mergeMapConcurrently$1(f, 1, stream);
  1308. };
  1309. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  1310. /** @author Brian Cavalier */
  1311. /** @author John Hann */
  1312. /**
  1313. * @returns {Stream} stream containing events from two streams in time order.
  1314. * If two events are simultaneous they will be merged in arbitrary order.
  1315. */
  1316. function merge$1(stream1, stream2) {
  1317. return mergeArray([stream1, stream2]);
  1318. }
  1319. /**
  1320. * @param {Array} streams array of stream to merge
  1321. * @returns {Stream} stream containing events from all input observables
  1322. * in time order. If two events are simultaneous they will be merged in
  1323. * arbitrary order.
  1324. */
  1325. var mergeArray = function mergeArray(streams) {
  1326. return mergeStreams(withoutCanonicalEmpty(streams));
  1327. };
  1328. /**
  1329. * This implements fusion/flattening for merge. It will
  1330. * fuse adjacent merge operations. For example:
  1331. * - a.merge(b).merge(c) effectively becomes merge(a, b, c)
  1332. * - merge(a, merge(b, c)) effectively becomes merge(a, b, c)
  1333. * It does this by concatenating the sources arrays of
  1334. * any nested Merge sources, in effect "flattening" nested
  1335. * merge operations into a single merge.
  1336. */
  1337. var mergeStreams = function mergeStreams(streams) {
  1338. return streams.length === 0 ? empty() : streams.length === 1 ? streams[0] : new Merge(reduce(appendSources, [], streams));
  1339. };
  1340. var withoutCanonicalEmpty = function withoutCanonicalEmpty(streams) {
  1341. return streams.filter(isNotCanonicalEmpty);
  1342. };
  1343. var isNotCanonicalEmpty = function isNotCanonicalEmpty(stream) {
  1344. return !isCanonicalEmpty(stream);
  1345. };
  1346. var appendSources = function appendSources(sources, stream) {
  1347. return sources.concat(stream instanceof Merge ? stream.sources : stream);
  1348. };
  1349. var Merge = /*#__PURE__*/function () {
  1350. function Merge(sources) {
  1351. classCallCheck(this, Merge);
  1352. this.sources = sources;
  1353. }
  1354. Merge.prototype.run = function run(sink, scheduler$$1) {
  1355. var l = this.sources.length;
  1356. var disposables = new Array(l);
  1357. var sinks = new Array(l);
  1358. var mergeSink = new MergeSink(disposables, sinks, sink);
  1359. for (var indexSink, i = 0; i < l; ++i) {
  1360. indexSink = sinks[i] = new IndexSink(i, mergeSink);
  1361. disposables[i] = this.sources[i].run(indexSink, scheduler$$1);
  1362. }
  1363. return disposeAll(disposables);
  1364. };
  1365. return Merge;
  1366. }();
  1367. var MergeSink = /*#__PURE__*/function (_Pipe) {
  1368. inherits(MergeSink, _Pipe);
  1369. function MergeSink(disposables, sinks, sink) {
  1370. classCallCheck(this, MergeSink);
  1371. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  1372. _this.disposables = disposables;
  1373. _this.activeCount = sinks.length;
  1374. return _this;
  1375. }
  1376. MergeSink.prototype.event = function event(t, indexValue) {
  1377. if (!indexValue.active) {
  1378. this._dispose(t, indexValue.index);
  1379. return;
  1380. }
  1381. this.sink.event(t, indexValue.value);
  1382. };
  1383. MergeSink.prototype._dispose = function _dispose(t, index) {
  1384. tryDispose(t, this.disposables[index], this.sink);
  1385. if (--this.activeCount === 0) {
  1386. this.sink.end(t);
  1387. }
  1388. };
  1389. return MergeSink;
  1390. }(Pipe);
  1391. /** @license MIT License (c) copyright 2010 original author or authors */
  1392. var sample$1 = function sample(values, sampler) {
  1393. return snapshot$1(function (x, _) {
  1394. return x;
  1395. }, values, sampler);
  1396. };
  1397. var snapshot$1 = function snapshot(f, values, sampler) {
  1398. return isCanonicalEmpty(sampler) || isCanonicalEmpty(values) ? empty() : new Snapshot(f, values, sampler);
  1399. };
  1400. var Snapshot = /*#__PURE__*/function () {
  1401. function Snapshot(f, values, sampler) {
  1402. classCallCheck(this, Snapshot);
  1403. this.f = f;
  1404. this.values = values;
  1405. this.sampler = sampler;
  1406. }
  1407. Snapshot.prototype.run = function run(sink, scheduler$$1) {
  1408. var sampleSink = new SnapshotSink(this.f, sink);
  1409. var valuesDisposable = this.values.run(sampleSink.latest, scheduler$$1);
  1410. var samplerDisposable = this.sampler.run(sampleSink, scheduler$$1);
  1411. return disposeBoth(samplerDisposable, valuesDisposable);
  1412. };
  1413. return Snapshot;
  1414. }();
  1415. var SnapshotSink = /*#__PURE__*/function (_Pipe) {
  1416. inherits(SnapshotSink, _Pipe);
  1417. function SnapshotSink(f, sink) {
  1418. classCallCheck(this, SnapshotSink);
  1419. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  1420. _this.f = f;
  1421. _this.latest = new LatestValueSink(_this);
  1422. return _this;
  1423. }
  1424. SnapshotSink.prototype.event = function event(t, x) {
  1425. if (this.latest.hasValue) {
  1426. var f = this.f;
  1427. this.sink.event(t, f(this.latest.value, x));
  1428. }
  1429. };
  1430. return SnapshotSink;
  1431. }(Pipe);
  1432. var LatestValueSink = /*#__PURE__*/function (_Pipe2) {
  1433. inherits(LatestValueSink, _Pipe2);
  1434. function LatestValueSink(sink) {
  1435. classCallCheck(this, LatestValueSink);
  1436. var _this2 = possibleConstructorReturn(this, _Pipe2.call(this, sink));
  1437. _this2.hasValue = false;
  1438. return _this2;
  1439. }
  1440. LatestValueSink.prototype.event = function event(t, x) {
  1441. this.value = x;
  1442. this.hasValue = true;
  1443. };
  1444. LatestValueSink.prototype.end = function end() {};
  1445. return LatestValueSink;
  1446. }(Pipe);
  1447. // Copied and modified from https://github.com/invertase/denque
  1448. // MIT License
  1449. // These constants were extracted directly from denque's shift()
  1450. // It's not clear exactly why the authors chose these particular
  1451. // values, but given denque's stated goals, it seems likely that
  1452. // they were chosen for speed/memory reasons.
  1453. // Max value of _head at which Queue is willing to shink
  1454. // its internal array
  1455. var HEAD_MAX_SHRINK = 2;
  1456. // Min value of _tail at which Queue is willing to shink
  1457. // its internal array
  1458. var TAIL_MIN_SHRINK = 10000;
  1459. var Queue = /*#__PURE__*/function () {
  1460. function Queue() {
  1461. classCallCheck(this, Queue);
  1462. this._head = 0;
  1463. this._tail = 0;
  1464. this._capacityMask = 0x3;
  1465. this._list = new Array(4);
  1466. }
  1467. Queue.prototype.push = function push(x) {
  1468. var tail = this._tail;
  1469. this._list[tail] = x;
  1470. this._tail = tail + 1 & this._capacityMask;
  1471. if (this._tail === this._head) {
  1472. this._growArray();
  1473. }
  1474. if (this._head < this._tail) {
  1475. return this._tail - this._head;
  1476. } else {
  1477. return this._capacityMask + 1 - (this._head - this._tail);
  1478. }
  1479. };
  1480. Queue.prototype.shift = function shift() {
  1481. var head = this._head;
  1482. if (head === this._tail) {
  1483. return undefined;
  1484. }
  1485. var x = this._list[head];
  1486. this._list[head] = undefined;
  1487. this._head = head + 1 & this._capacityMask;
  1488. if (head < HEAD_MAX_SHRINK && this._tail > TAIL_MIN_SHRINK && this._tail <= this._list.length >>> 2) {
  1489. this._shrinkArray();
  1490. }
  1491. return x;
  1492. };
  1493. Queue.prototype.isEmpty = function isEmpty() {
  1494. return this._head === this._tail;
  1495. };
  1496. Queue.prototype.length = function length() {
  1497. if (this._head === this._tail) {
  1498. return 0;
  1499. } else if (this._head < this._tail) {
  1500. return this._tail - this._head;
  1501. } else {
  1502. return this._capacityMask + 1 - (this._head - this._tail);
  1503. }
  1504. };
  1505. Queue.prototype._growArray = function _growArray() {
  1506. if (this._head) {
  1507. // copy existing data, head to end, then beginning to tail.
  1508. this._list = this._copyArray();
  1509. this._head = 0;
  1510. }
  1511. // head is at 0 and array is now full, safe to extend
  1512. this._tail = this._list.length;
  1513. this._list.length *= 2;
  1514. this._capacityMask = this._capacityMask << 1 | 1;
  1515. };
  1516. Queue.prototype._shrinkArray = function _shrinkArray() {
  1517. this._list.length >>>= 1;
  1518. this._capacityMask >>>= 1;
  1519. };
  1520. Queue.prototype._copyArray = function _copyArray() {
  1521. var newArray = [];
  1522. var list = this._list;
  1523. var len = list.length;
  1524. var i = void 0;
  1525. for (i = this._head; i < len; i++) {
  1526. newArray.push(list[i]);
  1527. }
  1528. for (i = 0; i < this._tail; i++) {
  1529. newArray.push(list[i]);
  1530. }
  1531. return newArray;
  1532. };
  1533. return Queue;
  1534. }();
  1535. /** @license MIT License (c) copyright 2010 original author or authors */
  1536. /**
  1537. * Combine two streams pairwise by index by applying f to values at corresponding
  1538. * indices. The returned stream ends when either of the input streams ends.
  1539. * @param {function} f function to combine values
  1540. * @returns {Stream} new stream with items at corresponding indices combined
  1541. * using f
  1542. */
  1543. function zip$1(f, stream1, stream2) {
  1544. return zipArray$1(f, [stream1, stream2]);
  1545. }
  1546. /**
  1547. * Combine streams pairwise (or tuple-wise) by index by applying f to values
  1548. * at corresponding indices. The returned stream ends when any of the input
  1549. * streams ends.
  1550. * @param {function} f function to combine values
  1551. * @param {[Stream]} streams streams to zip using f
  1552. * @returns {Stream} new stream with items at corresponding indices combined
  1553. * using f
  1554. */
  1555. var zipArray$1 = function zipArray(f, streams) {
  1556. return streams.length === 0 || containsCanonicalEmpty(streams) ? empty() : streams.length === 1 ? map$2(f, streams[0]) : new Zip(f, streams);
  1557. };
  1558. var Zip = /*#__PURE__*/function () {
  1559. function Zip(f, sources) {
  1560. classCallCheck(this, Zip);
  1561. this.f = f;
  1562. this.sources = sources;
  1563. }
  1564. Zip.prototype.run = function run(sink, scheduler$$1) {
  1565. var l = this.sources.length;
  1566. var disposables = new Array(l);
  1567. var sinks = new Array(l);
  1568. var buffers = new Array(l);
  1569. var zipSink = new ZipSink(this.f, buffers, sinks, sink);
  1570. for (var indexSink, i = 0; i < l; ++i) {
  1571. buffers[i] = new Queue();
  1572. indexSink = sinks[i] = new IndexSink(i, zipSink);
  1573. disposables[i] = this.sources[i].run(indexSink, scheduler$$1);
  1574. }
  1575. return disposeAll(disposables);
  1576. };
  1577. return Zip;
  1578. }();
  1579. var ZipSink = /*#__PURE__*/function (_Pipe) {
  1580. inherits(ZipSink, _Pipe);
  1581. function ZipSink(f, buffers, sinks, sink) {
  1582. classCallCheck(this, ZipSink);
  1583. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  1584. _this.f = f;
  1585. _this.sinks = sinks;
  1586. _this.buffers = buffers;
  1587. return _this;
  1588. }
  1589. ZipSink.prototype.event = function event(t, indexedValue) {
  1590. /* eslint complexity: [1, 5] */
  1591. if (!indexedValue.active) {
  1592. this._dispose(t, indexedValue.index);
  1593. return;
  1594. }
  1595. var buffers = this.buffers;
  1596. var buffer = buffers[indexedValue.index];
  1597. buffer.push(indexedValue.value);
  1598. if (buffer.length() === 1) {
  1599. if (!ready(this.buffers)) {
  1600. return;
  1601. }
  1602. emitZipped(this.f, t, buffers, this.sink);
  1603. if (ended(this.buffers, this.sinks)) {
  1604. this.sink.end(t);
  1605. }
  1606. }
  1607. };
  1608. ZipSink.prototype._dispose = function _dispose(t, index) {
  1609. var buffer = this.buffers[index];
  1610. if (buffer.isEmpty()) {
  1611. this.sink.end(t);
  1612. }
  1613. };
  1614. return ZipSink;
  1615. }(Pipe);
  1616. var emitZipped = function emitZipped(f, t, buffers, sink) {
  1617. return sink.event(t, invoke(f, map(head, buffers)));
  1618. };
  1619. var head = function head(buffer) {
  1620. return buffer.shift();
  1621. };
  1622. function ended(buffers, sinks) {
  1623. for (var i = 0, l = buffers.length; i < l; ++i) {
  1624. if (buffers[i].isEmpty() && !sinks[i].active) {
  1625. return true;
  1626. }
  1627. }
  1628. return false;
  1629. }
  1630. function ready(buffers) {
  1631. for (var i = 0, l = buffers.length; i < l; ++i) {
  1632. if (buffers[i].isEmpty()) {
  1633. return false;
  1634. }
  1635. }
  1636. return true;
  1637. }
  1638. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  1639. /** @author Brian Cavalier */
  1640. /** @author John Hann */
  1641. /**
  1642. * Given a stream of streams, return a new stream that adopts the behavior
  1643. * of the most recent inner stream.
  1644. * @param {Stream} stream of streams on which to switch
  1645. * @returns {Stream} switching stream
  1646. */
  1647. var switchLatest = function switchLatest(stream) {
  1648. return isCanonicalEmpty(stream) ? empty() : new Switch(stream);
  1649. };
  1650. var Switch = /*#__PURE__*/function () {
  1651. function Switch(source) {
  1652. classCallCheck(this, Switch);
  1653. this.source = source;
  1654. }
  1655. Switch.prototype.run = function run(sink, scheduler$$1) {
  1656. var switchSink = new SwitchSink(sink, scheduler$$1);
  1657. return disposeBoth(switchSink, this.source.run(switchSink, scheduler$$1));
  1658. };
  1659. return Switch;
  1660. }();
  1661. var SwitchSink = /*#__PURE__*/function () {
  1662. function SwitchSink(sink, scheduler$$1) {
  1663. classCallCheck(this, SwitchSink);
  1664. this.sink = sink;
  1665. this.scheduler = scheduler$$1;
  1666. this.current = null;
  1667. this.ended = false;
  1668. }
  1669. SwitchSink.prototype.event = function event(t, stream) {
  1670. this._disposeCurrent(t);
  1671. this.current = new Segment(stream, t, Infinity, this, this.sink, this.scheduler);
  1672. };
  1673. SwitchSink.prototype.end = function end(t) {
  1674. this.ended = true;
  1675. this._checkEnd(t);
  1676. };
  1677. SwitchSink.prototype.error = function error(t, e) {
  1678. this.ended = true;
  1679. this.sink.error(t, e);
  1680. };
  1681. SwitchSink.prototype.dispose = function dispose() {
  1682. return this._disposeCurrent(currentTime(this.scheduler));
  1683. };
  1684. SwitchSink.prototype._disposeCurrent = function _disposeCurrent(t) {
  1685. if (this.current !== null) {
  1686. return this.current._dispose(t);
  1687. }
  1688. };
  1689. SwitchSink.prototype._disposeInner = function _disposeInner(t, inner) {
  1690. inner._dispose(t);
  1691. if (inner === this.current) {
  1692. this.current = null;
  1693. }
  1694. };
  1695. SwitchSink.prototype._checkEnd = function _checkEnd(t) {
  1696. if (this.ended && this.current === null) {
  1697. this.sink.end(t);
  1698. }
  1699. };
  1700. SwitchSink.prototype._endInner = function _endInner(t, inner) {
  1701. this._disposeInner(t, inner);
  1702. this._checkEnd(t);
  1703. };
  1704. SwitchSink.prototype._errorInner = function _errorInner(t, e, inner) {
  1705. this._disposeInner(t, inner);
  1706. this.sink.error(t, e);
  1707. };
  1708. return SwitchSink;
  1709. }();
  1710. var Segment = /*#__PURE__*/function () {
  1711. function Segment(source, min, max, outer, sink, scheduler$$1) {
  1712. classCallCheck(this, Segment);
  1713. this.min = min;
  1714. this.max = max;
  1715. this.outer = outer;
  1716. this.sink = sink;
  1717. this.disposable = source.run(this, schedulerRelativeTo(min, scheduler$$1));
  1718. }
  1719. Segment.prototype.event = function event(t, x) {
  1720. var time = Math.max(0, t + this.min);
  1721. if (time < this.max) {
  1722. this.sink.event(time, x);
  1723. }
  1724. };
  1725. Segment.prototype.end = function end(t) {
  1726. this.outer._endInner(t + this.min, this);
  1727. };
  1728. Segment.prototype.error = function error(t, e) {
  1729. this.outer._errorInner(t + this.min, e, this);
  1730. };
  1731. Segment.prototype._dispose = function _dispose(t) {
  1732. tryDispose(t, this.disposable, this.sink);
  1733. };
  1734. return Segment;
  1735. }();
  1736. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  1737. /** @author Brian Cavalier */
  1738. /** @author John Hann */
  1739. /**
  1740. * Retain only items matching a predicate
  1741. * @param {function(x:*):boolean} p filtering predicate called for each item
  1742. * @param {Stream} stream stream to filter
  1743. * @returns {Stream} stream containing only items for which predicate returns truthy
  1744. */
  1745. var filter$1 = function filter(p, stream) {
  1746. return Filter.create(p, stream);
  1747. };
  1748. /**
  1749. * Skip repeated events, using === to detect duplicates
  1750. * @param {Stream} stream stream from which to omit repeated events
  1751. * @returns {Stream} stream without repeated events
  1752. */
  1753. var skipRepeats = function skipRepeats(stream) {
  1754. return skipRepeatsWith$1(same, stream);
  1755. };
  1756. /**
  1757. * Skip repeated events using the provided equals function to detect duplicates
  1758. * @param {function(a:*, b:*):boolean} equals optional function to compare items
  1759. * @param {Stream} stream stream from which to omit repeated events
  1760. * @returns {Stream} stream without repeated events
  1761. */
  1762. var skipRepeatsWith$1 = function skipRepeatsWith(equals, stream) {
  1763. return isCanonicalEmpty(stream) ? empty() : new SkipRepeats(equals, stream);
  1764. };
  1765. var SkipRepeats = /*#__PURE__*/function () {
  1766. function SkipRepeats(equals, source) {
  1767. classCallCheck(this, SkipRepeats);
  1768. this.equals = equals;
  1769. this.source = source;
  1770. }
  1771. SkipRepeats.prototype.run = function run(sink, scheduler$$1) {
  1772. return this.source.run(new SkipRepeatsSink(this.equals, sink), scheduler$$1);
  1773. };
  1774. return SkipRepeats;
  1775. }();
  1776. var SkipRepeatsSink = /*#__PURE__*/function (_Pipe) {
  1777. inherits(SkipRepeatsSink, _Pipe);
  1778. function SkipRepeatsSink(equals, sink) {
  1779. classCallCheck(this, SkipRepeatsSink);
  1780. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  1781. _this.equals = equals;
  1782. _this.value = void 0;
  1783. _this.init = true;
  1784. return _this;
  1785. }
  1786. SkipRepeatsSink.prototype.event = function event(t, x) {
  1787. if (this.init) {
  1788. this.init = false;
  1789. this.value = x;
  1790. this.sink.event(t, x);
  1791. } else if (!this.equals(this.value, x)) {
  1792. this.value = x;
  1793. this.sink.event(t, x);
  1794. }
  1795. };
  1796. return SkipRepeatsSink;
  1797. }(Pipe);
  1798. function same(a, b) {
  1799. return a === b;
  1800. }
  1801. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  1802. /** @author Brian Cavalier */
  1803. /** @author John Hann */
  1804. var until$1 = function until(signal, stream) {
  1805. return new Until(signal, stream);
  1806. };
  1807. var since$1 = function since(signal, stream) {
  1808. return new Since(signal, stream);
  1809. };
  1810. var during$1 = function during(timeWindow, stream) {
  1811. return until$1(join(timeWindow), since$1(timeWindow, stream));
  1812. };
  1813. var Until = /*#__PURE__*/function () {
  1814. function Until(maxSignal, source) {
  1815. classCallCheck(this, Until);
  1816. this.maxSignal = maxSignal;
  1817. this.source = source;
  1818. }
  1819. Until.prototype.run = function run(sink, scheduler$$1) {
  1820. var disposable$$1 = new SettableDisposable();
  1821. var d1 = this.source.run(sink, scheduler$$1);
  1822. var d2 = this.maxSignal.run(new UntilSink(sink, disposable$$1), scheduler$$1);
  1823. disposable$$1.setDisposable(disposeBoth(d1, d2));
  1824. return disposable$$1;
  1825. };
  1826. return Until;
  1827. }();
  1828. var Since = /*#__PURE__*/function () {
  1829. function Since(minSignal, source) {
  1830. classCallCheck(this, Since);
  1831. this.minSignal = minSignal;
  1832. this.source = source;
  1833. }
  1834. Since.prototype.run = function run(sink, scheduler$$1) {
  1835. var min = new LowerBoundSink(this.minSignal, sink, scheduler$$1);
  1836. var d = this.source.run(new SinceSink(min, sink), scheduler$$1);
  1837. return disposeBoth(min, d);
  1838. };
  1839. return Since;
  1840. }();
  1841. var SinceSink = /*#__PURE__*/function (_Pipe) {
  1842. inherits(SinceSink, _Pipe);
  1843. function SinceSink(min, sink) {
  1844. classCallCheck(this, SinceSink);
  1845. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  1846. _this.min = min;
  1847. return _this;
  1848. }
  1849. SinceSink.prototype.event = function event(t, x) {
  1850. if (this.min.allow) {
  1851. this.sink.event(t, x);
  1852. }
  1853. };
  1854. return SinceSink;
  1855. }(Pipe);
  1856. var LowerBoundSink = /*#__PURE__*/function (_Pipe2) {
  1857. inherits(LowerBoundSink, _Pipe2);
  1858. function LowerBoundSink(signal, sink, scheduler$$1) {
  1859. classCallCheck(this, LowerBoundSink);
  1860. var _this2 = possibleConstructorReturn(this, _Pipe2.call(this, sink));
  1861. _this2.allow = false;
  1862. _this2.disposable = signal.run(_this2, scheduler$$1);
  1863. return _this2;
  1864. }
  1865. LowerBoundSink.prototype.event = function event() /* t, x */{
  1866. this.allow = true;
  1867. this.dispose();
  1868. };
  1869. LowerBoundSink.prototype.end = function end() {};
  1870. LowerBoundSink.prototype.dispose = function dispose() {
  1871. this.disposable.dispose();
  1872. };
  1873. return LowerBoundSink;
  1874. }(Pipe);
  1875. var UntilSink = /*#__PURE__*/function (_Pipe3) {
  1876. inherits(UntilSink, _Pipe3);
  1877. function UntilSink(sink, disposable$$1) {
  1878. classCallCheck(this, UntilSink);
  1879. var _this3 = possibleConstructorReturn(this, _Pipe3.call(this, sink));
  1880. _this3.disposable = disposable$$1;
  1881. return _this3;
  1882. }
  1883. UntilSink.prototype.event = function event(t, x) {
  1884. this.disposable.dispose();
  1885. this.sink.end(t);
  1886. };
  1887. UntilSink.prototype.end = function end() {};
  1888. return UntilSink;
  1889. }(Pipe);
  1890. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  1891. /** @author Brian Cavalier */
  1892. /** @author John Hann */
  1893. /**
  1894. * @param {Number} delayTime milliseconds to delay each item
  1895. * @param {Stream} stream
  1896. * @returns {Stream} new stream containing the same items, but delayed by ms
  1897. */
  1898. var delay$2 = function delay$$1(delayTime, stream) {
  1899. return delayTime <= 0 ? stream : new Delay(delayTime, stream);
  1900. };
  1901. var Delay = /*#__PURE__*/function () {
  1902. function Delay(dt, source) {
  1903. classCallCheck(this, Delay);
  1904. this.dt = dt;
  1905. this.source = source;
  1906. }
  1907. Delay.prototype.run = function run(sink, scheduler$$1) {
  1908. var delaySink = new DelaySink(this.dt, sink, scheduler$$1);
  1909. return disposeBoth(delaySink, this.source.run(delaySink, scheduler$$1));
  1910. };
  1911. return Delay;
  1912. }();
  1913. var DelaySink = /*#__PURE__*/function (_Pipe) {
  1914. inherits(DelaySink, _Pipe);
  1915. function DelaySink(dt, sink, scheduler$$1) {
  1916. classCallCheck(this, DelaySink);
  1917. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  1918. _this.dt = dt;
  1919. _this.scheduler = scheduler$$1;
  1920. _this.tasks = [];
  1921. return _this;
  1922. }
  1923. DelaySink.prototype.dispose = function dispose() {
  1924. this.tasks.forEach(cancelTask);
  1925. };
  1926. DelaySink.prototype.event = function event(t, x) {
  1927. this.tasks.push(delay(this.dt, propagateEventTask$1(x, this.sink), this.scheduler));
  1928. };
  1929. DelaySink.prototype.end = function end(t) {
  1930. this.tasks.push(delay(this.dt, propagateEndTask(this.sink), this.scheduler));
  1931. };
  1932. return DelaySink;
  1933. }(Pipe);
  1934. /** @license MIT License (c) copyright 2010-2017 original author or authors */
  1935. /**
  1936. * Limit the rate of events by suppressing events that occur too often
  1937. * @param {Number} period time to suppress events
  1938. * @param {Stream} stream
  1939. * @returns {Stream}
  1940. */
  1941. var throttle$1 = function throttle(period, stream) {
  1942. return isCanonicalEmpty(stream) ? empty() : stream instanceof Map ? commuteMapThrottle(period, stream) : stream instanceof Throttle ? fuseThrottle(period, stream) : new Throttle(period, stream);
  1943. };
  1944. var commuteMapThrottle = function commuteMapThrottle(period, mapStream) {
  1945. return Map.create(mapStream.f, throttle$1(period, mapStream.source));
  1946. };
  1947. var fuseThrottle = function fuseThrottle(period, throttleStream) {
  1948. return new Throttle(Math.max(period, throttleStream.period), throttleStream.source);
  1949. };
  1950. var Throttle = /*#__PURE__*/function () {
  1951. function Throttle(period, source) {
  1952. classCallCheck(this, Throttle);
  1953. this.period = period;
  1954. this.source = source;
  1955. }
  1956. Throttle.prototype.run = function run(sink, scheduler$$1) {
  1957. return this.source.run(new ThrottleSink(this.period, sink), scheduler$$1);
  1958. };
  1959. return Throttle;
  1960. }();
  1961. var ThrottleSink = /*#__PURE__*/function (_Pipe) {
  1962. inherits(ThrottleSink, _Pipe);
  1963. function ThrottleSink(period, sink) {
  1964. classCallCheck(this, ThrottleSink);
  1965. var _this = possibleConstructorReturn(this, _Pipe.call(this, sink));
  1966. _this.time = 0;
  1967. _this.period = period;
  1968. return _this;
  1969. }
  1970. ThrottleSink.prototype.event = function event(t, x) {
  1971. if (t >= this.time) {
  1972. this.time = t + this.period;
  1973. this.sink.event(t, x);
  1974. }
  1975. };
  1976. return ThrottleSink;
  1977. }(Pipe);
  1978. /**
  1979. * Wait for a burst of events to subside and emit only the last event in the burst
  1980. * @param {Number} period events occuring more frequently than this
  1981. * will be suppressed
  1982. * @param {Stream} stream stream to debounce
  1983. * @returns {Stream} new debounced stream
  1984. */
  1985. var debounce$1 = function debounce(period, stream) {
  1986. return isCanonicalEmpty(stream) ? empty() : new Debounce(period, stream);
  1987. };
  1988. var Debounce = /*#__PURE__*/function () {
  1989. function Debounce(dt, source) {
  1990. classCallCheck(this, Debounce);
  1991. this.dt = dt;
  1992. this.source = source;
  1993. }
  1994. Debounce.prototype.run = function run(sink, scheduler$$1) {
  1995. return new DebounceSink(this.dt, this.source, sink, scheduler$$1);
  1996. };
  1997. return Debounce;
  1998. }();
  1999. var DebounceSink = /*#__PURE__*/function () {
  2000. function DebounceSink(dt, source, sink, scheduler$$1) {
  2001. classCallCheck(this, DebounceSink);
  2002. this.dt = dt;
  2003. this.sink = sink;
  2004. this.scheduler = scheduler$$1;
  2005. this.value = void 0;
  2006. this.timer = null;
  2007. this.disposable = source.run(this, scheduler$$1);
  2008. }
  2009. DebounceSink.prototype.event = function event(t, x) {
  2010. this._clearTimer();
  2011. this.value = x;
  2012. this.timer = delay(this.dt, new DebounceTask(this, x), this.scheduler);
  2013. };
  2014. DebounceSink.prototype._event = function _event(t, x) {
  2015. this._clearTimer();
  2016. this.sink.event(t, x);
  2017. };
  2018. DebounceSink.prototype.end = function end(t) {
  2019. if (this._clearTimer()) {
  2020. this.sink.event(t, this.value);
  2021. this.value = undefined;
  2022. }
  2023. this.sink.end(t);
  2024. };
  2025. DebounceSink.prototype.error = function error(t, x) {
  2026. this._clearTimer();
  2027. this.sink.error(t, x);
  2028. };
  2029. DebounceSink.prototype.dispose = function dispose() {
  2030. this._clearTimer();
  2031. this.disposable.dispose();
  2032. };
  2033. DebounceSink.prototype._clearTimer = function _clearTimer() {
  2034. if (this.timer === null) {
  2035. return false;
  2036. }
  2037. this.timer.dispose();
  2038. this.timer = null;
  2039. return true;
  2040. };
  2041. return DebounceSink;
  2042. }();
  2043. var DebounceTask = /*#__PURE__*/function () {
  2044. function DebounceTask(debounce, value) {
  2045. classCallCheck(this, DebounceTask);
  2046. this.debounce = debounce;
  2047. this.value = value;
  2048. }
  2049. DebounceTask.prototype.run = function run(t) {
  2050. this.debounce._event(t, this.value);
  2051. };
  2052. DebounceTask.prototype.error = function error(t, e) {
  2053. this.debounce.error(t, e);
  2054. };
  2055. DebounceTask.prototype.dispose = function dispose() {};
  2056. return DebounceTask;
  2057. }();
  2058. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  2059. /** @author Brian Cavalier */
  2060. /** @author John Hann */
  2061. /**
  2062. * Turn a Stream<Promise<T>> into Stream<T> by awaiting each promise.
  2063. * Event order is preserved. The stream will fail if any promise rejects.
  2064. */
  2065. var awaitPromises = function awaitPromises(stream) {
  2066. return isCanonicalEmpty(stream) ? empty() : new Await(stream);
  2067. };
  2068. /**
  2069. * Create a stream containing only the promise's fulfillment
  2070. * value at the time it fulfills.
  2071. * @param {Promise<T>} p promise
  2072. * @return {Stream<T>} stream containing promise's fulfillment value.
  2073. * If the promise rejects, the stream will error
  2074. */
  2075. var fromPromise = /*#__PURE__*/compose(awaitPromises, now);
  2076. var Await = /*#__PURE__*/function () {
  2077. function Await(source) {
  2078. classCallCheck(this, Await);
  2079. this.source = source;
  2080. }
  2081. Await.prototype.run = function run(sink, scheduler$$1) {
  2082. return this.source.run(new AwaitSink(sink, scheduler$$1), scheduler$$1);
  2083. };
  2084. return Await;
  2085. }();
  2086. var AwaitSink = /*#__PURE__*/function () {
  2087. function AwaitSink(sink, scheduler$$1) {
  2088. var _this = this;
  2089. classCallCheck(this, AwaitSink);
  2090. this.sink = sink;
  2091. this.scheduler = scheduler$$1;
  2092. this.queue = Promise.resolve();
  2093. // Pre-create closures, to avoid creating them per event
  2094. this._eventBound = function (x) {
  2095. return _this.sink.event(currentTime(_this.scheduler), x);
  2096. };
  2097. this._endBound = function () {
  2098. return _this.sink.end(currentTime(_this.scheduler));
  2099. };
  2100. this._errorBound = function (e) {
  2101. return _this.sink.error(currentTime(_this.scheduler), e);
  2102. };
  2103. }
  2104. AwaitSink.prototype.event = function event(t, promise) {
  2105. var _this2 = this;
  2106. this.queue = this.queue.then(function () {
  2107. return _this2._event(promise);
  2108. }).catch(this._errorBound);
  2109. };
  2110. AwaitSink.prototype.end = function end(t) {
  2111. this.queue = this.queue.then(this._endBound).catch(this._errorBound);
  2112. };
  2113. AwaitSink.prototype.error = function error(t, e) {
  2114. var _this3 = this;
  2115. // Don't resolve error values, propagate directly
  2116. this.queue = this.queue.then(function () {
  2117. return _this3._errorBound(e);
  2118. }).catch(fatalError);
  2119. };
  2120. AwaitSink.prototype._event = function _event(promise) {
  2121. return promise.then(this._eventBound);
  2122. };
  2123. return AwaitSink;
  2124. }();
  2125. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  2126. /** @author Brian Cavalier */
  2127. /** @author John Hann */
  2128. var SafeSink = /*#__PURE__*/function () {
  2129. function SafeSink(sink) {
  2130. classCallCheck(this, SafeSink);
  2131. this.sink = sink;
  2132. this.active = true;
  2133. }
  2134. SafeSink.prototype.event = function event(t, x) {
  2135. if (!this.active) {
  2136. return;
  2137. }
  2138. this.sink.event(t, x);
  2139. };
  2140. SafeSink.prototype.end = function end(t, x) {
  2141. if (!this.active) {
  2142. return;
  2143. }
  2144. this.disable();
  2145. this.sink.end(t, x);
  2146. };
  2147. SafeSink.prototype.error = function error(t, e) {
  2148. this.disable();
  2149. this.sink.error(t, e);
  2150. };
  2151. SafeSink.prototype.disable = function disable() {
  2152. this.active = false;
  2153. return this.sink;
  2154. };
  2155. return SafeSink;
  2156. }();
  2157. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  2158. /** @author Brian Cavalier */
  2159. /** @author John Hann */
  2160. function tryEvent(t, x, sink) {
  2161. try {
  2162. sink.event(t, x);
  2163. } catch (e) {
  2164. sink.error(t, e);
  2165. }
  2166. }
  2167. function tryEnd(t, sink) {
  2168. try {
  2169. sink.end(t);
  2170. } catch (e) {
  2171. sink.error(t, e);
  2172. }
  2173. }
  2174. /** @license MIT License (c) copyright 2010-2016 original author or authors */
  2175. /** @author Brian Cavalier */
  2176. /** @author John Hann */
  2177. /**
  2178. * If stream encounters an error, recover and continue with items from stream
  2179. * returned by f.
  2180. * @param {function(error:*):Stream} f function which returns a new stream
  2181. * @param {Stream} stream
  2182. * @returns {Stream} new stream which will recover from an error by calling f
  2183. */
  2184. var recoverWith$1 = function recoverWith(f, stream) {
  2185. return isCanonicalEmpty(stream) ? empty() : new RecoverWith(f, stream);
  2186. };
  2187. /**
  2188. * Create a stream containing only an error
  2189. * @param {*} e error value, preferably an Error or Error subtype
  2190. * @returns {Stream} new stream containing only an error
  2191. */
  2192. var throwError = function throwError(e) {
  2193. return new ErrorStream(e);
  2194. };
  2195. var ErrorStream = /*#__PURE__*/function () {
  2196. function ErrorStream(e) {
  2197. classCallCheck(this, ErrorStream);
  2198. this.value = e;
  2199. }
  2200. ErrorStream.prototype.run = function run(sink, scheduler$$1) {
  2201. return asap(propagateErrorTask$1(this.value, sink), scheduler$$1);
  2202. };
  2203. return ErrorStream;
  2204. }();
  2205. var RecoverWith = /*#__PURE__*/function () {
  2206. function RecoverWith(f, source) {
  2207. classCallCheck(this, RecoverWith);
  2208. this.f = f;
  2209. this.source = source;
  2210. }
  2211. RecoverWith.prototype.run = function run(sink, scheduler$$1) {
  2212. return new RecoverWithSink(this.f, this.source, sink, scheduler$$1);
  2213. };
  2214. return RecoverWith;
  2215. }();
  2216. var RecoverWithSink = /*#__PURE__*/function () {
  2217. function RecoverWithSink(f, source, sink, scheduler$$1) {
  2218. classCallCheck(this, RecoverWithSink);
  2219. this.f = f;
  2220. this.sink = new SafeSink(sink);
  2221. this.scheduler = scheduler$$1;
  2222. this.disposable = source.run(this, scheduler$$1);
  2223. }
  2224. RecoverWithSink.prototype.event = function event(t, x) {
  2225. tryEvent(t, x, this.sink);
  2226. };
  2227. RecoverWithSink.prototype.end = function end(t) {
  2228. tryEnd(t, this.sink);
  2229. };
  2230. RecoverWithSink.prototype.error = function error(t, e) {
  2231. var nextSink = this.sink.disable();
  2232. tryDispose(t, this.disposable, this.sink);
  2233. this._startNext(t, e, nextSink);
  2234. };
  2235. RecoverWithSink.prototype._startNext = function _startNext(t, x, sink) {
  2236. try {
  2237. this.disposable = this._continue(this.f, t, x, sink);
  2238. } catch (e) {
  2239. sink.error(t, e);
  2240. }
  2241. };
  2242. RecoverWithSink.prototype._continue = function _continue(f, t, x, sink) {
  2243. return run$1(sink, this.scheduler, withLocalTime$1(t, f(x)));
  2244. };
  2245. RecoverWithSink.prototype.dispose = function dispose() {
  2246. return this.disposable.dispose();
  2247. };
  2248. return RecoverWithSink;
  2249. }();
  2250. var multicast = function multicast(stream) {
  2251. return stream instanceof Multicast || isCanonicalEmpty(stream) ? stream : new Multicast(stream);
  2252. };
  2253. var Multicast = /*#__PURE__*/function () {
  2254. function Multicast(source) {
  2255. classCallCheck(this, Multicast);
  2256. this.source = new MulticastSource(source);
  2257. }
  2258. Multicast.prototype.run = function run(sink, scheduler$$1) {
  2259. return this.source.run(sink, scheduler$$1);
  2260. };
  2261. return Multicast;
  2262. }();
  2263. var MulticastSource = /*#__PURE__*/function () {
  2264. function MulticastSource(source) {
  2265. classCallCheck(this, MulticastSource);
  2266. this.source = source;
  2267. this.sinks = [];
  2268. this.disposable = disposeNone();
  2269. }
  2270. MulticastSource.prototype.run = function run(sink, scheduler$$1) {
  2271. var n = this.add(sink);
  2272. if (n === 1) {
  2273. this.disposable = this.source.run(this, scheduler$$1);
  2274. }
  2275. return disposeOnce(new MulticastDisposable(this, sink));
  2276. };
  2277. MulticastSource.prototype.dispose = function dispose() {
  2278. var disposable$$1 = this.disposable;
  2279. this.disposable = disposeNone();
  2280. return disposable$$1.dispose();
  2281. };
  2282. MulticastSource.prototype.add = function add(sink) {
  2283. this.sinks = append(sink, this.sinks);
  2284. return this.sinks.length;
  2285. };
  2286. MulticastSource.prototype.remove = function remove$$1(sink) {
  2287. var i = findIndex(sink, this.sinks);
  2288. // istanbul ignore next
  2289. if (i >= 0) {
  2290. this.sinks = remove(i, this.sinks);
  2291. }
  2292. return this.sinks.length;
  2293. };
  2294. MulticastSource.prototype.event = function event(time, value) {
  2295. var s = this.sinks;
  2296. if (s.length === 1) {
  2297. return s[0].event(time, value);
  2298. }
  2299. for (var i = 0; i < s.length; ++i) {
  2300. tryEvent(time, value, s[i]);
  2301. }
  2302. };
  2303. MulticastSource.prototype.end = function end(time) {
  2304. var s = this.sinks;
  2305. for (var i = 0; i < s.length; ++i) {
  2306. tryEnd(time, s[i]);
  2307. }
  2308. };
  2309. MulticastSource.prototype.error = function error(time, err) {
  2310. var s = this.sinks;
  2311. for (var i = 0; i < s.length; ++i) {
  2312. s[i].error(time, err);
  2313. }
  2314. };
  2315. return MulticastSource;
  2316. }();
  2317. var MulticastDisposable = /*#__PURE__*/function () {
  2318. function MulticastDisposable(source, sink) {
  2319. classCallCheck(this, MulticastDisposable);
  2320. this.source = source;
  2321. this.sink = sink;
  2322. }
  2323. MulticastDisposable.prototype.dispose = function dispose() {
  2324. if (this.source.remove(this.sink) === 0) {
  2325. this.source.dispose();
  2326. }
  2327. };
  2328. return MulticastDisposable;
  2329. }();
  2330. /** @license MIT License (c) copyright 2016 original author or authors */
  2331. /* eslint-disable import/first */
  2332. var zipItems$$1 = /*#__PURE__*/curry3(zipItems$1);
  2333. var withItems$$1 = /*#__PURE__*/curry2(withItems$1);
  2334. // -----------------------------------------------------------------------
  2335. // Observing
  2336. var runEffects$$1 = /*#__PURE__*/curry2(runEffects$1);
  2337. var run$$1 = /*#__PURE__*/curry3(run$1);
  2338. // -------------------------------------------------------
  2339. var withLocalTime$$1 = /*#__PURE__*/curry2(withLocalTime$1);
  2340. // -------------------------------------------------------
  2341. var loop$$1 = /*#__PURE__*/curry3(loop$1);
  2342. // -------------------------------------------------------
  2343. var scan$$1 = /*#__PURE__*/curry3(scan$1);
  2344. // -----------------------------------------------------------------------
  2345. // Extending
  2346. var startWith$$1 = /*#__PURE__*/curry2(startWith$1);
  2347. // -----------------------------------------------------------------------
  2348. // Transforming
  2349. var map$1 = /*#__PURE__*/curry2(map$2);
  2350. var constant$$1 = /*#__PURE__*/curry2(constant$1);
  2351. var tap$$1 = /*#__PURE__*/curry2(tap$1);
  2352. var ap$$1 = /*#__PURE__*/curry2(ap$1);
  2353. // -----------------------------------------------------------------------
  2354. // FlatMapping
  2355. var chain$$1 = /*#__PURE__*/curry2(chain$1);
  2356. var continueWith$$1 = /*#__PURE__*/curry2(continueWith$1);
  2357. var concatMap$$1 = /*#__PURE__*/curry2(concatMap$1);
  2358. // -----------------------------------------------------------------------
  2359. // Concurrent merging
  2360. var mergeConcurrently$$1 = /*#__PURE__*/curry2(mergeConcurrently$1);
  2361. var mergeMapConcurrently$$1 = /*#__PURE__*/curry3(mergeMapConcurrently$1);
  2362. // -----------------------------------------------------------------------
  2363. // Merging
  2364. var merge$$1 = /*#__PURE__*/curry2(merge$1);
  2365. // -----------------------------------------------------------------------
  2366. // Combining
  2367. var combine$$1 = /*#__PURE__*/curry3(combine$1);
  2368. var combineArray$$1 = /*#__PURE__*/curry2(combineArray$1);
  2369. // -----------------------------------------------------------------------
  2370. // Sampling
  2371. var sample$$1 = /*#__PURE__*/curry2(sample$1);
  2372. var snapshot$$1 = /*#__PURE__*/curry3(snapshot$1);
  2373. // -----------------------------------------------------------------------
  2374. // Zipping
  2375. var zip$$1 = /*#__PURE__*/curry3(zip$1);
  2376. var zipArray$$1 = /*#__PURE__*/curry2(zipArray$1);
  2377. // -----------------------------------------------------------------------
  2378. // Filtering
  2379. var filter$$1 = /*#__PURE__*/curry2(filter$1);
  2380. var skipRepeatsWith$$1 = /*#__PURE__*/curry2(skipRepeatsWith$1);
  2381. // -----------------------------------------------------------------------
  2382. // Slicing
  2383. var take$$1 = /*#__PURE__*/curry2(take$1);
  2384. var skip$$1 = /*#__PURE__*/curry2(skip$1);
  2385. var slice$$1 = /*#__PURE__*/curry3(slice$1);
  2386. var takeWhile$$1 = /*#__PURE__*/curry2(takeWhile$1);
  2387. var skipWhile$$1 = /*#__PURE__*/curry2(skipWhile$1);
  2388. var skipAfter$$1 = /*#__PURE__*/curry2(skipAfter$1);
  2389. // -----------------------------------------------------------------------
  2390. // Time slicing
  2391. var until$$1 = /*#__PURE__*/curry2(until$1);
  2392. var since$$1 = /*#__PURE__*/curry2(since$1);
  2393. var during$$1 = /*#__PURE__*/curry2(during$1);
  2394. // -----------------------------------------------------------------------
  2395. // Delaying
  2396. var delay$1 = /*#__PURE__*/curry2(delay$2);
  2397. // -----------------------------------------------------------------------
  2398. // Rate limiting
  2399. var throttle$$1 = /*#__PURE__*/curry2(throttle$1);
  2400. var debounce$$1 = /*#__PURE__*/curry2(debounce$1);
  2401. // -----------------------------------------------------------------------
  2402. // Error handling
  2403. var recoverWith$$1 = /*#__PURE__*/curry2(recoverWith$1);
  2404. // ----------------------------------------------------------------------
  2405. var propagateTask$$1 = /*#__PURE__*/curry3(propagateTask$1);
  2406. var propagateEventTask$$1 = /*#__PURE__*/curry2(propagateEventTask$1);
  2407. var propagateErrorTask$$1 = /*#__PURE__*/curry2(propagateErrorTask$1);
  2408. export { zipItems$$1 as zipItems, withItems$$1 as withItems, runEffects$$1 as runEffects, run$$1 as run, withLocalTime$$1 as withLocalTime, loop$$1 as loop, scan$$1 as scan, startWith$$1 as startWith, map$1 as map, constant$$1 as constant, tap$$1 as tap, ap$$1 as ap, chain$$1 as chain, join, continueWith$$1 as continueWith, concatMap$$1 as concatMap, mergeConcurrently$$1 as mergeConcurrently, mergeMapConcurrently$$1 as mergeMapConcurrently, merge$$1 as merge, mergeArray, combine$$1 as combine, combineArray$$1 as combineArray, sample$$1 as sample, snapshot$$1 as snapshot, zip$$1 as zip, zipArray$$1 as zipArray, filter$$1 as filter, skipRepeats, skipRepeatsWith$$1 as skipRepeatsWith, take$$1 as take, skip$$1 as skip, slice$$1 as slice, takeWhile$$1 as takeWhile, skipWhile$$1 as skipWhile, skipAfter$$1 as skipAfter, until$$1 as until, since$$1 as since, during$$1 as during, delay$1 as delay, throttle$$1 as throttle, debounce$$1 as debounce, recoverWith$$1 as recoverWith, throwError, propagateTask$$1 as propagateTask, propagateEventTask$$1 as propagateEventTask, propagateErrorTask$$1 as propagateErrorTask, propagateEndTask, empty, never, now, at, periodic$1 as periodic, newStream, switchLatest, fromPromise, awaitPromises, multicast, MulticastSource };
  2409. //# sourceMappingURL=index.es.js.map