Skip to content

Instantly share code, notes, and snippets.

@jasonleehodges
Created November 10, 2018 15:13
Show Gist options
  • Save jasonleehodges/8d23872361942bc2d8974ca397827ecc to your computer and use it in GitHub Desktop.
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.
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