- Companion
- class
Type members
Value members
Concrete methods
Creates a both version of IorT[F, A, B]
from a F[A]
and a F[B]
Creates a both version of IorT[F, A, B]
from a F[A]
and a F[B]
scala> import cats.data.IorT
scala> import cats.implicits._
scala> IorT.both(Option("err"), Option(3))
res0: cats.data.IorT[Option,String,Int] = IorT(Some(Both(err,3)))
Creates a both version of IorT[F, A, B]
from a A
and a B
Creates a both version of IorT[F, A, B]
from a A
and a B
scala> import cats.data.IorT
scala> import cats.implicits._
scala> IorT.bothT[Option]("err", 3)
res0: cats.data.IorT[Option,String,Int] = IorT(Some(Both(err,3)))
If the condition is satisfied, return the given B
in Ior.Right
, otherwise, return the given
A
in Ior.Left
, lifted into the specified Applicative
.
If the condition is satisfied, return the given B
in Ior.Right
, otherwise, return the given
A
in Ior.Left
, lifted into the specified Applicative
.
scala> import cats.data.IorT
scala> import cats.implicits._
scala> val userInput = "hello world"
scala> IorT.cond[Option](
| userInput.forall(_.isDigit) && userInput.size == 10,
| userInput,
| "The input does not look like a phone number")
res0: cats.data.IorT[Option,String,String] = IorT(Some(Left(The input does not look like a phone number)))
If the condition is satisfied, return the value of IorT.right
on F[B]
, otherwise, return the
value of IorT.left
on F[A]
.
If the condition is satisfied, return the value of IorT.right
on F[B]
, otherwise, return the
value of IorT.left
on F[A]
.
scala> import cats.data.IorT
scala> import cats.implicits._
scala> val userInput = "hello world"
scala> IorT.condF[Option, String, String](
| userInput.forall(_.isDigit) && userInput.size == 10,
| Some(userInput),
| None)
res0: cats.data.IorT[Option,String,String] = IorT(None)
Transforms an Either
into an IorT
, lifted into the specified Applicative
.
Transforms an Either
into an IorT
, lifted into the specified Applicative
.
scala> import cats.data.IorT
scala> import cats.implicits._
scala> val e: Either[String, Int] = Either.right(3)
scala> IorT.fromEither[Option](e)
res0: cats.data.IorT[Option,String,Int] = IorT(Some(Right(3)))
Transforms an F[Either]
into an IorT
.
Transforms an F[Either]
into an IorT
.
scala> import cats.data.IorT
scala> import cats.implicits._
scala> val e: Either[String, Int] = Either.right(3)
scala> IorT.fromEitherF(Option(e))
res0: cats.data.IorT[Option,String,Int] = IorT(Some(Right(3)))
Transforms an Ior
into an IorT
, lifted into the specified Applicative
.
Transforms an Ior
into an IorT
, lifted into the specified Applicative
.
scala> import cats.data.{IorT, Ior}
scala> import cats.implicits._
scala> val i: Ior[String, Int] = Ior.both("warning", 3)
scala> IorT.fromIor[Option](i)
res0: cats.data.IorT[Option,String,Int] = IorT(Some(Both(warning,3)))
Transforms an Option
into an IorT
, lifted into the specified Applicative
and using
the second argument if the Option
is a None
.
Transforms an Option
into an IorT
, lifted into the specified Applicative
and using
the second argument if the Option
is a None
.
scala> import cats.data.IorT
scala> import cats.implicits._
scala> val o: Option[Int] = None
scala> IorT.fromOption[List](o, "Answer not known.")
res0: cats.data.IorT[List,String,Int] = IorT(List(Left(Answer not known.)))
scala> IorT.fromOption[List](Some(42), "Answer not known.")
res1: cats.data.IorT[List,String,Int] = IorT(List(Right(42)))
Transforms an F[Option]
into an IorT
, using the second argument if the Option
is a None
.
Transforms an F[Option]
into an IorT
, using the second argument if the Option
is a None
.
scala> import cats.data.IorT
scala> import cats.implicits._
scala> val o: Option[Int] = None
scala> IorT.fromOptionF(List(o), "Answer not known.")
res0: cats.data.IorT[List,String,Int] = IorT(List(Left(Answer not known.)))
scala> IorT.fromOptionF(List(Option(42)), "Answer not known.")
res1: cats.data.IorT[List,String,Int] = IorT(List(Right(42)))
Similar to fromOptionF
but the left is carried from monadic F[_]
context when the option is None
Similar to fromOptionF
but the left is carried from monadic F[_]
context when the option is None
Creates a left version of IorT[F, A, B]
from a F[A]
Creates a left version of IorT[F, A, B]
from a F[A]
scala> import cats.data.IorT
scala> import cats.implicits._
scala> IorT.left[Int](Option("err"))
res0: cats.data.IorT[Option,String,Int] = IorT(Some(Left(err)))
Creates a left version of IorT[F, A, B]
from a A
Creates a left version of IorT[F, A, B]
from a A
scala> import cats.data.IorT
scala> import cats.implicits._
scala> IorT.leftT[Option, Int]("err")
res0: cats.data.IorT[Option,String,Int] = IorT(Some(Left(err)))
Alias for right
Alias for right
scala> import cats.data.IorT
scala> import cats.implicits._
scala> val o: Option[Int] = Some(3)
scala> val n: Option[Int] = None
scala> IorT.liftF(o)
res0: cats.data.IorT[Option,Nothing,Int] = IorT(Some(Right(3)))
scala> IorT.liftF(n)
res1: cats.data.IorT[Option,Nothing,Int] = IorT(None)
Same as liftF, but expressed as a FunctionK for use with IorT.mapK
scala> import cats._, data._, implicits._
scala> val a: OptionT[Eval, Int] = 1.pure[OptionT[Eval, *]]
scala> val b: OptionT[IorT[Eval, String, *], Int] = a.mapK(IorT.liftK)
scala> b.value.value.value
res0: cats.data.Ior[String,Option[Int]] = Right(Some(1))
Creates a right version of IorT[F, A, B]
from a B
Creates a right version of IorT[F, A, B]
from a B
scala> import cats.data.IorT
scala> import cats.implicits._
scala> IorT.pure[Option, String](3)
res0: cats.data.IorT[Option,String,Int] = IorT(Some(Right(3)))
Inherited methods
An alternative Parallel implementation which merges the semantics of the outer Parallel (the F[_] effect) with the effects of the inner one (the Ior). The inner Parallel has the semantics of Ior's Parallel, while the outer has the semantics of parallel ''evaluation'' (in most cases). The default Parallel for IorT, when the nested F also has a Parallel, is to strictly take the semantics of the nested F and to short-circuit any lefts (often, errors) in a left-to-right fashion, mirroring the semantics of Applicative on IorT. This instance is different in that it will not ''short-circuit'' but instead accumulate all lefts according to the supplied Semigroup.
An alternative Parallel implementation which merges the semantics of the outer Parallel (the F[_] effect) with the effects of the inner one (the Ior). The inner Parallel has the semantics of Ior's Parallel, while the outer has the semantics of parallel ''evaluation'' (in most cases). The default Parallel for IorT, when the nested F also has a Parallel, is to strictly take the semantics of the nested F and to short-circuit any lefts (often, errors) in a left-to-right fashion, mirroring the semantics of Applicative on IorT. This instance is different in that it will not ''short-circuit'' but instead accumulate all lefts according to the supplied Semigroup.
implicit val p: Parallel[IorT[IO, Chain[Error], *]] = IorT.accumulatingParallel
val a = IorT(IO(Chain(error1).leftIor[Unit]))
val b = IorT(IO(Chain(error2).leftIor[Unit]))
(a, b).parTupled // => IorT(IO(Chain(error1, error2).leftIor[Unit]))
- Inherited from
- IorTInstances
Implicits
Inherited implicits
- Inherited from
- IorTInstances
- Inherited from
- IorTInstances2
- Inherited from
- IorTInstances1
- Inherited from
- IorTInstances
- Inherited from
- IorTInstances1
- Inherited from
- IorTInstances1