monad transformers in cats scala

Viewed 309

i am trying to learn scala cats library. So i am completely new to functional programming.

Please help me to extract value from below example function :

import cats._
import cats.data._
import cats.syntax._
import cats.implicits._
import cats.functor._

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
//import cats.syntax.applicative._


//Here i added test functions to return Either[List[String], A] where left is collecting error list.

case class User(name:String)
case class Users(ppl:List[User])

val testUsers = List(User("test1"), User("test2"))

val func0:Future[Either[List[String], Users]] = () => Future.successful(testUsers.asRight[List[String]])
val func1:(Users => Either[List[String], User]) = (users:Users) => users.ppl(0).asRight[List[String]]

//How to make this function to return Future[Either[List[String], User]] = ???
val res:Future[Either[List[String], Either[List[String], User]]] = EitherT(func0).map(func1).value
2 Answers
Related