I have 4 text input fields. When the user enters text into any of the fields, I will enable a button. To accomplish this, I will use the combineLatest by combining 4 observables that receive text in their streams. I am at a loss as to how to access the latest value of each of the observables. NOTE: I want to use an array as eventually there will be more than 4 input fields. I am also looking for a solution in Kotlin.
val text1: PublishSubject<String> = PublishSubject.create()
val text2: PublishSubject<String> = PublishSubject.create()
val text3: PublishSubject<String> = PublishSubject.create()
val text4: PublishSubject<String> = PublishSubject.create()
val inputs = Arrays.asList(
text1, text2, text3, text4
)
Observable.combineLatest(inputs) {
// How do I access the latest value from each observable?
}
Inside the lambda you get an array. The i-th element of this array (arrayOfEmissions
in the following example) corresponds to the latest element emitted by the i-th observable.
Observable.combineLatest(inputs) { arrayOfEmissions ->
}