Skip to content

Instantly share code, notes, and snippets.

@joescii
Created July 13, 2016 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joescii/bb82f2903324c0ef9516a770bafeb1e7 to your computer and use it in GitHub Desktop.
Save joescii/bb82f2903324c0ef9516a770bafeb1e7 to your computer and use it in GitHub Desktop.
SO `chunkWhen` updated for scalaz streams 0.7.3a
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