is there an (idiomatic) way to do `if let Left(err...
# arrow
c
is there an (idiomatic) way to do
if let Left(err) = myEitherValue { /* do something with err */ }
? basically i want to run a block if
myEitherValue
is
Left
, and i would like to avoid casting it
basically this
Copy code
fun <E, T> Either<E, T>.ifLeft(f: (E) -> Unit) = when(this) {
  is Either.Left<E> -> f(this.value)
  else -> Unit
}
but maybe this is built-in or there's a more idiomatic way? 🙂
ah, i just read the above thread, and it sounds like
tapLeft
is what i want 🙂 (just need to upgrade to 1.x)
p
mapLeft?
Depends on what you want to do