is there a function like `Either<Throwable, T&g...
# arrow
t
is there a function like
Either<Throwable, T>.getOrThrow(): T
? i've been using
when()
to change behavior on
Left
or
Right
but it's kinda verbose.
p
throwing is discouraged, so when/fold is the way to go if you want to do it 😄
t
gotcha. i don't want to, but that's the controller api 😉
a
in those cases you can do
theEitherValue.getOrElse { throw it }
, which I find quite readable and not so verbose
âž• 6
c
@Alejandro Serrano.Mena any preference between
either.getOrElse { throw it }
and
either.recover { throw it }
? To my knowledge, these behave the same?
a
I tend to use the first one, mostly out of taste (and it also feels a bit weird to say that "throwing" is recovering from an exception 😅) also lately I'm trying to use
Raise<Error>.f(): A
more often than
Either<Error, A>
, and in that case I just use
fold
to make a final throw