demonstrates odd Iteratee.foreach behavior
This file contains 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
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