def lift[M[_]: Applicative]: IndexedStateT[({type λ[α]=M[F[α]]})#λ, S1, S2, A] = new IndexedStateT[({type λ[α]=M[F[α]]})#λ, S1, S2, A] { def apply(initial: S1): M[F[(S2, A)]] = Applicative[M].point(self(initial)) } ... trait EitherTFunctions { def eitherT[F[_], A, B](a: F[A \/ B]): EitherT[F, A, B] = EitherT[F, A, B](a) ...
1 def getString: Option[String] = "Hello ".some //> getString: => Option[String]
2 def getResult: StringEither[String] = "how are you!".right[String] 3 //> getResult: => Exercises.monad_txnfm.StringEither[String]
4 def modState(s:Int): IntState[Unit] = put(s) //> modState: (s: Int)Exercises.monad_txnfm.IntState[Unit]
5 val prg: StateEitherOption[String] = for { 6 s1 <- OptionT.optionT(getString.point[StateEither]) 7 s2 <- "World,".point[StateEitherOption] 8 s3 <- (EitherT.eitherT(getResult.point[IntState]): StateEither[String]).liftM[OptionT] 9 _ <- (modState(99).liftM[StringEitherT]: StateEither[Unit]).liftM[OptionT] 10 } yield s1+s2+s3 //> prg : Exercises.monad_txnfm.StateEitherOption[String] = OptionT(EitherT(sc 11 //| alaz.IndexedStateT$$anon$10@158d2680))
12 prg.run //> res0: Exercises.monad_txnfm.StateEither[Option[String]] = EitherT(scalaz.In 13 //| dexedStateT$$anon$10@158d2680)