how do you filter and replace a given result with ...
# arrow
f
how do you filter and replace a given result with error in a Kotlin Result and Arrow Either? eg given the types Result<Response> or Either<Throwable, Response> if the response in the success case/on the right has response.isSuccessful is false, I want to turn that into a failed result/throwable on the left
d
I think you can bind() a result in an either scope?
l
what about
.map()
functions in Arrow ?
r
scratch.kt
You could use
bind
or
flatMap
like in the snippet above.
Or use the Raise DSL to create your own operations for the
either
block.
a
the simples way would be to do:
Copy code
fun <A> Either<Throwable, A>.toResult() = Result<A> = either { this.bind() }

fun <A> Result<A>.toEither(): Either<Throwable, A> = result { this.bind() }
the general pattern is that the outer block (`either`/`result`) tells you the result type, and
bind()
"injects" an error into the context
r
raise.kt.cpp
f
what about filterOrElse and filterOrOther? they look like they should do roughly the same thing? https://github.com/arrow-kt/arrow/issues/1179