Created
September 3, 2016 12:36
-
-
Save davegurnell/5c62365ac9b17b9ce32e301b4b1435fb to your computer and use it in GitHub Desktop.
Snippet for a conversation in the Cats Gitter channel
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
| import scala.annotation.tailrec | |
| import scala.concurrent.{ ExecutionContext => EC, _ } | |
| trait Json // whatever JSON type you're using | |
| def getJson(url: String)(implicit ec: EC): Future[Json] = | |
| ??? // whatever implementation you currently have | |
| def getNextUrlFromJson(json: Json): Option[String] = | |
| ??? // whatever implementation you currently have | |
| def getAllJson(url: String)(implicit ec: EC): Future[Seq[Json]] = | |
| getJson(url) flatMap { json => | |
| getNextUrlFromJson(json) match { | |
| case Some(nextUrl) => getAllJson(nextUrl).map(rest => json +: rest) | |
| case None => Future.successful(Seq.empty) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment