Imagine there are two BehaviourSubject with Strings:
private val subjectLocationA = BehaviorSubject.createDefault("London")
private val subjectLocationB = BehaviorSubject.createDefault("Paris")
were I update location each like
subjectLocationA.onNext("Denver")
Then I have a enum class
@Serializable
enum class ActiveLocationList(@StringRes val value: Int) {
ALL_LOCATION("all"),
MY_FAVLOCATION("favorites")
}
used in a Observable:
val settingsActiveLocationList: Observable<ActiveLocationList>
I combine the above Subjects and Observables via combineLatest():
Observables.combineLatest(
subjectLocationA,
subjectLocationB,
settingsActiveLocationList,
).switchMap { (locationA, locationB, activeLocationList) ->
//..
}
Now I would like to extend a third location subject subjectLocationC according to above example. But I am about to extend the combineLatest:
Observables.combineLatest(
subjectLocationA,
subjectLocationB,
subjectLocationC,
settingsActiveLocationList,
).switchMap { (locationA, locationB, locationC, activeLocationList) ->
//..
IDE complains with
Type mismatch.
Required: (TypeVariable(T1), TypeVariable(T2), TypeVariable(T3)) → TypeVariable(R)
Found: Observable
and
Cannot infer a type for this parameter. Please specify it explicitly.
According to the Observables implementation says amongst others
fun <T1 : Any, T2 : Any, T3 : Any> combineLatest
and
inline fun <T1 : Any, T2 : Any, T3 : Any, T4 : Any, R : Any> combineLatest
but nothing in between?! I think I would need
fun <T1 : Any, T2 : Any, T3 : Any, T4 : Any> combineLatest
or am I wrong? Is there a workaround maybe? What am I missing?
Personally I have a library for it, but Stack Overflow doesn't like links, so I use the following code, you can just copy-paste it