Cont

interface Cont<R, A>

Cont represents a suspending computation that runs will either

  • Complete with a value of A.

  • Short-circuit with a value of R.

So Cont is defined by fold, to map both values of R and A to a value of B.

Functions

attempt
Link copied to clipboard
open fun attempt(): Cont<R, Result<A>>

Runs the Cont and captures any NonFatal exception into Result.

fold
Link copied to clipboard
abstract suspend fun <B> fold(recover: suspend (R) -> B, transform: suspend (A) -> B): B

Runs the suspending computation by creating a Continuation, and running the fold function over the computation.

open suspend fun <B> fold(error: suspend (error: Throwable) -> B, recover: suspend (R) -> B, transform: suspend (A) -> B): B

Like fold but also allows folding over any unexpected Throwable that might have occurred.

handleError
Link copied to clipboard
open fun handleError(recover: suspend (R) -> A): Cont<Nothing, A>
handleErrorWith
Link copied to clipboard
open fun <R2> handleErrorWith(recover: suspend (R) -> Cont<R2, A>): Cont<R2, A>
redeem
Link copied to clipboard
open fun <B> redeem(recover: suspend (R) -> B, transform: suspend (A) -> B): Cont<Nothing, B>
redeemWith
Link copied to clipboard
open fun <R2, B> redeemWith(recover: suspend (R) -> Cont<R2, B>, transform: suspend (A) -> Cont<R2, B>): Cont<R2, B>
toEither
Link copied to clipboard
open suspend fun toEither(): Either<R, A>

fold the Cont into an Either. Where the shifted value R is mapped to Either.Left, and result value A is mapped to Either.Right.

toIor
Link copied to clipboard
open suspend fun toIor(): Ior<R, A>

fold the Cont into an Ior. Where the shifted value R is mapped to Ior.Left, and result value A is mapped to Ior.Right.

toOption
Link copied to clipboard
open suspend fun toOption(orElse: suspend (R) -> Option<A>): Option<A>

fold the Cont into an Option. Where the shifted value R is mapped to Option by the provided function orElse, and result value A is mapped to Some.

toValidated
Link copied to clipboard
open suspend fun toValidated(): Validated<R, A>

fold the Cont into an Validated. Where the shifted value R is mapped to Validated.Invalid, and result value A is mapped to Validated.Valid.

Extensions

toOption
Link copied to clipboard
suspend fun <A> Cont<None, A>.toOption(): Option<A>

Sources

common source
Link copied to clipboard