@@ -92,30 +92,33 @@ var subscription = source.subscribe(
9292// => Completed
9393
9494/* Using an array */
95- var source = Rx .Observable .of (1 ,2 ,3 )
96- .flatMap (
97- function (x , i ) { return [x,i]; },
98- function (x , y , ix , iy ) { return x + y + ix + iy; }
99- );
100-
101- var subscription = source .subscribe (
102- function (x ) {
103- console .log (' Next: ' + x);
104- },
105- function (err ) {
106- console .log (' Error: ' + err);
107- },
108- function () {
109- console .log (' Completed' );
110- });
111-
112- // => Next: 2
113- // => Next: 2
114- // => Next: 5
115- // => Next: 5
116- // => Next: 8
117- // => Next: 8
118- // => Completed
95+ Rx .Observable .of (2 , 3 , 5 )
96+ .selectMany (function (outer ) {
97+ // Return x^2, x^3 and x^4
98+ return [x * x,
99+ x * x * x,
100+ x * x * x * x];
101+ },
102+ function (outer , inner , outerIndex , innerIndex )
103+ {
104+ return { outer : outer, inner : inner, outerIdx : outerIndex, innerIdx : innerIndex };
105+ }
106+ ).subscribe (function (next ) {
107+
108+ console .log (' Outer: ' + next .outer + ' , Inner: ' + next .inner , +
109+ ' , InnerIndex: ' + next .innerIdx + ' , OuterIndex: ' + next .outerIdx );
110+ }, function () {
111+ console .log (' Completed' );
112+ });
113+
114+ // => Outer: 2, Inner: 4, InnerIndex : 0, OuterIndex : 0
115+ // => Outer: 2, Inner: 8, InnerIndex : 1, OuterIndex : 0
116+ // => Outer: 2, Inner: 16, InnerIndex : 2, OuterIndex : 0
117+ // => Outer: 3, Inner: 9, InnerIndex : 0, OuterIndex : 1
118+ // => Outer: 3, Inner: 27, InnerIndex : 1, OuterIndex : 1
119+ // => Outer: 3, Inner: 81, InnerIndex : 2, OuterIndex : 1
120+ // ...etc
121+ // => Completed
119122```
120123
121124### Location
0 commit comments