ProgramBuilder

open class ProgramBuilder<Action, Result>(endWith: (Result) -> Action, exceptional: (Throwable) -> Action = { e -> throw e })

This class provides a DSL to build initial-style programs, given the type of basic actions or instructions.

The type arguments are a bit tricky to use, due to the restrictions Kotlin's type system:

  • To create generic utilities over any program, you should use a completely polymorphic ProgramBuilder<Action, Result> as the extension receiver.

  • For each particular action you usually want to instantiate ProgramBuilder using <Action<A>, A> everywhere it appears. We highly recommend to create a typealias for it.

Constructors

Link copied to clipboard
constructor(endWith: (Result) -> Action, exceptional: (Throwable) -> Action = { e -> throw e })

Types

Link copied to clipboard
sealed interface State<Action, Result>

Functions

Link copied to clipboard
suspend fun <R> perform(f: ((R) -> Action) -> Action): R

Record the execution of an action which consumes a value of type R.

suspend fun <A, R> perform(f: (A, (R) -> Action) -> Action, x: A): R

Record the execution of an action which consumes a value of type R, and requires an additional argument of type A.

suspend fun <A, B, R> perform(f: (A, B, (R) -> Action) -> Action, x: A, y: B): R

Record the execution of an action which consumes a value of type R, and requires additional arguments of types A and B.

Link copied to clipboard
suspend fun performUnit(f: (() -> Action) -> Action)

Record the execution of an action which doesn't consume any value.

suspend fun <A> performUnit(f: (A, () -> Action) -> Action, x: A)

Record the execution of an action which doesn't consume any value, and requires an additional argument of type A.

suspend fun <A, B> performUnit(f: (A, B, () -> Action) -> Action, x: A, y: B)

Record the execution of an action which doesn't consume any value, and requires additional arguments of types A and B.