Im stuck getting the following example working as expected, I have tried using zip
and combineLatest
and as show below withLatestFrom
however non of them gives the expected output.
@Test
fun thereCanBeOnlyOne() {
val s1 = BehaviorSubject.create<Int>()
val s2 = BehaviorSubject.create<Int>()
s2.withLatestFrom<Int, Int, Int>(s1)
.subscribe { (a, b) ->
println("$a - $b")
}
s1.onNext(1)
s1.onNext(2)
s2.onNext(1)
s2.onNext(2)
s1.onNext(333)
s2.onNext(444)
}
What I want is the following to print:
2 - 1
2 - 2
333 - 444