RXJS How to convert observable <T []> to observable <T>

I would like to take an Observable <T []> and convert it to an observable <T> so that each array from Observable <T []> and the individual elements of the arrays are then allocated separately through Observable <T>.

Is there a standard operator for this? I searched but found nothing. Thank.


After heading towards concatMap / flatMap, I came up with the following general solution:

var source: Observable<T[]>;
...
var splitSource = source.flatMap<T>((x:T[]) => { return Rx.Observable.fromArray(x); });
+4
source share
2 answers

You can use concatMapas follows:

function identity (x) {return x}

var obs_of_array$ = Rx.Observable.return(['1','2','you got it'])
    .concatMap(identity)

, concatMap ( promises) , . Jsbin ,

, , , , concatMap .

+6

Observable<T[]> Observable<T>.

, flatMap() , , , 11 , .

, jsfiddle in @user3743222 :

//.concatMap(identity)
.flatMap(theArray=>theArray)

toArray() , , .

    let sorted$ = source$.toArray().flatMap(theList=> theList.sort(this.myComparer) )

Observable<T>. ( N.B , , )

0

All Articles