object ContT
- Companion
- class
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Type members
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
}
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)
}
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)
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)
def resetT[M[_], A, B](contT: ContT[M, B, B])(`evidence$1`: Monad[M], `evidence$2`: Defer[M]): ContT[M, A, B]
def shiftT[M[_], A, B](f: B => M[A] => ContT[M, A, A])(`evidence$3`: Applicative[M], `evidence$4`: Defer[M]): ContT[M, A, B]