So I have a certain function which I need to call only if a certain condition is true. If it's false, I consider it as Right.
I would use EitherT.cond, but the thing is my function's return type is Future[Either[ErrorType, Unit]], so it's not suitable for me. Here's my code which does what I want:
def callEitherFunction: Future[Either[ErrorType, Unit]]
for {
_ <- if (condition) {
EitherT(callEitherFunction)
} else {
Either.right[ErrorType, Unit](()).toEitherT[Future]
}
} yield {
//Some actions
}
I wonder if there is a more elegant way to do it. Would appreciate any help.