Is there a nice way to map an either through a lam...
# arrow
p
Is there a nice way to map an either through a lambda that might throw and catch/map the exception to left? At the moment I have
Copy code
fetch(key).flatMap { Either.catch({ Malformed(key) }) { f(it) } }
s
That is probably the nicest way to do it, although you could also replace
flatMap
with either block.
Copy code
either {
  val res = fetch(key).bind()
  Either.catch { Malformed(key) }
    .mapLeft(f).bind()
}
🙏 1