cats.data.ContT
See theContT companion class
object ContT
Attributes
- Companion
- class
- Source
- ContT.scala
- Graph
-
- Supertypes
- Self type
-
ContT.type
Members list
Type members
Inherited types
The names of the product elements
The name of the type
Value members
Concrete methods
Build a computation that makes use of a callback, also known as a continuation.
Build a computation that makes use of a callback, also known as a continuation.
Example:
ContT.apply { callback =>
for {
a <- doFirstThing()
b <- doSecondThing(a)
c <- callback(b)
d <- doFourthThing(c)
} yield d
}
Attributes
- Source
- ContT.scala
Attributes
- Source
- ContT.scala
Similar to pure but evaluation of the argument is deferred.
Similar to pure but evaluation of the argument is deferred.
This is useful for building a computation which calls its continuation as the final step. Instead of writing:
ContT.apply { cb =>
val x = foo()
val y = bar(x)
val z = baz(y)
cb(z)
}
you can write:
ContT.defer {
val x = foo()
val y = bar(x)
baz(y)
}
Attributes
- Source
- ContT.scala
Similar to apply but evaluation of the argument is deferred.
Lifts the M[B]
into an ContT[M, A, B]
.
Lifts the M[B]
into an ContT[M, A, B]
.
scala> import cats._, data._, implicits._
scala> val a: EitherT[Eval, String, Int] = 1.pure[EitherT[Eval, String, *]]
scala> val c: cats.data.ContT[EitherT[Eval, String, *], Int, Int] = ContT.liftF(a)
scala> c.run(EitherT.rightT(_)).value.value
res0: Either[String, Int] = Right(1)
scala> c.run(_ => EitherT.leftT("a")).value.value
res1: Either[String, Int] = Left(a)
Attributes
- Source
- ContT.scala
Same as liftF, but expressed as a FunctionK for use with mapK
Same as liftF, but expressed as a FunctionK for use with mapK
scala> import cats._, data._
scala> trait Foo[F[_]] { def bar: F[Int] }
scala> def mapK[F[_], G[_]](fooF: Foo[F])(f: F ~> G): Foo[G] = new Foo[G] { def bar: G[Int] = f(fooF.bar) }
scala> val eitherTFoo = new Foo[EitherT[Eval, String, *]] { def bar = EitherT.rightT(1) }
scala> val contTFoo: Foo[ContT[EitherT[Eval, String, *], Int, *]] = mapK(eitherTFoo)(ContT.liftK)
scala> contTFoo.bar.run(EitherT.rightT(_)).value.value
res0: Either[String, Int] = Right(1)
Attributes
- Source
- ContT.scala
Lift a pure value into ContT
Attributes
- Source
- ContT.scala
Implicits
In this article