Skip to content

Instantly share code, notes, and snippets.

@yilinwei
Created March 8, 2017 21:20
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 yilinwei/c5c8b060df63ec0c1368af9a4e7b8a5c to your computer and use it in GitHub Desktop.
Save yilinwei/c5c8b060df63ec0c1368af9a4e7b8a5c to your computer and use it in GitHub Desktop.
recurse
object Test {
type Paged[A] = Single[(A, Option[Single[_]])]
val s: Paged[Int]= Single((1, Some(Single((2, None)))))
def recurse[A](paged: Paged[A]): Observable[A] = paged
.toObservable
.flatMap {
case (i, None) => Observable(i)
case (i, Some(page: Paged[A])) => Observable.pure(i) ++ recurse(page)
}
def main(args: Array[String]): Unit = {
recurse(s).foreach(println)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment