Here are function definitions that return ReaderT:
def f1:ReaderT[FailFast, Map[String,String], Boolean] = ReaderT(_ => Right(true))
def f2:ReaderT[FailFast, Map[String,String], Boolean] = ReaderT(_ => Left(List("d")))
def f3:ReaderT[FailFast, Map[String,String], Boolean] = ReaderT(_ => Right(true))
def f4:ReaderT[FailFast, Map[String,String], Boolean] = ReaderT(_ => Right(true))
I want to combine them. f1
and f2
are used as monadic effects. But result of f3
and f4
must be accumulated. I try to implement something that looks like:
def fc:ReaderT[FailFast, Map[String,String], Boolean] =
f1.flatMap( b1 => {
if (b1)
for {
b2 <- f2
b3 <- Semigroupal.tuple2[FailSlow, Boolean, Boolean](
f3, // how to convert it to validated here without run?
f4 // how to convert it to validated here without run?
).toEither
} yield b3
else ReaderT(_ => Right(true))
})
If more then one option exists, please offer both