I'm using scalaz 6.0 with scala. I'm using iteratees to read from an input stream.
Here's the simple file called simple.txt I have.
This
Is
A test
My iteratee will build up an io monad to print the lines
def printLines: IterV[String, IO[Unit]] = {
def step(currentIO: IO[Unit])(input: Input[String]): IterV[String, IO[Unit]] =
input match {
case El(x) => Cont(
step(
currentIO.flatMap(_ => putStrLn(x))
)
)
case IterV.Empty() => Cont(step(currentIO))
case EOF() => Done(currentIO, EOF[String])
}
Cont(step(io()))
}
When I use the enumeratorM
getFileLines(new File(".../simple.txt"))(printLines).flatMap(_.run).unsafePerformIO
I retrieve the correct output.
When I try to use
getLines(printLines).flatMap(_.run).unsafePerformIO
I only get "This" back to the console. getLines uses the standard input stream. I've added debug statements to the iteratee and getLines seems to send EOF() after the first line and I haven't been able to resolve it.