Skip to content

Instantly share code, notes, and snippets.

@SylvainHocq
Created February 11, 2020 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SylvainHocq/0bc59abb152fb185a7a6fcc0c809fc30 to your computer and use it in GitHub Desktop.
Save SylvainHocq/0bc59abb152fb185a7a6fcc0c809fc30 to your computer and use it in GitHub Desktop.
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