I'm using RxSwift 2.0.0-beta
How can I combine 2 observables of different types in a zip like manner?
// This works
[just(1), just(1)].zip { intElements in
return intElements.count
}
// This doesn't
[just(1), just("one")].zip { differentTypeElements in
return differentTypeElements.count
}
The current workaround I have is to map everything to an optional tuple that combines the types, then zips optional tuples into a non-optional one.
let intObs = just(1)
.map { int -> (int: Int?, string: String?) in
return (int: int, string: nil)
}
let stringObs = just("string")
.map { string -> (int: Int?, string: String?) in
return (int: nil, string: string)
}
[intObs, stringObs].zip { (optionalPairs) -> (int: Int, string: String) in
return (int: optionalPairs[0].int!, string: optionalPairs[1].string!)
}
That's clearly pretty ugly though. What is the better way?