Is there a way to represent a function that either...
# arrow
d
Is there a way to represent a function that either does an action successfully (no return value) or has a failure one can
bind()
to in an either? Is there only
Either<SomeFailure, Unit>
or maybe something made for this purpose?
s
Either<SomeFailure, Unit>
is the best accurate return type for this.
s
What about a function that does something, may fail (but I don’t want/can’t know why it failed) and it may also succeed but without any result? Is
Either<Unit, Unit>
normal, or just an indicator that I probably want something more smart for
Left
?
s
I've not really come across cases where I have no idea at all what went wrong. I would probably create a marker
object Failed
that at some point you
mapLeft
to align errors into a different error hierarchy, or
Throwable
with
Either.catch
in case I don't know what goes wrong. Being aware that with
Throwable
you don't swallow, and/or send an alert/log to a metric service. In any other case where there is some result but no clear error, so
Either<Unit, A>
is a good indication you probably want
A?
.