Created
August 18, 2015 07:42
-
-
Save aniketbhatnagar/2c759b7035f157f0171f to your computer and use it in GitHub Desktop.
Grouping an Enumerator by size (Playframework)
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
import play.api.libs.iteratee.Enumerator | |
import play.api.libs.iteratee.Enumeratee | |
import play.api.libs.iteratee.Iteratee | |
def grouped[T](enumerator: Enumerator[T], groupSize: Int): Enumerator[List[T]] = { | |
val groupingIteratee = Enumeratee.take[T](groupSize) &>> Iteratee.getChunks | |
val groupingEnumeratee = Enumeratee.grouped(groupingIteratee) | |
enumerator &> groupingEnumeratee | |
} | |
import scala.concurrent.Await | |
import scala.concurrent.duration.Duration | |
val e = Enumerator((1 to 1000) : _*) | |
val groupedE = grouped(e, 5) | |
val r = groupedE.run(Iteratee.getChunks) | |
println(Await.result(r, Duration.Inf)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment