mapError
infix fun <Error, OtherError, A> Effect<Error, A>.mapError(transform: suspend (error: Error) -> OtherError): Effect<OtherError, A>
Transform the raised value Error of the Effect
into OtherError, or raise an exception into suspend. This results in an Effect
that returns a value of A or raises OtherError.
import arrow.core.raise.effect
import arrow.core.raise.mapError
object User
object Error
val error = effect<Error, User> { raise(Error) } // Raise(error)
val a = error.mapError<Error, String, User> { _ -> "some-failure" } // Raise(some-failure)
val b = error.mapError<Error, String, User>(Any::toString) // Raise(Error)
val c = error.mapError<Error, Nothing, User> { _ -> throw RuntimeException("BOOM") } // Exception(BOOM)
Content copied to clipboard
infix fun <Error, OtherError, A> EagerEffect<Error, A>.mapError(transform: (error: Error) -> OtherError): EagerEffect<OtherError, A>
Transform the raised value Error of the EagerEffect
into OtherError. This results in an EagerEffect
that returns a value of A or raises OtherError.
import arrow.core.raise.eagerEffect
import arrow.core.raise.mapError
object User
object Error
val error = eagerEffect<Error, User> { raise(Error) } // Raise(error)
val a = error.mapError<Error, String, User> { _ -> "some-failure" } // Raise(some-failure)
val b = error.mapError<Error, String, User>(Any::toString) // Raise(Error)
Content copied to clipboard