Вот небольшой набор функций, которые возвращают ReaderT
:
type FailFast[A] = Either[List[String], A]
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))
def fc:ReaderT[FailFast, Map[String,String], Boolean] =
f1.flatMap( b1 => {
if (b1)
for {
b2 <- f2
b3 <- f3
b4 <- f4
} yield b4
else ReaderT(_ => Right(true))
})
Как реализовать fc
в случае, если f1
вернет Reader
, но не ReaderT
:
def f1:Reader[Map[String,String], Boolean] = Reader(_ => true)
Теперь я должен составить Reader
, что в точности равно ReaderT[Id, ...]
с Reader[FailFast, ...]