Class/Object

cats.data

EitherT

Related Docs: object EitherT | package data

Permalink

final case class EitherT[F[_], A, B](value: F[Either[A, B]]) extends Product with Serializable

Transformer for Either, allowing the effect of an arbitrary type constructor F to be combined with the fail-fast effect of Either.

EitherT[F, A, B] wraps a value of type F[Either[A, B]]. An F[C] can be lifted in to EitherT[F, A, C] via EitherT.right, and lifted in to a EitherT[F, C, B] via EitherT.left.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. EitherT
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new EitherT(value: F[Either[A, B]])

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def ===(that: EitherT[F, A, B])(implicit eq: Eq[F[Either[A, B]]]): Boolean

    Permalink
  5. def applyAlt[D](ff: EitherT[F, A, (B) ⇒ D])(implicit F: Apply[F]): EitherT[F, A, D]

    Permalink
  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def biSemiflatMap[C, D](fa: (A) ⇒ F[C], fb: (B) ⇒ F[D])(implicit F: Monad[F]): EitherT[F, C, D]

    Permalink

    Combine leftSemiflatMap and semiflatMap together.

    Combine leftSemiflatMap and semiflatMap together.

    Example:

    scala> import cats.implicits._
    scala> import cats.data.EitherT
    
    scala> val eitherT: EitherT[List, String, Int] = EitherT[List, String, Int](List(Left("abc"), Right(123)))
    scala> eitherT.biSemiflatMap(string => List(string.length), int => List(int.toFloat))
    res0: cats.data.EitherT[List,Int,Float] = EitherT(List(Left(3), Right(123.0)))
  8. def biflatMap[AA >: A, BB >: B](fa: (A) ⇒ EitherT[F, AA, BB], fb: (B) ⇒ EitherT[F, AA, BB])(implicit F: FlatMap[F]): EitherT[F, AA, BB]

    Permalink
  9. def bimap[C, D](fa: (A) ⇒ C, fb: (B) ⇒ D)(implicit F: Functor[F]): EitherT[F, C, D]

    Permalink
  10. def bitraverse[G[_], C, D](f: (A) ⇒ G[C], g: (B) ⇒ G[D])(implicit traverseF: Traverse[F], applicativeG: Applicative[G]): G[EitherT[F, C, D]]

    Permalink
  11. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  12. def collectRight(implicit FA: Alternative[F], FM: Monad[F]): F[B]

    Permalink
  13. def combine(that: EitherT[F, A, B])(implicit F: Apply[F], B: Semigroup[B]): EitherT[F, A, B]

    Permalink

    Similar to Either#combine but mapped over an F context.

    Similar to Either#combine but mapped over an F context.

    Examples:

    scala> import cats.data.EitherT
    scala> import cats.implicits._
    scala> val l1: EitherT[Option, String, Int] = EitherT.left(Some("error 1"))
    scala> val l2: EitherT[Option, String, Int] = EitherT.left(Some("error 2"))
    scala> val r3: EitherT[Option, String, Int] = EitherT.right(Some(3))
    scala> val r4: EitherT[Option, String, Int] = EitherT.right(Some(4))
    scala> val noneEitherT: EitherT[Option, String, Int] = EitherT.left(None)
    
    scala> l1 combine l2
    res0: EitherT[Option, String, Int] = EitherT(Some(Left(error 1)))
    
    scala> l1 combine r3
    res1: EitherT[Option, String, Int] = EitherT(Some(Left(error 1)))
    
    scala> r3 combine l1
    res2: EitherT[Option, String, Int] = EitherT(Some(Left(error 1)))
    
    scala> r3 combine r4
    res3: EitherT[Option, String, Int] = EitherT(Some(Right(7)))
    
    scala> l1 combine noneEitherT
    res4: EitherT[Option, String, Int] = EitherT(None)
    
    scala> noneEitherT combine l1
    res5: EitherT[Option, String, Int] = EitherT(None)
    
    scala> r3 combine noneEitherT
    res6: EitherT[Option, String, Int] = EitherT(None)
    
    scala> noneEitherT combine r4
    res7: EitherT[Option, String, Int] = EitherT(None)
  14. def compare(that: EitherT[F, A, B])(implicit o: Order[F[Either[A, B]]]): Int

    Permalink
  15. def ensure[AA >: A](onFailure: ⇒ AA)(f: (B) ⇒ Boolean)(implicit F: Functor[F]): EitherT[F, AA, B]

    Permalink
  16. def ensureOr[AA >: A](onFailure: (B) ⇒ AA)(f: (B) ⇒ Boolean)(implicit F: Functor[F]): EitherT[F, AA, B]

    Permalink
  17. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  18. def exists(f: (B) ⇒ Boolean)(implicit F: Functor[F]): F[Boolean]

    Permalink
  19. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  20. def flatMap[AA >: A, D](f: (B) ⇒ EitherT[F, AA, D])(implicit F: Monad[F]): EitherT[F, AA, D]

    Permalink
  21. def flatMapF[AA >: A, D](f: (B) ⇒ F[Either[AA, D]])(implicit F: Monad[F]): EitherT[F, AA, D]

    Permalink
  22. def fold[C](fa: (A) ⇒ C, fb: (B) ⇒ C)(implicit F: Functor[F]): F[C]

    Permalink
  23. def foldF[C](fa: (A) ⇒ F[C], fb: (B) ⇒ F[C])(implicit F: FlatMap[F]): F[C]

    Permalink
  24. def foldLeft[C](c: C)(f: (C, B) ⇒ C)(implicit F: Foldable[F]): C

    Permalink
  25. def foldRight[C](lc: Eval[C])(f: (B, Eval[C]) ⇒ Eval[C])(implicit F: Foldable[F]): Eval[C]

    Permalink
  26. def forall(f: (B) ⇒ Boolean)(implicit F: Functor[F]): F[Boolean]

    Permalink
  27. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  28. def getOrElse[BB >: B](default: ⇒ BB)(implicit F: Functor[F]): F[BB]

    Permalink
  29. def getOrElseF[BB >: B](default: ⇒ F[BB])(implicit F: Monad[F]): F[BB]

    Permalink
  30. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  31. def isLeft(implicit F: Functor[F]): F[Boolean]

    Permalink
  32. def isRight(implicit F: Functor[F]): F[Boolean]

    Permalink
  33. def leftFlatMap[BB >: B, D](f: (A) ⇒ EitherT[F, D, BB])(implicit F: Monad[F]): EitherT[F, D, BB]

    Permalink
  34. def leftMap[C](f: (A) ⇒ C)(implicit F: Functor[F]): EitherT[F, C, B]

    Permalink
  35. def leftSemiflatMap[D](f: (A) ⇒ F[D])(implicit F: Monad[F]): EitherT[F, D, B]

    Permalink
  36. def map[D](f: (B) ⇒ D)(implicit F: Functor[F]): EitherT[F, A, D]

    Permalink
  37. def mapK[G[_]](f: ~>[F, G]): EitherT[G, A, B]

    Permalink

    Modify the context F using transformation f.

  38. def merge[AA >: A](implicit ev: <:<[B, AA], F: Functor[F]): F[AA]

    Permalink
  39. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  40. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  41. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  42. def orElse[AA, BB >: B](default: ⇒ EitherT[F, AA, BB])(implicit F: Monad[F]): EitherT[F, AA, BB]

    Permalink
  43. def partialCompare(that: EitherT[F, A, B])(implicit p: PartialOrder[F[Either[A, B]]]): Double

    Permalink
  44. def recover(pf: PartialFunction[A, B])(implicit F: Functor[F]): EitherT[F, A, B]

    Permalink
  45. def recoverWith(pf: PartialFunction[A, EitherT[F, A, B]])(implicit F: Monad[F]): EitherT[F, A, B]

    Permalink
  46. def rethrowT(implicit F: MonadError[F, A]): F[B]

    Permalink

    Inverse of MonadError#attemptT

  47. def semiflatMap[D](f: (B) ⇒ F[D])(implicit F: Monad[F]): EitherT[F, A, D]

    Permalink
  48. def show(implicit show: Show[F[Either[A, B]]]): String

    Permalink
  49. def subflatMap[AA >: A, D](f: (B) ⇒ Either[AA, D])(implicit F: Functor[F]): EitherT[F, AA, D]

    Permalink
  50. def swap(implicit F: Functor[F]): EitherT[F, B, A]

    Permalink
  51. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  52. def to[G[_]](implicit F: Functor[F], G: Alternative[G]): F[G[B]]

    Permalink
  53. def toNested: Nested[F, [β$2$]Either[A, β$2$], B]

    Permalink

    Transform this EitherT[F, A, B] into a Nested[F, Either[A, ?], B].

    Transform this EitherT[F, A, B] into a Nested[F, Either[A, ?], B].

    An example where toNested can be used, is to get the Apply.ap function with the behavior from the composed Apply instances from F and Either[A, ?], which is inconsistent with the behavior of the ap from Monad of EitherT.

    scala> import cats.data.EitherT
    scala> import cats.implicits._
    scala> val ff: EitherT[List, String, Int => String] =
         |   EitherT(List(Either.right(_.toString), Either.left("error")))
    scala> val fa: EitherT[List, String, Int] =
         |   EitherT(List(Either.right(1), Either.right(2)))
    scala> ff.ap(fa)
    res0: EitherT[List,String,String] = EitherT(List(Right(1), Right(2), Left(error)))
    scala> EitherT((ff.toNested).ap(fa.toNested).value)
    res1: EitherT[List,String,String] = EitherT(List(Right(1), Right(2), Left(error), Left(error)))
  54. def toNestedValidated(implicit F: Functor[F]): Nested[F, [β$4$]Validated[A, β$4$], B]

    Permalink

    Transform this EitherT[F, A, B] into a Nested[F, Validated[A, ?], B].

    Transform this EitherT[F, A, B] into a Nested[F, Validated[A, ?], B].

    Example:

    scala> import cats.data.{EitherT, Validated}
    scala> import cats.implicits._
    scala> val f: Int => String = i => (i*2).toString
    scala> val r1: EitherT[Option, String, Int => String] = EitherT.right(Some(f))
    r1: cats.data.EitherT[Option,String,Int => String] = EitherT(Some(Right(<function1>)))
    scala> val r2: EitherT[Option, String, Int] = EitherT.right(Some(10))
    r2: cats.data.EitherT[Option,String,Int] = EitherT(Some(Right(10)))
    scala> type ErrorOr[A] = Validated[String, A]
    scala> (r1.toNestedValidated).ap(r2.toNestedValidated)
    res0: cats.data.Nested[Option,ErrorOr,String] = Nested(Some(Valid(20)))
  55. def toNestedValidatedNec(implicit F: Functor[F]): Nested[F, [β$8$]Validated[Type[A], β$8$], B]

    Permalink

    Transform this EitherT[F, A, B] into a Nested[F, ValidatedNec[A, ?], B].

  56. def toNestedValidatedNel(implicit F: Functor[F]): Nested[F, [β$6$]Validated[NonEmptyList[A], β$6$], B]

    Permalink

    Transform this EitherT[F, A, B] into a Nested[F, ValidatedNel[A, ?], B].

  57. def toOption(implicit F: Functor[F]): OptionT[F, B]

    Permalink
  58. def toValidated(implicit F: Functor[F]): F[Validated[A, B]]

    Permalink
  59. def toValidatedNec(implicit F: Functor[F]): F[ValidatedNec[A, B]]

    Permalink
  60. def toValidatedNel(implicit F: Functor[F]): F[ValidatedNel[A, B]]

    Permalink
  61. def transform[C, D](f: (Either[A, B]) ⇒ Either[C, D])(implicit F: Functor[F]): EitherT[F, C, D]

    Permalink
  62. def traverse[G[_], D](f: (B) ⇒ G[D])(implicit traverseF: Traverse[F], applicativeG: Applicative[G]): G[EitherT[F, A, D]]

    Permalink
  63. val value: F[Either[A, B]]

    Permalink
  64. def valueOr[BB >: B](f: (A) ⇒ BB)(implicit F: Functor[F]): F[BB]

    Permalink
  65. def valueOrF[BB >: B](f: (A) ⇒ F[BB])(implicit F: Monad[F]): F[BB]

    Permalink
  66. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  67. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  68. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  69. def withValidated[AA, BB](f: (Validated[A, B]) ⇒ Validated[AA, BB])(implicit F: Functor[F]): EitherT[F, AA, BB]

    Permalink

    Run this value as a Validated against the function and convert it back to an EitherT.

    Run this value as a Validated against the function and convert it back to an EitherT.

    The Applicative instance for EitherT "fails fast" - it is often useful to "momentarily" have it accumulate errors instead, which is what the Validated data type gives us.

    Example:

    scala> import cats.implicits._
    scala> type Error = String
    scala> val v1: Validated[NonEmptyList[Error], Int] = Validated.invalidNel("error 1")
    scala> val v2: Validated[NonEmptyList[Error], Int] = Validated.invalidNel("error 2")
    scala> val eithert: EitherT[Option, Error, Int] = EitherT.leftT[Option, Int]("error 3")
    scala> eithert.withValidated { v3 => (v1, v2, v3.toValidatedNel).mapN { case (i, j, k) => i + j + k } }
    res0: EitherT[Option, NonEmptyList[Error], Int] = EitherT(Some(Left(NonEmptyList(error 1, error 2, error 3))))

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped