Last active
August 29, 2015 14:24
-
-
Save fiadliel/597c9a859682fb42747c to your computer and use it in GitHub Desktop.
Paged API requests for scalaz-stream
This file contains 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
case class Response(results: Seq[String], nextPage: Option[Int]) | |
def getPagedUrl(url: String, curPage: Option[Int]): Task[Response] = ??? | |
def pagedRequest(url: String, curPage: Option[Int] = None): Process[Task, String] = { | |
Process.eval(getPagedUrl(url, curPage)) flatMap { response => | |
Process.emitAll(response.results) ++ | |
response.nextPage.map(p => pagedRequest(url, Some(p))).getOrElse(Process.empty) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works like a charm!