Package-level declarations

Types

Link copied to clipboard
annotation class DelicateRaiseApi
Link copied to clipboard
typealias EagerEffect<Error, A> = Raise<Error>.() -> A

The same behavior and API as Effect except without requiring suspend.

Link copied to clipboard
typealias Effect<Error, A> = suspend Raise<Error>.() -> A

Effect represents a function of suspend Raise<R>.() -> A, that short-circuit with a value of R or Throwable, or completes with a value of A.

Link copied to clipboard
annotation class ExperimentalTraceApi
Link copied to clipboard
class IgnoreErrorsRaise<N>(raise: Raise<N>, error: () -> N) : Raise<Any?>

Implementation of Raise used by ignoreErrors. You should never use this directly.

Link copied to clipboard

Implementation of Raise used by ior. You should never use this directly.

Link copied to clipboard
typealias Null = Nothing?
Link copied to clipboard
class NullableRaise(raise: Raise<Null>) : Raise<Null>

Implementation of Raise used by nullable. You should never use this directly.

Link copied to clipboard
class OptionRaise(raise: Raise<None>) : Raise<None>

Implementation of Raise used by option. You should never use this directly.

Link copied to clipboard
interface Raise<in Error>
Link copied to clipboard
open class RaiseAccumulate<Error>(val raise: Raise<NonEmptyList<Error>>) : Raise<Error>

Receiver type belonging to mapOrAccumulate. Allows binding both Either and EitherNel values for Either.Left types of Error. It extends Raise of Error, and allows working over Raise of NonEmptyList of Error as well.

Link copied to clipboard

RaiseCancellationException is a delicate api, and should be used with care. It drives the short-circuiting behavior of Raise.

Link copied to clipboard
annotation class RaiseDSL
Link copied to clipboard

Implementation of Raise used by result. You should never use this directly.

Link copied to clipboard

Tracing result. Allows to inspect the traces from where raise was called.

Functions

Link copied to clipboard
@JvmName(name = "catchReified")
inline fun <T : Throwable, A> catch(block: () -> A, catch: (t: T) -> A): A

Allows safely catching exceptions of type T without capturing CancellationException, or fatal exceptions like OutOfMemoryError or VirtualMachineError on the JVM.

inline fun <A> catch(block: () -> A, catch: (throwable: Throwable) -> A): A

Allows safely catching exceptions without capturing CancellationException, or fatal exceptions like OutOfMemoryError or VirtualMachineError on the JVM.

Link copied to clipboard

Runs the Effect and captures any nonFatalOrThrow exception into Result.

@JvmName(name = "catchReified")
infix inline fun <T : Throwable, Error, A> EagerEffect<Error, A>.catch(crossinline catch: Raise<Error>.(t: T) -> A): EagerEffect<Error, A>
infix fun <Error, A> EagerEffect<Error, A>.catch(catch: Raise<Error>.(throwable: Throwable) -> A): EagerEffect<Error, A>

@JvmName(name = "catchReified")
infix inline fun <T : Throwable, Error, A> Effect<Error, A>.catch(crossinline catch: suspend Raise<Error>.(t: T) -> A): Effect<Error, A>

A version of catch that refines the Throwable to T. This is useful for wrapping foreign code, such as database, network calls, etc.

infix fun <Error, A> Effect<Error, A>.catch(catch: suspend Raise<Error>.(throwable: Throwable) -> A): Effect<Error, A>

Catch any unexpected exceptions, and catch them. You can either return a value a new value of A, or short-circuit the effect by raising with a value of Error, or raise an exception into suspend.

Link copied to clipboard
inline fun <Error, A> eagerEffect(noinline block: Raise<Error>.() -> A): EagerEffect<Error, A>
Link copied to clipboard
inline fun <Error, A> effect(noinline block: suspend Raise<Error>.() -> A): Effect<Error, A>
Link copied to clipboard
inline fun <Error, A> either(block: Raise<Error>.() -> A): Either<Error, A>

Runs a computation block using Raise, and return its outcome as Either.

Link copied to clipboard
inline fun <Error> Raise<Error>.ensure(condition: Boolean, raise: () -> Error)

Ensures that the condition is met; otherwise, Raise.raises a logical failure of type Error.

Link copied to clipboard
inline fun <Error, B : Any> Raise<Error>.ensureNotNull(value: B?, raise: () -> Error): B

Ensures that the value is not null; otherwise, Raise.raises a logical failure of type Error.

Link copied to clipboard
@JvmName(name = "_foldOrThrow")
inline fun <Error, A, B> fold(block: Raise<Error>.() -> A, recover: (error: Error) -> B, transform: (value: A) -> B): B

The most general way to execute a computation using Raise. Depending on the outcome of the block, one of the two continuations is run:

@JvmName(name = "_fold")
inline fun <Error, A, B> fold(block: Raise<Error>.() -> A, catch: (throwable: Throwable) -> B, recover: (error: Error) -> B, transform: (value: A) -> B): B

The most general way to execute a computation using Raise. Depending on the outcome of the block, one of the three continuations is run:

Link copied to clipboard
inline fun <Error, A, B> EagerEffect<Error, A>.fold(recover: (error: Error) -> B, transform: (value: A) -> B): B
inline fun <Error, A, B> EagerEffect<Error, A>.fold(catch: (throwable: Throwable) -> B, recover: (error: Error) -> B, transform: (value: A) -> B): B

invoke the EagerEffect and fold the result:

suspend fun <Error, A, B> Effect<Error, A>.fold(recover: suspend (error: Error) -> B, transform: suspend (value: A) -> B): B
suspend fun <Error, A, B> Effect<Error, A>.fold(catch: suspend (throwable: Throwable) -> B, recover: suspend (error: Error) -> B, transform: suspend (value: A) -> B): B

invoke the Effect and fold the result:

Link copied to clipboard
inline fun <Error, A> Raise<Error>.forEachAccumulating(iterable: Iterable<A>, combine: (Error, Error) -> Error, block: RaiseAccumulate<Error>.(A) -> Unit)
inline fun <Error, A> Raise<Error>.forEachAccumulating(iterator: Iterator<A>, combine: (Error, Error) -> Error, block: RaiseAccumulate<Error>.(A) -> Unit)
inline fun <Error, A> Raise<Error>.forEachAccumulating(sequence: Sequence<A>, combine: (Error, Error) -> Error, block: RaiseAccumulate<Error>.(A) -> Unit)
Link copied to clipboard
fun <A> EagerEffect<Nothing, A>.get(): A
suspend fun <A> Effect<Nothing, A>.get(): A
Link copied to clipboard
infix inline fun <Error, A> EagerEffect<Error, A>.getOrElse(recover: (error: Error) -> A): A
infix inline suspend fun <Error, A> Effect<Error, A>.getOrElse(recover: suspend (error: Error) -> A): A
Link copied to clipboard

Run the EagerEffect by returning A, or null if raised with Error.

suspend fun <Error, A> Effect<Error, A>.getOrNull(): A?

Run the Effect by returning A, or null if raised with Error.

Link copied to clipboard
inline fun <Error, A> ior(noinline combineError: (Error, Error) -> Error, block: IorRaise<Error>.() -> A): Ior<Error, A>

Runs a computation block using Raise, and return its outcome as Ior.

Link copied to clipboard
inline fun <Error, A> iorNel(noinline combineError: (NonEmptyList<Error>, NonEmptyList<Error>) -> NonEmptyList<Error> = { a, b -> a + b }, block: IorRaise<NonEmptyList<Error>>.() -> A): IorNel<Error, A>

Run a computation block using Raise. and return its outcome as IorNel.

Link copied to clipboard
infix fun <Error, OtherError, A> EagerEffect<Error, A>.mapError(transform: (error: Error) -> OtherError): EagerEffect<OtherError, A>

Transform the raised value Error of the EagerEffect into OtherError. This results in an EagerEffect that returns a value of A or raises OtherError.

infix fun <Error, OtherError, A> Effect<Error, A>.mapError(transform: suspend (error: Error) -> OtherError): Effect<OtherError, A>

Transform the raised value Error of the Effect into OtherError, or raise an exception into suspend. This results in an Effect that returns a value of A or raises OtherError.

Link copied to clipboard
inline fun <Error, A, B> Raise<NonEmptyList<Error>>.mapOrAccumulate(nonEmptyList: NonEmptyList<A>, transform: RaiseAccumulate<Error>.(A) -> B): NonEmptyList<B>

Accumulate the errors obtained by executing the transform over every element of NonEmptyList.

inline fun <Error, A, B> Raise<NonEmptyList<Error>>.mapOrAccumulate(nonEmptySet: NonEmptySet<A>, transform: RaiseAccumulate<Error>.(A) -> B): NonEmptySet<B>

Accumulate the errors obtained by executing the transform over every element of NonEmptySet.

inline fun <Error, A, B> Raise<NonEmptyList<Error>>.mapOrAccumulate(iterable: Iterable<A>, transform: RaiseAccumulate<Error>.(A) -> B): List<B>

Accumulate the errors obtained by executing the transform over every element of iterable.

inline fun <K, Error, A, B> Raise<NonEmptyList<Error>>.mapOrAccumulate(map: Map<K, A>, transform: RaiseAccumulate<Error>.(Map.Entry<K, A>) -> B): Map<K, B>
inline fun <K, Error, A, B> Raise<Error>.mapOrAccumulate(map: Map<K, A>, combine: (Error, Error) -> Error, transform: RaiseAccumulate<Error>.(Map.Entry<K, A>) -> B): Map<K, B>

inline fun <Error, A, B> Raise<NonEmptyList<Error>>.mapOrAccumulate(sequence: Sequence<A>, transform: RaiseAccumulate<Error>.(A) -> B): List<B>

Accumulate the errors obtained by executing the transform over every element of sequence.

inline fun <Error, A, B> Raise<Error>.mapOrAccumulate(iterable: Iterable<A>, combine: (Error, Error) -> Error, transform: RaiseAccumulate<Error>.(A) -> B): List<B>

Transform every element of iterable using the given transform, or accumulate all the occurred errors using combine.

inline fun <Error, A, B> Raise<Error>.mapOrAccumulate(sequence: Sequence<A>, combine: (Error, Error) -> Error, transform: RaiseAccumulate<Error>.(A) -> B): List<B>

Transform every element of sequence using the given transform, or accumulate all the occurred errors using combine.

Link copied to clipboard
@JvmName(name = "_merge")
inline fun <A> merge(block: Raise<A>.() -> A): A

Execute the Raise context function resulting in A or any logical error of type A. Does not distinguish between normal results and errors, thus you can consider return and raise to be semantically equivalent inside.

Link copied to clipboard
fun <A> EagerEffect<A, A>.merge(): A
suspend fun <A> Effect<A, A>.merge(): A
Link copied to clipboard
inline fun <A> nullable(block: NullableRaise.() -> A): A?

Runs a computation block using Raise, and return its outcome as nullable type, where null represents logical failure.

Link copied to clipboard
inline fun <A> option(block: OptionRaise.() -> A): Option<A>

Runs a computation block using Raise, and return its outcome as Option.

Link copied to clipboard
inline fun <Error, A> recover(block: Raise<Error>.() -> A, recover: (error: Error) -> A): A

Execute the Raise context function resulting in A or any logical error of type Error, and recover by providing a transform Error into a fallback value of type A. Base implementation of effect { f() } getOrElse { fallback() }.

@JvmName(name = "recoverReified")
inline fun <T : Throwable, Error, A> recover(block: Raise<Error>.() -> A, recover: (error: Error) -> A, catch: (t: T) -> A): A
inline fun <Error, A> recover(block: Raise<Error>.() -> A, recover: (error: Error) -> A, catch: (throwable: Throwable) -> A): A

Execute the Raise context function resulting in A or any logical error of type Error, and recover by providing a transform Error into a fallback value of type A, or catch any unexpected exceptions by providing a transform Throwable into a fallback value of type A,

Link copied to clipboard

infix fun <Error, OtherError, A> Effect<Error, A>.recover(recover: suspend Raise<OtherError>.(error: Error) -> A): Effect<OtherError, A>

Catch the raised value Error of the Effect. You can either return a value a new value of A, or short-circuit the effect by raising with a value of OtherError, or raise an exception into suspend.

Link copied to clipboard
inline fun <A> result(block: ResultRaise.() -> A): Result<A>

Runs a computation block using Raise, and return its outcome as Result.

Link copied to clipboard

Run the EagerEffect by returning Either.Right of A, or Either.Left of Error.

suspend fun <Error, A> Effect<Error, A>.toEither(): Either<Error, A>

Run the Effect by returning Either.Right of A, or Either.Left of Error.

Link copied to clipboard

Run the EagerEffect by returning Ior.Right of A, or Ior.Left of Error.

suspend fun <Error, A> Effect<Error, A>.toIor(): Ior<Error, A>

Run the Effect by returning Ior.Right of A, or Ior.Left of Error.

Link copied to clipboard
inline fun <Error, A> EagerEffect<Error, A>.toOption(recover: (error: Error) -> Option<A>): Option<A>

Run the EagerEffect by returning Option of A, recover run the fallback lambda and returning its result of Option of A.

suspend fun <Error, A> Effect<Error, A>.toOption(recover: suspend (error: Error) -> Option<A>): Option<A>

Run the Effect by returning Option of A, recover run the fallback lambda and returning its result of Option of A.

Link copied to clipboard

Run the EagerEffect by returning Result of A, or Result.Failure if raised with Throwable.

suspend fun <A> Effect<Throwable, A>.toResult(): Result<A>

Run the Effect by returning Result of A, or Result.Failure if raised with Throwable.

inline fun <Error, A> EagerEffect<Error, A>.toResult(recover: (error: Error) -> Result<A>): Result<A>

Run the EagerEffect by returning Result of A, recover run the fallback lambda and returning its result of Result of A.

suspend fun <Error, A> Effect<Error, A>.toResult(recover: suspend (error: Error) -> Result<A>): Result<A>

Run the Effect by returning Result of A, recover run the fallback lambda and returning its result of Result of A.

Link copied to clipboard
inline fun <Error, A> Raise<Error>.traced(block: Raise<Error>.() -> A, trace: (trace: Trace, error: Error) -> Unit): A

Inspect a Trace value of Error.

Link copied to clipboard
inline fun <Error, OtherError, A> Raise<Error>.withError(transform: (OtherError) -> Error, block: Raise<OtherError>.() -> A): A

Execute the Raise context function resulting in A or any logical error of type OtherError, and transform any raised OtherError into Error, which is raised to the outer Raise.

Link copied to clipboard
inline fun <Error, A, B, C> Raise<NonEmptyList<Error>>.zipOrAccumulate(action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, block: (A, B) -> C): C

Accumulate the errors from running both action1 and action2.

inline fun <Error, A, B, C> Raise<Error>.zipOrAccumulate(combine: (Error, Error) -> Error, action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, block: (A, B) -> C): C

Accumulate the errors from running both action1 and action2 using the given combine function.

inline fun <Error, A, B, C, D> Raise<NonEmptyList<Error>>.zipOrAccumulate(action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, action3: RaiseAccumulate<Error>.() -> C, block: (A, B, C) -> D): D

Accumulate the errors from running action1, action2, and action3.

inline fun <Error, A, B, C, D> Raise<Error>.zipOrAccumulate(combine: (Error, Error) -> Error, action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, action3: RaiseAccumulate<Error>.() -> C, block: (A, B, C) -> D): D

Accumulate the errors from running action1, action2, and action3 using the given combine.

inline fun <Error, A, B, C, D, E> Raise<NonEmptyList<Error>>.zipOrAccumulate(action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, action3: RaiseAccumulate<Error>.() -> C, action4: RaiseAccumulate<Error>.() -> D, block: (A, B, C, D) -> E): E

Accumulate the errors from running action1, action2, action3, and action4.

inline fun <Error, A, B, C, D, E> Raise<Error>.zipOrAccumulate(combine: (Error, Error) -> Error, action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, action3: RaiseAccumulate<Error>.() -> C, action4: RaiseAccumulate<Error>.() -> D, block: (A, B, C, D) -> E): E

Accumulate the errors from running action1, action2, action3, and action4 using the given combine.

inline fun <Error, A, B, C, D, E, F> Raise<NonEmptyList<Error>>.zipOrAccumulate(action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, action3: RaiseAccumulate<Error>.() -> C, action4: RaiseAccumulate<Error>.() -> D, action5: RaiseAccumulate<Error>.() -> E, block: (A, B, C, D, E) -> F): F

Accumulate the errors from running action1, action2, action3, action4, and action5.

inline fun <Error, A, B, C, D, E, F> Raise<Error>.zipOrAccumulate(combine: (Error, Error) -> Error, action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, action3: RaiseAccumulate<Error>.() -> C, action4: RaiseAccumulate<Error>.() -> D, action5: RaiseAccumulate<Error>.() -> E, block: (A, B, C, D, E) -> F): F

Accumulate the errors from running action1, action2, action3, action4, and action5 using the given combine.

inline fun <Error, A, B, C, D, E, F, G> Raise<NonEmptyList<Error>>.zipOrAccumulate(action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, action3: RaiseAccumulate<Error>.() -> C, action4: RaiseAccumulate<Error>.() -> D, action5: RaiseAccumulate<Error>.() -> E, action6: RaiseAccumulate<Error>.() -> F, block: (A, B, C, D, E, F) -> G): G

Accumulate the errors from running action1, action2, action3, action4, action5, and action6.

inline fun <Error, A, B, C, D, E, F, G> Raise<Error>.zipOrAccumulate(combine: (Error, Error) -> Error, action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, action3: RaiseAccumulate<Error>.() -> C, action4: RaiseAccumulate<Error>.() -> D, action5: RaiseAccumulate<Error>.() -> E, action6: RaiseAccumulate<Error>.() -> F, block: (A, B, C, D, E, F) -> G): G

Accumulate the errors from running action1, action2, action3, action4, action5, and action6 using the given combine.

inline fun <Error, A, B, C, D, E, F, G, H> Raise<NonEmptyList<Error>>.zipOrAccumulate(action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, action3: RaiseAccumulate<Error>.() -> C, action4: RaiseAccumulate<Error>.() -> D, action5: RaiseAccumulate<Error>.() -> E, action6: RaiseAccumulate<Error>.() -> F, action7: RaiseAccumulate<Error>.() -> G, block: (A, B, C, D, E, F, G) -> H): H

Accumulate the errors from running action1, action2, action3, action4, action5, action6, and action7.

inline fun <Error, A, B, C, D, E, F, G, H> Raise<Error>.zipOrAccumulate(combine: (Error, Error) -> Error, action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, action3: RaiseAccumulate<Error>.() -> C, action4: RaiseAccumulate<Error>.() -> D, action5: RaiseAccumulate<Error>.() -> E, action6: RaiseAccumulate<Error>.() -> F, action7: RaiseAccumulate<Error>.() -> G, block: (A, B, C, D, E, F, G) -> H): H

Accumulate the errors from running action1, action2, action3, action4, action5, action6, and action7 using the given combine.

inline fun <Error, A, B, C, D, E, F, G, H, I> Raise<NonEmptyList<Error>>.zipOrAccumulate(action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, action3: RaiseAccumulate<Error>.() -> C, action4: RaiseAccumulate<Error>.() -> D, action5: RaiseAccumulate<Error>.() -> E, action6: RaiseAccumulate<Error>.() -> F, action7: RaiseAccumulate<Error>.() -> G, action8: RaiseAccumulate<Error>.() -> H, block: (A, B, C, D, E, F, G, H) -> I): I

Accumulate the errors from running action1, action2, action3, action4, action5, action6, action7, and action8.

inline fun <Error, A, B, C, D, E, F, G, H, I> Raise<Error>.zipOrAccumulate(combine: (Error, Error) -> Error, action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, action3: RaiseAccumulate<Error>.() -> C, action4: RaiseAccumulate<Error>.() -> D, action5: RaiseAccumulate<Error>.() -> E, action6: RaiseAccumulate<Error>.() -> F, action7: RaiseAccumulate<Error>.() -> G, action8: RaiseAccumulate<Error>.() -> H, block: (A, B, C, D, E, F, G, H) -> I): I

Accumulate the errors from running action1, action2, action3, action4, action5, action6, action7, and action8 using the given combine.

inline fun <Error, A, B, C, D, E, F, G, H, I, J> Raise<NonEmptyList<Error>>.zipOrAccumulate(action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, action3: RaiseAccumulate<Error>.() -> C, action4: RaiseAccumulate<Error>.() -> D, action5: RaiseAccumulate<Error>.() -> E, action6: RaiseAccumulate<Error>.() -> F, action7: RaiseAccumulate<Error>.() -> G, action8: RaiseAccumulate<Error>.() -> H, action9: RaiseAccumulate<Error>.() -> I, block: (A, B, C, D, E, F, G, H, I) -> J): J

Accumulate the errors from running action1, action2, action3, action4, action5, action6, action7, action8, and action9.

inline fun <Error, A, B, C, D, E, F, G, H, I, J> Raise<Error>.zipOrAccumulate(combine: (Error, Error) -> Error, action1: RaiseAccumulate<Error>.() -> A, action2: RaiseAccumulate<Error>.() -> B, action3: RaiseAccumulate<Error>.() -> C, action4: RaiseAccumulate<Error>.() -> D, action5: RaiseAccumulate<Error>.() -> E, action6: RaiseAccumulate<Error>.() -> F, action7: RaiseAccumulate<Error>.() -> G, action8: RaiseAccumulate<Error>.() -> H, action9: RaiseAccumulate<Error>.() -> I, block: (A, B, C, D, E, F, G, H, I) -> J): J

Accumulate the errors from running action1, action2, action3, action4, action5, action6, action7, action8, and action9 using the given combine.