IO
for a minute
map[A, B]: IO[A] => (A => B) => IO[B]
IO
is a datatype, which gets interpreted
map
is fully parametric on A
and B
B
to do special things
B
s, i.e. B = IO[C]
, you want to do something else
ioA.map(printEffect)
, it gets treated as any other B
, i.e. you get IO[IO[Unit]]
identity: Int => Int
I guess what I am struggling with is if map
is defined as:
map[A, B]: IO[A] => (A => B) => IO[B]
and flatMap
as
flatMap[A, B]: IO[A] => (A => F[B]) => IO[B]
if they both result in IO[B]
then why does one necessarily run a program and one does not?
IO
in A => IO[B]
in flatMap, not F
class IO[A](...) {
def map[B](f: A => B): IO[B]
def flatMap[B](f: A => IO[B]): IO[B]
}
object IO {
def delay(a: => A): IO[A]
}
pure
and delay
(picks delay
, which is the most powerful)
map
fundamentally cannot do what you want
IO
)