mattmoore
01/01/2020, 3:04 AMraulraja
01/01/2020, 1:13 PMraulraja
01/01/2020, 1:14 PMraulraja
01/01/2020, 1:15 PMraulraja
01/01/2020, 1:17 PMmattmoore
01/01/2020, 8:40 PM.attempt()
which seems to work quite nicely, similar to Scala/Haskell.Jannis
01/01/2020, 9:34 PMIO<A>
in relation to errors has two states A
or Throwable
. With IO<E, A>
you get control over the error type which means you can raise and handle custom exceptions easier (they don't have to be Throwable
. It also tells a caller what errors to expect and in case of IO<Nothing, A>
to not expect any errors. The possible states (in regards to errors) for IO<E, A>
are E
, A
or Throwable
. Throwable
here explicitly marks unexpected errors, whereas E
marks expected errors. (expected as in the caller should in some way handle those errors consciously, whereas a Throwable
is probably only handled by a catch-all like handler). If you are familiar with mtl IO<E, A> = EitherT<ForIO, E, A> = IO<Either<E, A>>
, though the more you go down to the concrete type IO<Either<E, A>>
the less nice interaction with that datatype is going to be. Using IO<E, A>
will always be easier than the equivalent EitherT
or IO<Either<E, A>>
code.