Consider the following snippet:
def foo(x:String): EitherT[F, Throwable, String] = ???
def bar(x:String): EitherT[F, Throwable, String] = ???
I want the following:
On some input s
, first call foo(s)
and if it "fails" return the output of bar(s)
else return the output of foo(s)
without calling bar(s)
. I have come up with the following.
def foobar(s:String) = {
val f = foo(s)
// if f is successful return f else return bar(s)
f.biflatMap(_ => bar(s), _ => f)
}
Is there a better way to do what I want?