Hi, i need to execute meterService.incrementExitRe...
# arrow
j
Hi, i need to execute meterService.incrementExitRequests(“online”) always, no matter if there is an error. Is there anything in arrow that works like a finally clause? Not sure if it is the correct approach.
Copy code
either<ReservationError, Unit> {
    //do some logic
}.mapLeft {
    meterService.incrementExitError("online")
    it
}.map {
    meterService.incrementExitRequests("online")
}
p
You may be after guaranteeCase or bracketCase
s
Interesting 🤔 both
guaranteeCase
or
bracketCase
would work for this, but it's actually meant for other things. That being said
guaranteeCase
and
bracketCase
(and
Resource
) signal
ExitCase.Cancelled
when calling
bind()
on
Either.Left
. Why not just use
also
?
Copy code
either<ReservationError, Unit> {

}.also {
  meterService.incrementExitRequests("online")
}
guaranteeCase
or
guarantee
would make more sense to me if you'd do something like this.
Copy code
either {
  guarantee({
    Either.Left("error").bind()
  }) { println("I always run") }
}
j
makes sense i’ll grive it a try