Cody Mikol
05/14/2021, 3:36 PMalso
in arrow for things like logging?
Currently doing something like
foo()
.mapLeft { it.also { logger.error("Something terrible has happened!") } }
.map { it.also { logger.success("Something good has happened!") } }
Marius Kotsbak
05/14/2021, 5:08 PMCody Mikol
05/14/2021, 5:09 PMMarius Kotsbak
05/14/2021, 5:10 PMCody Mikol
05/14/2021, 5:11 PMCody Mikol
05/14/2021, 5:12 PM.tap
.tapLeft
.flatTap
sound like they are exactly what I’m looking forMarius Kotsbak
05/14/2021, 5:12 PMCody Mikol
05/14/2021, 5:29 PMpackage com.openanywhere.oautils.arrow
import arrow.core.Either
inline fun <L, R> Either<L, R>.tap(fn: () -> Unit) = this.map { it.also { fn() } }
inline fun <L, R> Either<L, R>.tapLeft(fn: () -> Unit) = this.mapLeft { it.also { fn() } }
Cody Mikol
05/14/2021, 5:30 PMCody Mikol
05/14/2021, 5:30 PMCody Mikol
05/14/2021, 5:32 PMinline fun <L, R> Either<L, R>.tapFold(lFn: () -> Unit, rFn: () -> Unit) = this
.tap { rFn() }
.tapLeft { lFn() }
Marius Kotsbak
05/14/2021, 5:33 PMCody Mikol
05/14/2021, 5:33 PMCody Mikol
05/14/2021, 5:34 PMMarius Kotsbak
05/14/2021, 6:50 PM