Created
November 10, 2018 15:13
-
-
Save jasonleehodges/8d23872361942bc2d8974ca397827ecc to your computer and use it in GitHub Desktop.
Simulate pulling data down from a pageable api where you don't know how many pages there are in your request without using any mutable variables to keep track of what page you are on.
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.collection.mutable.Queue | |
object Page extends App { | |
val apiData = Queue(1000,1000,1000,1000,1000,10) | |
Stream.from(1).takeWhile(getPage(_).nonEmpty).foreach(_ => processData()) | |
def getPage(x: Int): Queue[Int] = { return apiData } | |
def processData(){ println(apiData.dequeue()) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment