Getting the last two values from an RxSwift Observable
I really can't remember why, but at some point I needed to get a RxSwift Observable's last two values, to compare them and decide what to do next.
Searching around, most answers I found looked a bit too complex to read and too verbose for something that seemed like it should be simple.
It turns out, there is a simple solution. One that only takes one line:
Observable.zip(ourObservable, ourObservable.skip(1))
Here, the left-hand value will be the previous value, and the right-hand value will be the latest value.
Yes, that's it. Thank you, duan!