ContT

cats.data.ContT
See theContT companion class
object ContT

Attributes

Companion
class
Source
ContT.scala
Graph
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
ContT.type

Members list

Type members

Inherited types

type MirroredElemLabels <: Tuple

The names of the product elements

The names of the product elements

Attributes

Inherited from:
Mirror
Source
Mirror.scala

The name of the type

The name of the type

Attributes

Inherited from:
Mirror
Source
Mirror.scala

Value members

Concrete methods

def apply[M[_], A, B](fn: (B => M[A]) => M[A]): ContT[M, A, B]

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
def callCC[M[_], A, B, C](f: (B => ContT[M, A, C]) => ContT[M, A, B])(implicit M: Defer[M]): ContT[M, A, B]

Attributes

Source
ContT.scala
def defer[M[_], A, B](b: => B): ContT[M, A, B]

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
def later[M[_], A, B](fn: => (B => M[A]) => M[A]): ContT[M, A, B]

Similar to apply but evaluation of the argument is deferred.

Similar to apply but evaluation of the argument is deferred.

Attributes

Source
ContT.scala
def liftF[M[_], A, B](mb: M[B])(implicit M: FlatMap[M]): ContT[M, A, B]

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
def liftK[M[_], B](implicit M: FlatMap[M]): FunctionK[M, [_] =>> ContT[M, B, _$8]]

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
def pure[M[_], A, B](b: B): ContT[M, A, B]

Lift a pure value into ContT

Lift a pure value into ContT

Attributes

Source
ContT.scala
def resetT[M[_] : Defer, A, B](contT: ContT[M, B, B]): ContT[M, A, B]

Attributes

Source
ContT.scala
def shiftT[M[_] : Defer, A, B](f: (B => M[A]) => ContT[M, A, A]): ContT[M, A, B]

Attributes

Source
ContT.scala
def tailRecM[M[_], A, B, C](a: A)(fn: A => ContT[M, C, Either[A, B]])(implicit M: Defer[M]): ContT[M, C, B]

Attributes

Source
ContT.scala

Implicits

Implicits

implicit def catsDataContTDefer[M[_], B]: Defer[[_] =>> ContT[M, B, _$19]]

Attributes

Source
ContT.scala
implicit def catsDataContTMonad[M[_] : Defer, A]: Monad[[_] =>> ContT[M, A, _$22]]

Attributes

Source
ContT.scala