@@ -10,12 +10,47 @@ import {InnerSubscriber} from '../InnerSubscriber';
10
10
import { subscribeToResult } from '../util/subscribeToResult' ;
11
11
12
12
/**
13
- * Returns an Observable where for each item in the source Observable, the supplied function is applied to each item,
14
- * resulting in a new value to then be applied again with the function.
15
- * @param {function } project the function for projecting the next emitted item of the Observable.
16
- * @param {number } [concurrent] the max number of observables that can be created concurrently. defaults to infinity.
17
- * @param {Scheduler } [scheduler] The Scheduler to use for managing the expansions.
18
- * @return {Observable } an Observable containing the expansions of the source Observable.
13
+ * Recursively projects each source value to an Observable which is merged in
14
+ * the output Observable.
15
+ *
16
+ * <span class="informal">It's similar to {@link mergeMap}, but applies the
17
+ * projection function to every source value as well as every output value.
18
+ * It's recursive.</span>
19
+ *
20
+ * <img src="./img/expand.png" width="100%">
21
+ *
22
+ * Returns an Observable that emits items based on applying a function that you
23
+ * supply to each item emitted by the source Observable, where that function
24
+ * returns an Observable, and then merging those resulting Observables and
25
+ * emitting the results of this merger. *Expand* will re-emit on the output
26
+ * Observable every source value. Then, each output value is given to the
27
+ * `project` function which returns an inner Observable to be merged on the
28
+ * output Observable. Those output values resulting from the projection are also
29
+ * given to the `project` function to produce new output values. This is how
30
+ * *expand* behaves recursively.
31
+ *
32
+ * @example <caption>Start emitting the powers of two on every click, at most 10 of them</caption>
33
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
34
+ * var powersOfTwo = clicks
35
+ * .mapTo(1)
36
+ * .expand(x => Rx.Observable.of(2 * x).delay(1000))
37
+ * .take(10);
38
+ * powersOfTwo.subscribe(x => console.log(x));
39
+ *
40
+ * @see {@link mergeMap }
41
+ * @see {@link mergeScan }
42
+ *
43
+ * @param {function(value: T, index: number) => Observable } project A function
44
+ * that, when applied to an item emitted by the source or the output Observable,
45
+ * returns an Observable.
46
+ * @param {number } [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
47
+ * Observables being subscribed to concurrently.
48
+ * @param {Scheduler } [scheduler=null] The Scheduler to use for subscribing to
49
+ * each projected inner Observable.
50
+ * @return {Observable } An Observable that emits the source values and also
51
+ * result of applying the projection function to each value emitted on the
52
+ * output Observable and and merging the results of the Observables obtained
53
+ * from this transformation.
19
54
* @method expand
20
55
* @owner Observable
21
56
*/
0 commit comments