Created
September 9, 2015 15:04
-
-
Save pyetras/62df0b79db79f140d0f5 to your computer and use it in GitHub Desktop.
chunkUntil for scalaz-stream
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
def chunkUntil[I](emit: I => Boolean): Process1[I, Vector[I]] = { | |
def go(acc: Vector[I]): Process1[I, Vector[I]] = | |
Process.receive1Or[I,Vector[I]](Process.emit(acc)) { i => | |
val chunk = acc :+ i | |
if (emit(i)) Process.emit(chunk) ++ go(Vector()) | |
else go(chunk) | |
} | |
go(Vector()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment