let's say, I have a current implementation that looks like this: ```suspend fun loadInt(key: String)...
i
let's say, I have a current implementation that looks like this:
Copy code
suspend fun loadInt(key: String): Int?
The
null
is representing the absence of the value and that's why I was thinking about
Either
or
Option
, but then there is that problem. How would you imagine a migration to
IO
? Something like this would work?
Copy code
fun loadInt(key: String): IO<Int>
s
It’s all about shape and structure.
IO<None, A>
could be a non wrapped version of
suspend () -> A?
where you can capture it as such and run it to
A?
as a suspend function.
i
I guess I need more studying, because I'm not sure I understand the answer 😕
s
Option<A> = None | Some<A>
, or
Option<A>
is modelled by a object marker
None
that short-circuits and a marker for
A
that is biased.
IO<E, A>
can model
suspend () -> Option<A>
with a object marker
None
(
IO.Error<None>
)that short-circuits and a marker for
A
that is biased (
IO.Just
)
That way you can without additional wrapping consume
A?
safely into
IO
and run it later back to
A?
without additional wrapping in
IO
.