If you want to have access to the error state from...
# arrow
j
If you want to have access to the error state from
release
outside of bracket you cannot do that with
IO
you can only access it as @pakoito showed with the two examples. If you want the monadic state accessible you can however use
EitherT
with can do that:
bracketCase({ e -> if (e is ExitCase.Error) EitherT(abort().attempt()) }, use)
will wrap the error in
EitherT
and the bracket instance for
EitherT
will restore this error after
bracketCase(...)
completed, so if it failed with an error you have the error in the left part of the
EitherT
. With only
IO
this is not possible because the monadic state of
IO
is infinite (state of the world theoretically), but `EitherT`'s state is not (it is just an either wrapped in
F
). You need mtl for that and that is in incubator. The behavior here is a bit brittle and currently implemented by hand but it should work. You will also need to lift the acquire and use step to eitherT, but that can be done with just
EitherT.lift
. The implementation for monad-transformers will get a lot simpler and easier to use soon-ish