[ad_1]
I’ve an observable that appears like this:
func getParameters() -> Single<[ParameterModel]?> {
do {
loading.settle for(allParameters.isEmpty)
return strive parameterService.getParameters()
.do(onSuccess: { [weak self] parameters in
self?.loading.settle for(false)
self?.content material.settle for(parameters?.compactMap { $0 }
.compactMap { TechnicianParameterTableViewCellViewModel(parameter: $0) } ?? [])
})
} catch { return Single.error(error) }
}
The vital half is the place it compactMaps right into a cell. This works as anticipated. However I even have one other observable that appears like this:
func getSingleOrDoubleDoor() -> Single<SingleOrDoubleDoor?> { //SingleOrDoubleDoor is an enum
do {
return strive parameterService.getSingleOrDoubleDoor()
} catch {
return Single.error(error)
}
}
Now, I wish to kind of merge getSingleOrDoubleDoor() into getParameters() in order that I can entry the values of each observables in onSuccess. I need to use the outcome kind of like this:
.compactMap { TechnicianParameterTableViewCellViewModel(parameter: $0, isSingleOrDouble: $1) } ?? [])
Not being an knowledgeable on Rx I nonetheless assume that that is executed utilizing .flatMap{}. Type of like:
...return strive parameterService.getParameters().flatMap { _ in getSingleOrDoubleDoor() }...
However this provides me an error:
Can’t convert worth of kind ‘([ParameterModel]?) -> Single<SingleOrDoubleDoor?>’ (aka ‘(Non-compulsory<Array>) -> PrimitiveSequence<SingleTrait, Non-compulsory>’) to anticipated argument kind ‘([ParameterModel]?) throws -> PrimitiveSequence<SingleTrait, [ParameterModel]?>’
Tried altering the return expression nevertheless it nonetheless would not take. Unsure easy methods to make this occur.
[ad_2]
