Created
January 3, 2014 20:13
-
-
Save rubanm/8245660 to your computer and use it in GitHub Desktop.
Paging responses - avoid while loop, use Stream takeWhile.
Somewhat ugly, but works.
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
val responses = MutableList[Response]() | |
Stream.from(0, PAGE_SIZE).takeWhile { case offset => | |
request.setOffset(offset) | |
val response = Await.result(client.execute(request)) | |
response.getResponseCode match { | |
case ResponseCode.OK => responses += (response); true | |
case ResponseCode.END => false | |
case _ => false // or throw exception | |
} | |
}.foreach { case exec => () } // not lazy | |
responses.reduce { ... } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment