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

Simon Frost

10/25/2023, 12:52 PM
Hey guy, it there a way to convert a Kotlin Result to a Arrow Either in the library, like:
Copy code
fun <T : Any?> Result<T>.toEither(): Either<Throwable, T> = this.fold(
    { Either.Right(it) },
    { Either.Left(it) }
)
If not, is there anything that speaks against adding this ?
a

Alejandro Serrano.Mena

10/25/2023, 12:56 PM
that's perfectly fine; we didn't include it directly because most of the times one has a
Result
is because of a throwing function
but in that case you can just do
Either.catch { theThrowingFunction() }
❤️ 1
s

Simon Frost

10/25/2023, 1:07 PM
thats true, for most of the cases. In case you don’t want to or can’t change it (external library), it would be good to have such functionality in the core library.
a

Alejandro Serrano.Mena

10/25/2023, 1:08 PM
indeed, although I think
result.fold(::Either.Right, ::Either.Left)
is quite small too
s

Simon Frost

10/25/2023, 1:15 PM
try it 😅
Do I understand you correctly that you see no added value in providing something like this in core?
a

Alejandro Serrano.Mena

10/25/2023, 1:19 PM
I personally don't, but feel free to open an issue in the repo to have more community input (I don't want to impose my opinion on you or any other)
👍 2
3 Views