Lê Khánh Vinh
Lê Khánh Vinh

Reputation: 2609

IOS RxSwift Create Array of Observable from Observable array

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]>

Upvotes: 5

Views: 7946

Answers (1)

xandrefreire
xandrefreire

Reputation: 2326

You can chain functions with ´flatMap´ operator:

funcA().flatMap{ objects in 
    Observable.from(objects)
}
.flatMap{ eachObject in
    funcB(eachObject)
}

Upvotes: 16

Related Questions