1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.PropagateTask = exports.defaultScheduler = exports.multicast = exports.throwError = exports.flatMapError = exports.recoverWith = exports.await = exports.awaitPromises = exports.fromPromise = exports.debounce = exports.throttle = exports.timestamp = exports.delay = exports.during = exports.since = exports.skipUntil = exports.until = exports.takeUntil = exports.skipAfter = exports.skipWhile = exports.takeWhile = exports.slice = exports.skip = exports.take = exports.distinctBy = exports.skipRepeatsWith = exports.distinct = exports.skipRepeats = exports.filter = exports.switch = exports.switchLatest = exports.zipArray = exports.zip = exports.sampleWith = exports.sampleArray = exports.sample = exports.combineArray = exports.combine = exports.mergeArray = exports.merge = exports.mergeConcurrently = exports.concatMap = exports.flatMapEnd = exports.continueWith = exports.join = exports.chain = exports.flatMap = exports.transduce = exports.ap = exports.tap = exports.constant = exports.map = exports.startWith = exports.concat = exports.generate = exports.iterate = exports.unfold = exports.reduce = exports.scan = exports.loop = exports.drain = exports.forEach = exports.observe = exports.fromEvent = exports.periodic = exports.from = exports.never = exports.empty = exports.just = exports.of = exports.Stream = undefined;
|
7 |
|
8 | var _fromEvent = require('./source/fromEvent');
|
9 |
|
10 | Object.defineProperty(exports, 'fromEvent', {
|
11 | enumerable: true,
|
12 | get: function () {
|
13 | return _fromEvent.fromEvent;
|
14 | }
|
15 | });
|
16 |
|
17 | var _unfold = require('./source/unfold');
|
18 |
|
19 | Object.defineProperty(exports, 'unfold', {
|
20 | enumerable: true,
|
21 | get: function () {
|
22 | return _unfold.unfold;
|
23 | }
|
24 | });
|
25 |
|
26 | var _iterate = require('./source/iterate');
|
27 |
|
28 | Object.defineProperty(exports, 'iterate', {
|
29 | enumerable: true,
|
30 | get: function () {
|
31 | return _iterate.iterate;
|
32 | }
|
33 | });
|
34 |
|
35 | var _generate = require('./source/generate');
|
36 |
|
37 | Object.defineProperty(exports, 'generate', {
|
38 | enumerable: true,
|
39 | get: function () {
|
40 | return _generate.generate;
|
41 | }
|
42 | });
|
43 |
|
44 | var _Stream = require('./Stream');
|
45 |
|
46 | var _Stream2 = _interopRequireDefault(_Stream);
|
47 |
|
48 | var _prelude = require('@most/prelude');
|
49 |
|
50 | var base = _interopRequireWildcard(_prelude);
|
51 |
|
52 | var _core = require('./source/core');
|
53 |
|
54 | var _from = require('./source/from');
|
55 |
|
56 | var _periodic = require('./source/periodic');
|
57 |
|
58 | var _symbolObservable = require('symbol-observable');
|
59 |
|
60 | var _symbolObservable2 = _interopRequireDefault(_symbolObservable);
|
61 |
|
62 | var _subscribe = require('./observable/subscribe');
|
63 |
|
64 | var _thru = require('./combinator/thru');
|
65 |
|
66 | var _observe = require('./combinator/observe');
|
67 |
|
68 | var _loop = require('./combinator/loop');
|
69 |
|
70 | var _accumulate = require('./combinator/accumulate');
|
71 |
|
72 | var _build = require('./combinator/build');
|
73 |
|
74 | var _transform = require('./combinator/transform');
|
75 |
|
76 | var _applicative = require('./combinator/applicative');
|
77 |
|
78 | var _transduce = require('./combinator/transduce');
|
79 |
|
80 | var _flatMap = require('./combinator/flatMap');
|
81 |
|
82 | var _continueWith = require('./combinator/continueWith');
|
83 |
|
84 | var _concatMap = require('./combinator/concatMap');
|
85 |
|
86 | var _mergeConcurrently = require('./combinator/mergeConcurrently');
|
87 |
|
88 | var _merge = require('./combinator/merge');
|
89 |
|
90 | var _combine = require('./combinator/combine');
|
91 |
|
92 | var _sample = require('./combinator/sample');
|
93 |
|
94 | var _zip = require('./combinator/zip');
|
95 |
|
96 | var _switch = require('./combinator/switch');
|
97 |
|
98 | var _filter = require('./combinator/filter');
|
99 |
|
100 | var _slice = require('./combinator/slice');
|
101 |
|
102 | var _timeslice = require('./combinator/timeslice');
|
103 |
|
104 | var _delay = require('./combinator/delay');
|
105 |
|
106 | var _timestamp = require('./combinator/timestamp');
|
107 |
|
108 | var _limit = require('./combinator/limit');
|
109 |
|
110 | var _promises = require('./combinator/promises');
|
111 |
|
112 | var _errors = require('./combinator/errors');
|
113 |
|
114 | var _multicast = require('@most/multicast');
|
115 |
|
116 | var _multicast2 = _interopRequireDefault(_multicast);
|
117 |
|
118 | var _defaultScheduler = require('./scheduler/defaultScheduler');
|
119 |
|
120 | var _defaultScheduler2 = _interopRequireDefault(_defaultScheduler);
|
121 |
|
122 | var _PropagateTask = require('./scheduler/PropagateTask');
|
123 |
|
124 | var _PropagateTask2 = _interopRequireDefault(_PropagateTask);
|
125 |
|
126 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }
|
127 |
|
128 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
129 |
|
130 | /**
|
131 | * Core stream type
|
132 | * @type {Stream}
|
133 | */
|
134 | /** @license MIT License (c) copyright 2010-2016 original author or authors */
|
135 | /** @author Brian Cavalier */
|
136 | /** @author John Hann */
|
137 |
|
138 | exports.Stream = _Stream2.default;
|
139 |
|
140 | // Add of and empty to constructor for fantasy-land compat
|
141 |
|
142 | _Stream2.default.of = _core.of;
|
143 | _Stream2.default.empty = _core.empty;
|
144 | // Add from to constructor for ES Observable compat
|
145 | _Stream2.default.from = _from.from;
|
146 | exports.of = _core.of;
|
147 | exports.just = _core.of;
|
148 | exports.empty = _core.empty;
|
149 | exports.never = _core.never;
|
150 | exports.from = _from.from;
|
151 | exports.periodic = _periodic.periodic;
|
152 |
|
153 | // -----------------------------------------------------------------------
|
154 | // Draft ES Observable proposal interop
|
155 | // https://github.com/zenparsing/es-observable
|
156 |
|
157 | _Stream2.default.prototype.subscribe = function (subscriber) {
|
158 | return (0, _subscribe.subscribe)(subscriber, this);
|
159 | };
|
160 |
|
161 | _Stream2.default.prototype[_symbolObservable2.default] = function () {
|
162 | return this;
|
163 | };
|
164 |
|
165 | // -----------------------------------------------------------------------
|
166 | // Fluent adapter
|
167 |
|
168 | /**
|
169 | * Adapt a functional stream transform to fluent style.
|
170 | * It applies f to the this stream object
|
171 | * @param {function(s: Stream): Stream} f function that
|
172 | * receives the stream itself and must return a new stream
|
173 | * @return {Stream}
|
174 | */
|
175 | _Stream2.default.prototype.thru = function (f) {
|
176 | return (0, _thru.thru)(f, this);
|
177 | };
|
178 |
|
179 | // -----------------------------------------------------------------------
|
180 | // Adapting other sources
|
181 |
|
182 | /**
|
183 | * Create a stream of events from the supplied EventTarget or EventEmitter
|
184 | * @param {String} event event name
|
185 | * @param {EventTarget|EventEmitter} source EventTarget or EventEmitter. The source
|
186 | * must support either addEventListener/removeEventListener (w3c EventTarget:
|
187 | * http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget),
|
188 | * or addListener/removeListener (node EventEmitter: http://nodejs.org/api/events.html)
|
189 | * @returns {Stream} stream of events of the specified type from the source
|
190 | */
|
191 |
|
192 |
|
193 | // -----------------------------------------------------------------------
|
194 | // Observing
|
195 |
|
196 | exports.observe = _observe.observe;
|
197 | exports.forEach = _observe.observe;
|
198 | exports.drain = _observe.drain;
|
199 |
|
200 | /**
|
201 | * Process all the events in the stream
|
202 | * @returns {Promise} promise that fulfills when the stream ends, or rejects
|
203 | * if the stream fails with an unhandled error.
|
204 | */
|
205 |
|
206 | _Stream2.default.prototype.observe = _Stream2.default.prototype.forEach = function (f) {
|
207 | return (0, _observe.observe)(f, this);
|
208 | };
|
209 |
|
210 | /**
|
211 | * Consume all events in the stream, without providing a function to process each.
|
212 | * This causes a stream to become active and begin emitting events, and is useful
|
213 | * in cases where all processing has been setup upstream via other combinators, and
|
214 | * there is no need to process the terminal events.
|
215 | * @returns {Promise} promise that fulfills when the stream ends, or rejects
|
216 | * if the stream fails with an unhandled error.
|
217 | */
|
218 | _Stream2.default.prototype.drain = function () {
|
219 | return (0, _observe.drain)(this);
|
220 | };
|
221 |
|
222 | // -------------------------------------------------------
|
223 |
|
224 | exports.loop = _loop.loop;
|
225 |
|
226 | /**
|
227 | * Generalized feedback loop. Call a stepper function for each event. The stepper
|
228 | * will be called with 2 params: the current seed and the an event value. It must
|
229 | * return a new { seed, value } pair. The `seed` will be fed back into the next
|
230 | * invocation of stepper, and the `value` will be propagated as the event value.
|
231 | * @param {function(seed:*, value:*):{seed:*, value:*}} stepper loop step function
|
232 | * @param {*} seed initial seed value passed to first stepper call
|
233 | * @returns {Stream} new stream whose values are the `value` field of the objects
|
234 | * returned by the stepper
|
235 | */
|
236 |
|
237 | _Stream2.default.prototype.loop = function (stepper, seed) {
|
238 | return (0, _loop.loop)(stepper, seed, this);
|
239 | };
|
240 |
|
241 | // -------------------------------------------------------
|
242 |
|
243 | exports.scan = _accumulate.scan;
|
244 | exports.reduce = _accumulate.reduce;
|
245 |
|
246 | /**
|
247 | * Create a stream containing successive reduce results of applying f to
|
248 | * the previous reduce result and the current stream item.
|
249 | * @param {function(result:*, x:*):*} f reducer function
|
250 | * @param {*} initial initial value
|
251 | * @returns {Stream} new stream containing successive reduce results
|
252 | */
|
253 |
|
254 | _Stream2.default.prototype.scan = function (f, initial) {
|
255 | return (0, _accumulate.scan)(f, initial, this);
|
256 | };
|
257 |
|
258 | /**
|
259 | * Reduce the stream to produce a single result. Note that reducing an infinite
|
260 | * stream will return a Promise that never fulfills, but that may reject if an error
|
261 | * occurs.
|
262 | * @param {function(result:*, x:*):*} f reducer function
|
263 | * @param {*} initial optional initial value
|
264 | * @returns {Promise} promise for the file result of the reduce
|
265 | */
|
266 | _Stream2.default.prototype.reduce = function (f, initial) {
|
267 | return (0, _accumulate.reduce)(f, initial, this);
|
268 | };
|
269 |
|
270 | // -----------------------------------------------------------------------
|
271 | // Building and extending
|
272 |
|
273 | exports.concat = _build.concat;
|
274 | exports.startWith = _build.cons;
|
275 |
|
276 | /**
|
277 | * @param {Stream} tail
|
278 | * @returns {Stream} new stream containing all items in this followed by
|
279 | * all items in tail
|
280 | */
|
281 |
|
282 | _Stream2.default.prototype.concat = function (tail) {
|
283 | return (0, _build.concat)(this, tail);
|
284 | };
|
285 |
|
286 | /**
|
287 | * @param {*} x value to prepend
|
288 | * @returns {Stream} a new stream with x prepended
|
289 | */
|
290 | _Stream2.default.prototype.startWith = function (x) {
|
291 | return (0, _build.cons)(x, this);
|
292 | };
|
293 |
|
294 | // -----------------------------------------------------------------------
|
295 | // Transforming
|
296 |
|
297 | exports.map = _transform.map;
|
298 | exports.constant = _transform.constant;
|
299 | exports.tap = _transform.tap;
|
300 | exports.ap = _applicative.ap;
|
301 |
|
302 | /**
|
303 | * Transform each value in the stream by applying f to each
|
304 | * @param {function(*):*} f mapping function
|
305 | * @returns {Stream} stream containing items transformed by f
|
306 | */
|
307 |
|
308 | _Stream2.default.prototype.map = function (f) {
|
309 | return (0, _transform.map)(f, this);
|
310 | };
|
311 |
|
312 | /**
|
313 | * Assume this stream contains functions, and apply each function to each item
|
314 | * in the provided stream. This generates, in effect, a cross product.
|
315 | * @param {Stream} xs stream of items to which
|
316 | * @returns {Stream} stream containing the cross product of items
|
317 | */
|
318 | _Stream2.default.prototype.ap = function (xs) {
|
319 | return (0, _applicative.ap)(this, xs);
|
320 | };
|
321 |
|
322 | /**
|
323 | * Replace each value in the stream with x
|
324 | * @param {*} x
|
325 | * @returns {Stream} stream containing items replaced with x
|
326 | */
|
327 | _Stream2.default.prototype.constant = function (x) {
|
328 | return (0, _transform.constant)(x, this);
|
329 | };
|
330 |
|
331 | /**
|
332 | * Perform a side effect for each item in the stream
|
333 | * @param {function(x:*):*} f side effect to execute for each item. The
|
334 | * return value will be discarded.
|
335 | * @returns {Stream} new stream containing the same items as this stream
|
336 | */
|
337 | _Stream2.default.prototype.tap = function (f) {
|
338 | return (0, _transform.tap)(f, this);
|
339 | };
|
340 |
|
341 | // -----------------------------------------------------------------------
|
342 | // Transducer support
|
343 |
|
344 | exports.transduce = _transduce.transduce;
|
345 |
|
346 | /**
|
347 | * Transform this stream by passing its events through a transducer.
|
348 | * @param {function} transducer transducer function
|
349 | * @return {Stream} stream of events transformed by the transducer
|
350 | */
|
351 |
|
352 | _Stream2.default.prototype.transduce = function (transducer) {
|
353 | return (0, _transduce.transduce)(transducer, this);
|
354 | };
|
355 |
|
356 | // -----------------------------------------------------------------------
|
357 | // FlatMapping
|
358 |
|
359 | // @deprecated flatMap, use chain instead
|
360 | exports.flatMap = _flatMap.flatMap;
|
361 | exports.chain = _flatMap.flatMap;
|
362 | exports.join = _flatMap.join;
|
363 |
|
364 | /**
|
365 | * Map each value in the stream to a new stream, and merge it into the
|
366 | * returned outer stream. Event arrival times are preserved.
|
367 | * @param {function(x:*):Stream} f chaining function, must return a Stream
|
368 | * @returns {Stream} new stream containing all events from each stream returned by f
|
369 | */
|
370 |
|
371 | _Stream2.default.prototype.chain = function (f) {
|
372 | return (0, _flatMap.flatMap)(f, this);
|
373 | };
|
374 |
|
375 | // @deprecated use chain instead
|
376 | _Stream2.default.prototype.flatMap = _Stream2.default.prototype.chain;
|
377 |
|
378 | /**
|
379 | * Monadic join. Flatten a Stream<Stream<X>> to Stream<X> by merging inner
|
380 | * streams to the outer. Event arrival times are preserved.
|
381 | * @returns {Stream<X>} new stream containing all events of all inner streams
|
382 | */
|
383 | _Stream2.default.prototype.join = function () {
|
384 | return (0, _flatMap.join)(this);
|
385 | };
|
386 |
|
387 | // @deprecated flatMapEnd, use continueWith instead
|
388 | exports.continueWith = _continueWith.continueWith;
|
389 | exports.flatMapEnd = _continueWith.continueWith;
|
390 |
|
391 | /**
|
392 | * Map the end event to a new stream, and begin emitting its values.
|
393 | * @param {function(x:*):Stream} f function that receives the end event value,
|
394 | * and *must* return a new Stream to continue with.
|
395 | * @returns {Stream} new stream that emits all events from the original stream,
|
396 | * followed by all events from the stream returned by f.
|
397 | */
|
398 |
|
399 | _Stream2.default.prototype.continueWith = function (f) {
|
400 | return (0, _continueWith.continueWith)(f, this);
|
401 | };
|
402 |
|
403 | // @deprecated use continueWith instead
|
404 | _Stream2.default.prototype.flatMapEnd = _Stream2.default.prototype.continueWith;
|
405 |
|
406 | exports.concatMap = _concatMap.concatMap;
|
407 |
|
408 |
|
409 | _Stream2.default.prototype.concatMap = function (f) {
|
410 | return (0, _concatMap.concatMap)(f, this);
|
411 | };
|
412 |
|
413 | // -----------------------------------------------------------------------
|
414 | // Concurrent merging
|
415 |
|
416 | exports.mergeConcurrently = _mergeConcurrently.mergeConcurrently;
|
417 |
|
418 | /**
|
419 | * Flatten a Stream<Stream<X>> to Stream<X> by merging inner
|
420 | * streams to the outer, limiting the number of inner streams that may
|
421 | * be active concurrently.
|
422 | * @param {number} concurrency at most this many inner streams will be
|
423 | * allowed to be active concurrently.
|
424 | * @return {Stream<X>} new stream containing all events of all inner
|
425 | * streams, with limited concurrency.
|
426 | */
|
427 |
|
428 | _Stream2.default.prototype.mergeConcurrently = function (concurrency) {
|
429 | return (0, _mergeConcurrently.mergeConcurrently)(concurrency, this);
|
430 | };
|
431 |
|
432 | // -----------------------------------------------------------------------
|
433 | // Merging
|
434 |
|
435 | exports.merge = _merge.merge;
|
436 | exports.mergeArray = _merge.mergeArray;
|
437 |
|
438 | /**
|
439 | * Merge this stream and all the provided streams
|
440 | * @returns {Stream} stream containing items from this stream and s in time
|
441 | * order. If two events are simultaneous they will be merged in
|
442 | * arbitrary order.
|
443 | */
|
444 |
|
445 | _Stream2.default.prototype.merge = function () /* ...streams*/{
|
446 | return (0, _merge.mergeArray)(base.cons(this, arguments));
|
447 | };
|
448 |
|
449 | // -----------------------------------------------------------------------
|
450 | // Combining
|
451 |
|
452 | exports.combine = _combine.combine;
|
453 | exports.combineArray = _combine.combineArray;
|
454 |
|
455 | /**
|
456 | * Combine latest events from all input streams
|
457 | * @param {function(...events):*} f function to combine most recent events
|
458 | * @returns {Stream} stream containing the result of applying f to the most recent
|
459 | * event of each input stream, whenever a new event arrives on any stream.
|
460 | */
|
461 |
|
462 | _Stream2.default.prototype.combine = function (f /*, ...streams*/) {
|
463 | return (0, _combine.combineArray)(f, base.replace(this, 0, arguments));
|
464 | };
|
465 |
|
466 | // -----------------------------------------------------------------------
|
467 | // Sampling
|
468 |
|
469 | exports.sample = _sample.sample;
|
470 | exports.sampleArray = _sample.sampleArray;
|
471 | exports.sampleWith = _sample.sampleWith;
|
472 |
|
473 | /**
|
474 | * When an event arrives on sampler, emit the latest event value from stream.
|
475 | * @param {Stream} sampler stream of events at whose arrival time
|
476 | * signal's latest value will be propagated
|
477 | * @returns {Stream} sampled stream of values
|
478 | */
|
479 |
|
480 | _Stream2.default.prototype.sampleWith = function (sampler) {
|
481 | return (0, _sample.sampleWith)(sampler, this);
|
482 | };
|
483 |
|
484 | /**
|
485 | * When an event arrives on this stream, emit the result of calling f with the latest
|
486 | * values of all streams being sampled
|
487 | * @param {function(...values):*} f function to apply to each set of sampled values
|
488 | * @returns {Stream} stream of sampled and transformed values
|
489 | */
|
490 | _Stream2.default.prototype.sample = function (f /* ...streams */) {
|
491 | return (0, _sample.sampleArray)(f, this, base.tail(arguments));
|
492 | };
|
493 |
|
494 | // -----------------------------------------------------------------------
|
495 | // Zipping
|
496 |
|
497 | exports.zip = _zip.zip;
|
498 | exports.zipArray = _zip.zipArray;
|
499 |
|
500 | /**
|
501 | * Pair-wise combine items with those in s. Given 2 streams:
|
502 | * [1,2,3] zipWith f [4,5,6] -> [f(1,4),f(2,5),f(3,6)]
|
503 | * Note: zip causes fast streams to buffer and wait for slow streams.
|
504 | * @param {function(a:Stream, b:Stream, ...):*} f function to combine items
|
505 | * @returns {Stream} new stream containing pairs
|
506 | */
|
507 |
|
508 | _Stream2.default.prototype.zip = function (f /*, ...streams*/) {
|
509 | return (0, _zip.zipArray)(f, base.replace(this, 0, arguments));
|
510 | };
|
511 |
|
512 | // -----------------------------------------------------------------------
|
513 | // Switching
|
514 |
|
515 | // @deprecated switch, use switchLatest instead
|
516 | exports.switchLatest = _switch.switchLatest;
|
517 | exports.switch = _switch.switchLatest;
|
518 |
|
519 | /**
|
520 | * Given a stream of streams, return a new stream that adopts the behavior
|
521 | * of the most recent inner stream.
|
522 | * @returns {Stream} switching stream
|
523 | */
|
524 |
|
525 | _Stream2.default.prototype.switchLatest = function () {
|
526 | return (0, _switch.switchLatest)(this);
|
527 | };
|
528 |
|
529 | // @deprecated use switchLatest instead
|
530 | _Stream2.default.prototype.switch = _Stream2.default.prototype.switchLatest;
|
531 |
|
532 | // -----------------------------------------------------------------------
|
533 | // Filtering
|
534 |
|
535 | // @deprecated distinct, use skipRepeats instead
|
536 | // @deprecated distinctBy, use skipRepeatsWith instead
|
537 | exports.filter = _filter.filter;
|
538 | exports.skipRepeats = _filter.skipRepeats;
|
539 | exports.distinct = _filter.skipRepeats;
|
540 | exports.skipRepeatsWith = _filter.skipRepeatsWith;
|
541 | exports.distinctBy = _filter.skipRepeatsWith;
|
542 |
|
543 | /**
|
544 | * Retain only items matching a predicate
|
545 | * stream: -12345678-
|
546 | * filter(x => x % 2 === 0, stream): --2-4-6-8-
|
547 | * @param {function(x:*):boolean} p filtering predicate called for each item
|
548 | * @returns {Stream} stream containing only items for which predicate returns truthy
|
549 | */
|
550 |
|
551 | _Stream2.default.prototype.filter = function (p) {
|
552 | return (0, _filter.filter)(p, this);
|
553 | };
|
554 |
|
555 | /**
|
556 | * Skip repeated events, using === to compare items
|
557 | * stream: -abbcd-
|
558 | * distinct(stream): -ab-cd-
|
559 | * @returns {Stream} stream with no repeated events
|
560 | */
|
561 | _Stream2.default.prototype.skipRepeats = function () {
|
562 | return (0, _filter.skipRepeats)(this);
|
563 | };
|
564 |
|
565 | /**
|
566 | * Skip repeated events, using supplied equals function to compare items
|
567 | * @param {function(a:*, b:*):boolean} equals function to compare items
|
568 | * @returns {Stream} stream with no repeated events
|
569 | */
|
570 | _Stream2.default.prototype.skipRepeatsWith = function (equals) {
|
571 | return (0, _filter.skipRepeatsWith)(equals, this);
|
572 | };
|
573 |
|
574 | // -----------------------------------------------------------------------
|
575 | // Slicing
|
576 |
|
577 | exports.take = _slice.take;
|
578 | exports.skip = _slice.skip;
|
579 | exports.slice = _slice.slice;
|
580 | exports.takeWhile = _slice.takeWhile;
|
581 | exports.skipWhile = _slice.skipWhile;
|
582 | exports.skipAfter = _slice.skipAfter;
|
583 |
|
584 | /**
|
585 | * stream: -abcd-
|
586 | * take(2, stream): -ab|
|
587 | * @param {Number} n take up to this many events
|
588 | * @returns {Stream} stream containing at most the first n items from this stream
|
589 | */
|
590 |
|
591 | _Stream2.default.prototype.take = function (n) {
|
592 | return (0, _slice.take)(n, this);
|
593 | };
|
594 |
|
595 | /**
|
596 | * stream: -abcd->
|
597 | * skip(2, stream): ---cd->
|
598 | * @param {Number} n skip this many events
|
599 | * @returns {Stream} stream not containing the first n events
|
600 | */
|
601 | _Stream2.default.prototype.skip = function (n) {
|
602 | return (0, _slice.skip)(n, this);
|
603 | };
|
604 |
|
605 | /**
|
606 | * Slice a stream by event index. Equivalent to, but more efficient than
|
607 | * stream.take(end).skip(start);
|
608 | * NOTE: Negative start and end are not supported
|
609 | * @param {Number} start skip all events before the start index
|
610 | * @param {Number} end allow all events from the start index to the end index
|
611 | * @returns {Stream} stream containing items where start <= index < end
|
612 | */
|
613 | _Stream2.default.prototype.slice = function (start, end) {
|
614 | return (0, _slice.slice)(start, end, this);
|
615 | };
|
616 |
|
617 | /**
|
618 | * stream: -123451234->
|
619 | * takeWhile(x => x < 5, stream): -1234|
|
620 | * @param {function(x:*):boolean} p predicate
|
621 | * @returns {Stream} stream containing items up to, but not including, the
|
622 | * first item for which p returns falsy.
|
623 | */
|
624 | _Stream2.default.prototype.takeWhile = function (p) {
|
625 | return (0, _slice.takeWhile)(p, this);
|
626 | };
|
627 |
|
628 | /**
|
629 | * stream: -123451234->
|
630 | * skipWhile(x => x < 5, stream): -----51234->
|
631 | * @param {function(x:*):boolean} p predicate
|
632 | * @returns {Stream} stream containing items following *and including* the
|
633 | * first item for which p returns falsy.
|
634 | */
|
635 | _Stream2.default.prototype.skipWhile = function (p) {
|
636 | return (0, _slice.skipWhile)(p, this);
|
637 | };
|
638 |
|
639 | /**
|
640 | * stream: -123456789->
|
641 | * skipAfter(x => x === 5, stream):-12345|
|
642 | * @param {function(x:*):boolean} p predicate
|
643 | * @returns {Stream} stream containing items up to, *and including*, the
|
644 | * first item for which p returns truthy.
|
645 | */
|
646 | _Stream2.default.prototype.skipAfter = function (p) {
|
647 | return (0, _slice.skipAfter)(p, this);
|
648 | };
|
649 |
|
650 | // -----------------------------------------------------------------------
|
651 | // Time slicing
|
652 |
|
653 | // @deprecated takeUntil, use until instead
|
654 | // @deprecated skipUntil, use since instead
|
655 | exports.takeUntil = _timeslice.takeUntil;
|
656 | exports.until = _timeslice.takeUntil;
|
657 | exports.skipUntil = _timeslice.skipUntil;
|
658 | exports.since = _timeslice.skipUntil;
|
659 | exports.during = _timeslice.during;
|
660 |
|
661 | /**
|
662 | * stream: -a-b-c-d-e-f-g->
|
663 | * signal: -------x
|
664 | * takeUntil(signal, stream): -a-b-c-|
|
665 | * @param {Stream} signal retain only events in stream before the first
|
666 | * event in signal
|
667 | * @returns {Stream} new stream containing only events that occur before
|
668 | * the first event in signal.
|
669 | */
|
670 |
|
671 | _Stream2.default.prototype.until = function (signal) {
|
672 | return (0, _timeslice.takeUntil)(signal, this);
|
673 | };
|
674 |
|
675 | // @deprecated use until instead
|
676 | _Stream2.default.prototype.takeUntil = _Stream2.default.prototype.until;
|
677 |
|
678 | /**
|
679 | * stream: -a-b-c-d-e-f-g->
|
680 | * signal: -------x
|
681 | * takeUntil(signal, stream): -------d-e-f-g->
|
682 | * @param {Stream} signal retain only events in stream at or after the first
|
683 | * event in signal
|
684 | * @returns {Stream} new stream containing only events that occur after
|
685 | * the first event in signal.
|
686 | */
|
687 | _Stream2.default.prototype.since = function (signal) {
|
688 | return (0, _timeslice.skipUntil)(signal, this);
|
689 | };
|
690 |
|
691 | // @deprecated use since instead
|
692 | _Stream2.default.prototype.skipUntil = _Stream2.default.prototype.since;
|
693 |
|
694 | /**
|
695 | * stream: -a-b-c-d-e-f-g->
|
696 | * timeWindow: -----s
|
697 | * s: -----t
|
698 | * stream.during(timeWindow): -----c-d-e-|
|
699 | * @param {Stream<Stream>} timeWindow a stream whose first event (s) represents
|
700 | * the window start time. That event (s) is itself a stream whose first event (t)
|
701 | * represents the window end time
|
702 | * @returns {Stream} new stream containing only events within the provided timespan
|
703 | */
|
704 | _Stream2.default.prototype.during = function (timeWindow) {
|
705 | return (0, _timeslice.during)(timeWindow, this);
|
706 | };
|
707 |
|
708 | // -----------------------------------------------------------------------
|
709 | // Delaying
|
710 |
|
711 | exports.delay = _delay.delay;
|
712 |
|
713 | /**
|
714 | * @param {Number} delayTime milliseconds to delay each item
|
715 | * @returns {Stream} new stream containing the same items, but delayed by ms
|
716 | */
|
717 |
|
718 | _Stream2.default.prototype.delay = function (delayTime) {
|
719 | return (0, _delay.delay)(delayTime, this);
|
720 | };
|
721 |
|
722 | // -----------------------------------------------------------------------
|
723 | // Getting event timestamp
|
724 |
|
725 | exports.timestamp = _timestamp.timestamp;
|
726 |
|
727 | /**
|
728 | * Expose event timestamps into the stream. Turns a Stream<X> into
|
729 | * Stream<{time:t, value:X}>
|
730 | * @returns {Stream<{time:number, value:*}>}
|
731 | */
|
732 |
|
733 | _Stream2.default.prototype.timestamp = function () {
|
734 | return (0, _timestamp.timestamp)(this);
|
735 | };
|
736 |
|
737 | // -----------------------------------------------------------------------
|
738 | // Rate limiting
|
739 |
|
740 | exports.throttle = _limit.throttle;
|
741 | exports.debounce = _limit.debounce;
|
742 |
|
743 | /**
|
744 | * Limit the rate of events
|
745 | * stream: abcd----abcd----
|
746 | * throttle(2, stream): a-c-----a-c-----
|
747 | * @param {Number} period time to suppress events
|
748 | * @returns {Stream} new stream that skips events for throttle period
|
749 | */
|
750 |
|
751 | _Stream2.default.prototype.throttle = function (period) {
|
752 | return (0, _limit.throttle)(period, this);
|
753 | };
|
754 |
|
755 | /**
|
756 | * Wait for a burst of events to subside and emit only the last event in the burst
|
757 | * stream: abcd----abcd----
|
758 | * debounce(2, stream): -----d-------d--
|
759 | * @param {Number} period events occuring more frequently than this
|
760 | * on the provided scheduler will be suppressed
|
761 | * @returns {Stream} new debounced stream
|
762 | */
|
763 | _Stream2.default.prototype.debounce = function (period) {
|
764 | return (0, _limit.debounce)(period, this);
|
765 | };
|
766 |
|
767 | // -----------------------------------------------------------------------
|
768 | // Awaiting Promises
|
769 |
|
770 | // @deprecated await, use awaitPromises instead
|
771 | exports.fromPromise = _promises.fromPromise;
|
772 | exports.awaitPromises = _promises.awaitPromises;
|
773 | exports.await = _promises.awaitPromises;
|
774 |
|
775 | /**
|
776 | * Await promises, turning a Stream<Promise<X>> into Stream<X>. Preserves
|
777 | * event order, but timeshifts events based on promise resolution time.
|
778 | * @returns {Stream<X>} stream containing non-promise values
|
779 | */
|
780 |
|
781 | _Stream2.default.prototype.awaitPromises = function () {
|
782 | return (0, _promises.awaitPromises)(this);
|
783 | };
|
784 |
|
785 | // @deprecated use awaitPromises instead
|
786 | _Stream2.default.prototype.await = _Stream2.default.prototype.awaitPromises;
|
787 |
|
788 | // -----------------------------------------------------------------------
|
789 | // Error handling
|
790 |
|
791 | // @deprecated flatMapError, use recoverWith instead
|
792 | exports.recoverWith = _errors.recoverWith;
|
793 | exports.flatMapError = _errors.flatMapError;
|
794 | exports.throwError = _errors.throwError;
|
795 |
|
796 | /**
|
797 | * If this stream encounters an error, recover and continue with items from stream
|
798 | * returned by f.
|
799 | * stream: -a-b-c-X-
|
800 | * f(X): d-e-f-g-
|
801 | * flatMapError(f, stream): -a-b-c-d-e-f-g-
|
802 | * @param {function(error:*):Stream} f function which returns a new stream
|
803 | * @returns {Stream} new stream which will recover from an error by calling f
|
804 | */
|
805 |
|
806 | _Stream2.default.prototype.recoverWith = function (f) {
|
807 | return (0, _errors.flatMapError)(f, this);
|
808 | };
|
809 |
|
810 | // @deprecated use recoverWith instead
|
811 | _Stream2.default.prototype.flatMapError = _Stream2.default.prototype.recoverWith;
|
812 |
|
813 | // -----------------------------------------------------------------------
|
814 | // Multicasting
|
815 |
|
816 | exports.multicast = _multicast2.default;
|
817 |
|
818 | /**
|
819 | * Transform the stream into multicast stream. That means that many subscribers
|
820 | * to the stream will not cause multiple invocations of the internal machinery.
|
821 | * @returns {Stream} new stream which will multicast events to all observers.
|
822 | */
|
823 |
|
824 | _Stream2.default.prototype.multicast = function () {
|
825 | return (0, _multicast2.default)(this);
|
826 | };
|
827 |
|
828 | // export the instance of the defaultScheduler for third-party libraries
|
829 | exports.defaultScheduler = _defaultScheduler2.default;
|
830 |
|
831 | // export an implementation of Task used internally for third-party libraries
|
832 |
|
833 | exports.PropagateTask = _PropagateTask2.default; |
\ | No newline at end of file |