https://kotlinlang.org logo
#arrow
Title
# arrow
d

dave08

02/22/2023, 2:22 PM
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

simon.vergauwen

02/22/2023, 2:24 PM
Either<SomeFailure, Unit>
is the best accurate return type for this.
s

Stylianos Gakis

02/22/2023, 2:25 PM
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

simon.vergauwen

02/22/2023, 2:31 PM
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?
.
9 Views