Skip to content

Instantly share code, notes, and snippets.

@sullivan-
Last active March 13, 2017 16:11
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 sullivan-/4561d9fce97ca0fafdc187d17755bf8f to your computer and use it in GitHub Desktop.
Save sullivan-/4561d9fce97ca0fafdc187d17755bf8f to your computer and use it in GitHub Desktop.
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