What is arrow-idiomatic way to return typed error ...
# arrow
n
What is arrow-idiomatic way to return typed error from function that returns Unit?
y
Raise<ErrorType>.myFun(): Unit
n
Thank you. One more question - If I use
either{ }
in a function that returns Either<Error, Unit>, do I need to bind Unit or something?
s
It's the safest option to use
Raise
directly, you can also use
Either<ErrorType, Unit>
but then you need to make sure to always call
bind
. There is a detekt plugin to check that.
Yes, you need to make sure to call
bind
on
Either<Error, Unit>
, otherwise you'd swallow/ignore to error. Or, recover using
getOrElse
, etc.
That's why
Raise<ErrorType>.myFun(): Unit
is safest, you can call it inside
either<ErrorType, Unit> { myFun() }
but you don't need to call
bind
.
Raise<ErrorType>
gives you the exact same API as you get inside
either<ErrorType, Unit> { }
, but
Either
is perfectly valid if that's what you're using everywhere in your project ☺️ If it's a
private
function you could still consider
Raise
IMO.
🙌 2
n
Thank you very much, got it
🙌 1