Last active
August 29, 2015 14:08
-
-
Save schmmd/d0d791b6a9f38e695537 to your computer and use it in GitHub Desktop.
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
def all[T : RootJsonFormat](esDocConf: ESDocConf, batchSize: Int = 100): Iterator[T] = | |
new Iterator[T] { | |
var i = 0 | |
private def read() = { | |
val items = read(esDocConf, i * batchSize, batchSize) | |
i = i + 1 | |
items | |
} | |
private var batch = read() | |
override def hasNext: Boolean = { | |
if (batch.isEmpty) { | |
batch = read | |
} | |
!batch.isEmpty | |
} | |
override def next: T = { | |
if (batch.isEmpty) { | |
batch = read | |
} | |
val top = batch.head | |
batch = batch.tail | |
top | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment