Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS RxSwift Create Array of Observable from Observable array

Tags:

ios

rx-swift

I'm building a chain function which the flow is to take result from previous function and loop through each element do some calculation and final return back the original array

I have

func(A) -> Observable<[Object]>
func(B)(Object) -> Observable<Object>

How do we make the chaining like this?

Observable<[Object]> -> [Observable<Object>] -> Observable<[Object]>
like image 724
Lê Khánh Vinh Avatar asked Dec 07 '22 18:12

Lê Khánh Vinh


1 Answers

You can chain functions with ´flatMap´ operator:

funcA().flatMap{ objects in 
    Observable.from(objects)
}
.flatMap{ eachObject in
    funcB(eachObject)
}
like image 125
xandrefreire Avatar answered Dec 11 '22 08:12

xandrefreire