我想使用 IO 单子。
但是此代码不适用于大文件。我收到了 StackOverflowError。我尝试了该-DXss
选项,但它引发了同样的错误。
val main = for {
l <- getFileLines(file)(collect[String, List]).map(_.run)
_ <- l.traverse_(putStrLn)
} yield ()
我该怎么做?
我写了输出所有元素的Iteratee。
def putStrLn[E: Show]: IterV[E, IO[Unit]] = {
import IterV._
def step(i: IO[Unit])(input: Input[E]): IterV[E, IO[Unit]] =
input(el = e => Cont(step(i >|> effects.putStrLn(e.shows))),
empty = Cont(step(i)),
eof = Done(i, EOF[E]))
Cont(step(mzero[IO[Unit]]))
}
val main = for {
i <- getFileLines(file)(putStrLn).map(_.run)
} yield i.unsafePerformIO
这也是同样的结果。
我认为是由 IO 实现引起的。