Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Cont alias to ContT #3403

Merged
merged 2 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/AndThen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import cats.arrow.{ArrowChoice, CommutativeArrow}
* Example:
*
* {{{
* val seed = AndThen((x: Int) => x + 1))
* val seed = AndThen((x: Int) => x + 1)
* val f = (0 until 10000).foldLeft(seed)((acc, _) => acc.andThen(_ + 1))
*
* // This should not trigger stack overflow ;-)
Expand Down
19 changes: 19 additions & 0 deletions core/src/main/scala/cats/data/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,23 @@ package object data extends ScalaVersionSpecificPackage {
def apply[S, A](f: S => A, s: S): Store[S, A] =
RepresentableStore[S => *, S, A](f, s)
}

type Cont[A, B] = ContT[Eval, A, B]

object Cont {
def apply[A, B](f: (B => Eval[A]) => Eval[A]): Cont[A, B] =
ContT[Eval, A, B](f)

def pure[A, B](b: B): Cont[A, B] =
ContT.pure[Eval, A, B](b)

def defer[A, B](b: => B): Cont[A, B] =
ContT.defer[Eval, A, B](b)

def later[A, B](fn: => (B => Eval[A]) => Eval[A]): Cont[A, B] =
ContT.later(fn)

def tailRecM[A, B, C](a: A)(f: A => Cont[C, Either[A, B]]): Cont[C, B] =
ContT.tailRecM(a)(f)
}
}