Skip to content

Instantly share code, notes, and snippets.

@sullivan-
Last active Mar 13, 2017
Embed
What would you like to do?
demonstrates odd Iteratee.foreach behavior
object Run extends App {
import cats._
import io.iteratee._
import io.iteratee.internal._
def e = Enumerator.enumVector[Eval, Int]((0 until 10).toVector)
def ge = e.grouped(3)
println("fold ge")
Iteratee.foreach[Eval,Vector[Int]](println).apply(ge).run.value
// fold ge
// Vector(0, 1, 2)
// Vector(3, 4, 5)
// Vector(6, 7, 8)
// Vector(9)
def e2 = new Enumerator[Eval, Int] {
val iter = (0 until 10).grouped(3)
final def apply[A](step: Step[Eval, Int, A]): Eval[Step[Eval, Int, A]] = {
if (!step.isDone && iter.hasNext) {
step.feed(iter.next).flatMap(s => apply[A](s))
} else {
Now(step)
}
}
}
def ge2 = e2.grouped(3)
println("fold ge2")
Iteratee.foreach[Eval,Vector[Int]](println).apply(ge2).run.value
// fold ge2
// Vector(0, 1, 2)
// Vector(0, 1, 2)
// Vector(3, 4, 5)
// Vector(3, 4, 5)
// Vector(6, 7, 8)
// Vector(6, 7, 8)
// Vector(9)
// ()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment