arrow-streams / arrow.streams.internal / FreeC


sealed class FreeC<F, out R> : FreeCOf<F, R>

Free Monad with Catch (and Interruption).

FreeC provides mechanism for ensuring stack safety and capturing any exceptions that may arise during computation.

Furthermore, it may capture Interruption of the evaluation, although FreeC itself does not have any interruptible behaviour per se.

Interruption cause may be captured in FreeC.Interrupted and allows user to pass along any information relevant to interpreter.

Typically the FreeC user provides interpretation of FreeC in form of ViewL structure through the ViewL.fold function, that allows to step FreeC via series of Results (FreeC.Pure, FreeC.Fail and FreeC.Interrupted) and FreeC step (ViewL.View).


Result Emulated sealed trait. Never extend this interface! **Working with FreeC.Result must be done using Result.fold **interface Result<out R>


viewL val viewL: ViewL<F, R>


asHandler fun asHandler(e: Throwable): FreeC<F, R>
flatMap fun <R2> flatMap(f: (R) -> FreeCOf<F, R2>): FreeC<F, R2>
map fun <R2> map(f: (R) -> R2): FreeC<F, R2>
toString open fun toString(): String
translate open fun <G> translate(f: FunctionK<F, G>): FreeC<G, R>

Companion Object Functions

defer fun <F, R> defer(fr: () -> FreeCOf<F, R>): FreeC<F, R>
functionKF fun <F> functionKF(): FunctionK<F, FreeCPartialOf<F>>
interrupted fun <F, A, X> interrupted(interruptContext: X, failure: Option<Throwable>): FreeC<F, A>
just fun <F, R> just(r: R): FreeC<F, R>
liftF fun <F, A> liftF(f: Kind<F, A>): FreeC<F, A>
pureContinuation fun <F, R> pureContinuation(): (Result<R>) -> FreeC<F, R>
raiseError fun <F, R> raiseError(error: Throwable): FreeC<F, R>
tailRecM fun <F, A, B> tailRecM(a: A, f: (A) -> FreeC<F, Either<A, B>>): FreeC<F, B>
unit fun <F> unit(): FreeC<F, Unit>

Extension Functions

fold fun <F, R, A> FreeC<F, R>.fold(pure: (R) -> A, fail: (Throwable) -> A, interrupted: (Any?, Option<Throwable>) -> A, eval: (Kind<F, R>) -> A, bind: (FreeC<F, Any?>, (Result<Any?>) -> FreeCOf<F, R>) -> A): A
step Takes one evaluation step in the Free monad, re-associating left-nested binds in the process.tailrec fun <S, A> FreeC<S, A>.step(): FreeC<S, A>