Created
February 11, 2020 13:02
-
-
Save SylvainHocq/0bc59abb152fb185a7a6fcc0c809fc30 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <TSource> Observable<TSource>.pairWithPrevious() | |
: Observable<Pair<TSource?, TSource?>> { | |
return this | |
.map { | |
Pair(null as TSource?, it) | |
} | |
.scan { acc: Pair<TSource?, TSource?>, current: Pair<TSource?, TSource?> -> | |
Pair(acc.second, current.second) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment