Created
July 13, 2016 17:28
-
-
Save joescii/bb82f2903324c0ef9516a770bafeb1e7 to your computer and use it in GitHub Desktop.
SO `chunkWhen` updated for scalaz streams 0.7.3a
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
import scalaz.stream.Process._ | |
import scalaz.stream._ | |
import tee._ | |
object ChunkWhen { | |
def chunkWhen[I](f: (I, I) => Boolean): Process1[I, Vector[I]] = { | |
def go(acc: Vector[I]): Process1[I,Vector[I]] = | |
receive1Or[I, Vector[I]](emit(acc)){ i => | |
acc.lastOption match { | |
case Some(last) if ! f(last, i) => emit(acc) ++ go(Vector(i)) | |
case _ => go(acc :+ i) | |
} | |
} | |
go(Vector()) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment