import { Observable } from '../Observable'; import { SchedulerLike } from '../types'; export declare type ConditionFunc<S> = (state: S) => boolean; export declare type IterateFunc<S> = (state: S) => S; export declare type ResultFunc<S, T> = (state: S) => T; export interface GenerateBaseOptions<S> { /** * Initial state. */ initialState: S; /** * Condition function that accepts state and returns boolean. * When it returns false, the generator stops. * If not specified, a generator never stops. */ condition?: ConditionFunc<S>; /** * Iterate function that accepts state and returns new state. */ iterate: IterateFunc<S>; /** * SchedulerLike to use for generation process. * By default, a generator starts immediately. */ scheduler?: SchedulerLike; } export interface GenerateOptions<T, S> extends GenerateBaseOptions<S> { /** * Result selection function that accepts state and returns a value to emit. */ resultSelector: ResultFunc<S, T>; } /** * Generates an observable sequence by running a state-driven loop * producing the sequence's elements, using the specified scheduler * to send out observer messages. * *  * * @example <caption>Produces sequence of 0, 1, 2, ... 9, then completes.</caption> * const res = generate(0, x => x < 10, x => x + 1, x => x); * * @example <caption>Using asap scheduler, produces sequence of 2, 3, 5, then completes.</caption> * const res = generate(1, x => x < 5, x => x * 2, x => x + 1, asap); * * @see {@link from} * @see {@link Observable} * * @param {S} initialState Initial state. * @param {function (state: S): boolean} condition Condition to terminate generation (upon returning false). * @param {function (state: S): S} iterate Iteration step function. * @param {function (state: S): T} resultSelector Selector function for results produced in the sequence. (deprecated) * @param {SchedulerLike} [scheduler] A {@link SchedulerLike} on which to run the generator loop. If not provided, defaults to emit immediately. * @returns {Observable<T>} The generated sequence. */ export declare function generate<T, S>(initialState: S, condition: ConditionFunc<S>, iterate: IterateFunc<S>, resultSelector: ResultFunc<S, T>, scheduler?: SchedulerLike): Observable<T>; /** * Generates an Observable by running a state-driven loop * that emits an element on each iteration. * * <span class="informal">Use it instead of nexting values in a for loop.</span> * * <img src="./img/generate.png" width="100%"> * * `generate` allows you to create stream of values generated with a loop very similar to * traditional for loop. First argument of `generate` is a beginning value. Second argument * is a function that accepts this value and tests if some condition still holds. If it does, * loop continues, if not, it stops. Third value is a function which takes previously defined * value and modifies it in some way on each iteration. Note how these three parameters * are direct equivalents of three expressions in regular for loop: first expression * initializes some state (for example numeric index), second tests if loop can make next * iteration (for example if index is lower than 10) and third states how defined value * will be modified on every step (index will be incremented by one). * * Return value of a `generate` operator is an Observable that on each loop iteration * emits a value. First, condition function is ran. If it returned true, Observable * emits currently stored value (initial value at the first iteration) and then updates * that value with iterate function. If at some point condition returned false, Observable * completes at that moment. * * Optionally you can pass fourth parameter to `generate` - a result selector function which allows you * to immediately map value that would normally be emitted by an Observable. * * If you find three anonymous functions in `generate` call hard to read, you can provide * single object to the operator instead. That object has properties: `initialState`, * `condition`, `iterate` and `resultSelector`, which should have respective values that you * would normally pass to `generate`. `resultSelector` is still optional, but that form * of calling `generate` allows you to omit `condition` as well. If you omit it, that means * condition always holds, so output Observable will never complete. * * Both forms of `generate` can optionally accept a scheduler. In case of multi-parameter call, * scheduler simply comes as a last argument (no matter if there is resultSelector * function or not). In case of single-parameter call, you can provide it as a * `scheduler` property on object passed to the operator. In both cases scheduler decides when * next iteration of the loop will happen and therefore when next value will be emitted * by the Observable. For example to ensure that each value is pushed to the observer * on separate task in event loop, you could use `async` scheduler. Note that * by default (when no scheduler is passed) values are simply emitted synchronously. * * * @example <caption>Use with condition and iterate functions.</caption> * const generated = generate(0, x => x < 3, x => x + 1); * * generated.subscribe( * value => console.log(value), * err => {}, * () => console.log('Yo!') * ); * * // Logs: * // 0 * // 1 * // 2 * // "Yo!" * * * @example <caption>Use with condition, iterate and resultSelector functions.</caption> * const generated = generate(0, x => x < 3, x => x + 1, x => x * 1000); * * generated.subscribe( * value => console.log(value), * err => {}, * () => console.log('Yo!') * ); * * // Logs: * // 0 * // 1000 * // 2000 * // "Yo!" * * * @example <caption>Use with options object.</caption> * const generated = generate({ * initialState: 0, * condition(value) { return value < 3; }, * iterate(value) { return value + 1; }, * resultSelector(value) { return value * 1000; } * }); * * generated.subscribe( * value => console.log(value), * err => {}, * () => console.log('Yo!') * ); * * // Logs: * // 0 * // 1000 * // 2000 * // "Yo!" * * @example <caption>Use options object without condition function.</caption> * const generated = generate({ * initialState: 0, * iterate(value) { return value + 1; }, * resultSelector(value) { return value * 1000; } * }); * * generated.subscribe( * value => console.log(value), * err => {}, * () => console.log('Yo!') // This will never run. * ); * * // Logs: * // 0 * // 1000 * // 2000 * // 3000 * // ...and never stops. * * * @see {@link from} * @see {@link index/Observable.create} * * @param {S} initialState Initial state. * @param {function (state: S): boolean} condition Condition to terminate generation (upon returning false). * @param {function (state: S): S} iterate Iteration step function. * @param {function (state: S): T} [resultSelector] Selector function for results produced in the sequence. * @param {Scheduler} [scheduler] A {@link Scheduler} on which to run the generator loop. If not provided, defaults to emitting immediately. * @return {Observable<T>} The generated sequence. */ export declare function generate<S>(initialState: S, condition: ConditionFunc<S>, iterate: IterateFunc<S>, scheduler?: SchedulerLike): Observable<S>; /** * Generates an observable sequence by running a state-driven loop * producing the sequence's elements, using the specified scheduler * to send out observer messages. * The overload accepts options object that might contain initial state, iterate, * condition and scheduler. * *  * * @example <caption>Produces sequence of 0, 1, 2, ... 9, then completes.</caption> * const res = generate({ * initialState: 0, * condition: x => x < 10, * iterate: x => x + 1, * }); * * @see {@link from} * @see {@link Observable} * * @param {GenerateBaseOptions<S>} options Object that must contain initialState, iterate and might contain condition and scheduler. * @returns {Observable<S>} The generated sequence. */ export declare function generate<S>(options: GenerateBaseOptions<S>): Observable<S>; /** * Generates an observable sequence by running a state-driven loop * producing the sequence's elements, using the specified scheduler * to send out observer messages. * The overload accepts options object that might contain initial state, iterate, * condition, result selector and scheduler. * *  * * @example <caption>Produces sequence of 0, 1, 2, ... 9, then completes.</caption> * const res = generate({ * initialState: 0, * condition: x => x < 10, * iterate: x => x + 1, * resultSelector: x => x, * }); * * @see {@link from} * @see {@link Observable} * * @param {GenerateOptions<T, S>} options Object that must contain initialState, iterate, resultSelector and might contain condition and scheduler. * @returns {Observable<T>} The generated sequence. */ export declare function generate<T, S>(options: GenerateOptions<T, S>): Observable<T>;
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
dom | Folder | 0755 |
|
|
ConnectableObservable.d.ts | File | 907 B | 0644 |
|
ConnectableObservable.js | File | 5.84 KB | 0644 |
|
ConnectableObservable.js.map | File | 3.78 KB | 0644 |
|
SubscribeOnObservable.d.ts | File | 985 B | 0644 |
|
SubscribeOnObservable.js | File | 2.36 KB | 0644 |
|
SubscribeOnObservable.js.map | File | 1.24 KB | 0644 |
|
bindCallback.d.ts | File | 7.31 KB | 0644 |
|
bindCallback.js | File | 3.91 KB | 0644 |
|
bindCallback.js.map | File | 2.76 KB | 0644 |
|
bindNodeCallback.d.ts | File | 7.31 KB | 0644 |
|
bindNodeCallback.js | File | 4.37 KB | 0644 |
|
bindNodeCallback.js.map | File | 3.16 KB | 0644 |
|
combineLatest.d.ts | File | 14.21 KB | 0644 |
|
combineLatest.js | File | 4.28 KB | 0644 |
|
combineLatest.js.map | File | 2.89 KB | 0644 |
|
concat.d.ts | File | 4.77 KB | 0644 |
|
concat.js | File | 436 B | 0644 |
|
concat.js.map | File | 294 B | 0644 |
|
defer.d.ts | File | 2.1 KB | 0644 |
|
defer.js | File | 646 B | 0644 |
|
defer.js.map | File | 554 B | 0644 |
|
empty.d.ts | File | 2 KB | 0644 |
|
empty.js | File | 556 B | 0644 |
|
empty.js.map | File | 522 B | 0644 |
|
forkJoin.d.ts | File | 3.08 KB | 0644 |
|
forkJoin.js | File | 2.65 KB | 0644 |
|
forkJoin.js.map | File | 2.38 KB | 0644 |
|
from.d.ts | File | 404 B | 0644 |
|
from.js | File | 587 B | 0644 |
|
from.js.map | File | 411 B | 0644 |
|
fromArray.d.ts | File | 187 B | 0644 |
|
fromArray.js | File | 551 B | 0644 |
|
fromArray.js.map | File | 364 B | 0644 |
|
fromEvent.d.ts | File | 2.09 KB | 0644 |
|
fromEvent.js | File | 2.7 KB | 0644 |
|
fromEvent.js.map | File | 2.45 KB | 0644 |
|
fromEventPattern.d.ts | File | 557 B | 0644 |
|
fromEventPattern.js | File | 1.28 KB | 0644 |
|
fromEventPattern.js.map | File | 1.03 KB | 0644 |
|
fromIterable.d.ts | File | 189 B | 0644 |
|
fromIterable.js | File | 663 B | 0644 |
|
fromIterable.js.map | File | 444 B | 0644 |
|
fromPromise.d.ts | File | 191 B | 0644 |
|
fromPromise.js | File | 575 B | 0644 |
|
fromPromise.js.map | File | 368 B | 0644 |
|
generate.d.ts | File | 8.94 KB | 0644 |
|
generate.js | File | 3.64 KB | 0644 |
|
generate.js.map | File | 2.83 KB | 0644 |
|
iif.d.ts | File | 3.08 KB | 0644 |
|
iif.js | File | 466 B | 0644 |
|
iif.js.map | File | 367 B | 0644 |
|
interval.d.ts | File | 1.7 KB | 0644 |
|
interval.js | File | 1.04 KB | 0644 |
|
interval.js.map | File | 899 B | 0644 |
|
merge.d.ts | File | 6.45 KB | 0644 |
|
merge.js | File | 1.13 KB | 0644 |
|
merge.js.map | File | 938 B | 0644 |
|
never.d.ts | File | 1.12 KB | 0644 |
|
never.js | File | 321 B | 0644 |
|
never.js.map | File | 248 B | 0644 |
|
of.d.ts | File | 3.22 KB | 0644 |
|
of.js | File | 649 B | 0644 |
|
of.js.map | File | 478 B | 0644 |
|
onErrorResumeNext.d.ts | File | 1.03 KB | 0644 |
|
onErrorResumeNext.js | File | 1.08 KB | 0644 |
|
onErrorResumeNext.js.map | File | 843 B | 0644 |
|
pairs.d.ts | File | 1.97 KB | 0644 |
|
pairs.js | File | 1.59 KB | 0644 |
|
pairs.js.map | File | 1.5 KB | 0644 |
|
partition.d.ts | File | 2.28 KB | 0644 |
|
partition.js | File | 624 B | 0644 |
|
partition.js.map | File | 456 B | 0644 |
|
race.d.ts | File | 2.53 KB | 0644 |
|
race.js | File | 3.3 KB | 0644 |
|
race.js.map | File | 2.06 KB | 0644 |
|
range.d.ts | File | 1.44 KB | 0644 |
|
range.js | File | 1.39 KB | 0644 |
|
range.js.map | File | 1.2 KB | 0644 |
|
throwError.d.ts | File | 1.81 KB | 0644 |
|
throwError.js | File | 645 B | 0644 |
|
throwError.js.map | File | 583 B | 0644 |
|
timer.d.ts | File | 2.16 KB | 0644 |
|
timer.js | File | 1.39 KB | 0644 |
|
timer.js.map | File | 1.2 KB | 0644 |
|
using.d.ts | File | 2.32 KB | 0644 |
|
using.js | File | 1.01 KB | 0644 |
|
using.js.map | File | 849 B | 0644 |
|
zip.d.ts | File | 5.54 KB | 0644 |
|
zip.js | File | 7.82 KB | 0644 |
|
zip.js.map | File | 5.84 KB | 0644 |
|