Group Group Group Group Group Group Group Group Group

Chapter 12 - Using flatMapLatest to transforms a single-use data source into a multi-use Observable


#1

Hello,

I’m working my way through ch 12 and got confused with a piece of code.

let search = searchCityName.rx.text
.filter { ($0 ?? "").characters.count > 0 }
.flatMapLatest { text in
return ApiController.shared.currentWeather(city: text ?? "Error")
    .catchErrorJustReturn(ApiController.Weather.empty)
}
.shareReplay(1)
.observeOn(MainScheduler.instance)

According to details, flatMapLatest is used to make it multi-used observable. However, what confuses me is we’re not dealing with multiple observables here. It’s just a single observable searchCityName.rx.text we’re subscribing to. Please explain. Thanks.


#2

@bontojr Can you please help with this when you get a chance? Thank you - much appreciated! :]


#3

Hi, why flatMapLatest instead of flatMap?


#5

#6

@bontojr Can you please help with this when you get a chance? Thank you - much appreciated! :]