I have a question about IO
monad. I opened some InputStream
and want to use IO
to read from it. Here is the example:
def read(io: IO[Option[Array[Byte]]]): IO[Unit] = IO {
io.unsafeRunSync() match {
case Some(b) =>
//do some with b
read(io)
case None =>
()
}
}
The thing I'm confused about is that I read from the same IO
instance multiple times modifying its state. It does not look like referential transparent method. Is it common to do this way or there is something more FP style?