What would be the equivalent of
onLeft {}
when working with the Raise DSL?
Given the following using when dealing with an API that exposes `Either`s:
fun getIntFromDb(): Either<DbError, Int> = 0.right()
One could “forward” the
Either
and also intercept `Left`s for logging or whatever:
fun getInt(): Either<DbError, Int> =
getIntFromDb()
.onLeft { log(it.message) }
However, if the API uses the
Raise
DSL, it feels a little more weird:
fun Raise<DbError>.getIntFromDb(): Int = 0
fun Raise<DbError>.getInt(): Int =
withError({
log(it.message)
it
}) { getIntFromDb() }
While writing this, I realized
also
could clear some things up, but I'm still curious if this is the Correct™ approach:
fun Raise<DbError>.getInt(): Int =
withError({ it.also { log(it.message) } }) { getIntFromDb() }