Ivan Brko
04/22/2020, 6:59 PMfun <T : Any> Result<T>.toEither(): Either<RequestError, T> =
fold({ Either.right(it)}, {Either.left(calculateError())})
However, this doesn't compile (although Intellij doesn't show that anything is wrong with the code), as Either.right
creates Either<Nothing, T>
and Either.left
creates Either<T, Nothing>
, so neither branching of the fold returns the needed type. Can I create wanted Either here (without having to create it with val, specify its exact type and returning that). I hoped simply doing something like Either<RequestError, T>.right
would work, but of course it doesn't 😄raulraja
04/22/2020, 7:05 PMraulraja
04/22/2020, 7:06 PMraulraja
04/22/2020, 7:07 PMraulraja
04/22/2020, 7:07 PMIvan Brko
04/22/2020, 7:09 PMpakoito
04/22/2020, 8:01 PMpakoito
04/22/2020, 8:02 PMpakoito
04/22/2020, 8:02 PMfold({
val a: Either<RequestError, T> = Either.right(it)
a
}, {Either.left(calculateError())})
pakoito
04/22/2020, 8:02 PM