IO

open class IO<A>(thunk: suspend () -> A) : Effect<A>

A concrete implementation of Effect for handling side-effecting computations.

The IO class represents a computation that may perform side effects and produce a value of type A. It provides methods for transforming, chaining, and handling errors in a functional and type-safe manner. Computations are lazily evaluated when executed using run or runSync.

Parameters

A

The type of the value produced by the computation.

thunk

The suspendable computation that produces a value of type A.

See also

Constructors

Link copied to clipboard
constructor(thunk: suspend () -> A)

Types

Link copied to clipboard

Properties

Link copied to clipboard
val thunk: suspend () -> A

Functions

Link copied to clipboard
open override fun <B> ap(function: Effect<(A) -> B>): IO<B>

Applies a function contained in another Effect to the value of this IO.

Link copied to clipboard
open override fun <B> flatMap(transform: suspend (A) -> Effect<B>): IO<B>

Chains this IO with another Effect using the provided transform function.

Link copied to clipboard
open override fun handleError(recover: suspend (Throwable) -> A): IO<A>

Handles errors in this IO by recovering with a default value.

Link copied to clipboard
open override fun <B> map(transform: suspend (A) -> B): IO<B>

Transforms the result of this IO using the provided transform function.

Link copied to clipboard
open override fun recoverWith(recover: suspend (Throwable) -> Effect<A>): IO<A>

Handles errors in this IO by recovering with another Effect.

Link copied to clipboard
open suspend fun run(defaultValueOnFailure: A, block: suspend Effect.RunDSL<A>.() -> Unit): A

Executes the computation asynchronously, returning a default value on failure.

open suspend fun run(defaultValueOnFailure: suspend () -> A, block: suspend Effect.RunDSL<A>.() -> Unit): A

Executes the computation asynchronously, using a suspendable default value provider on failure.

Link copied to clipboard
open fun runSync(defaultValueOnFailure: A, block: suspend Effect.RunDSL<A>.() -> Unit): A

Executes the computation synchronously, returning a default value on failure.

open fun runSync(defaultValueOnFailure: suspend () -> A, block: suspend Effect.RunDSL<A>.() -> Unit): A

Executes the computation synchronously, using a suspendable default value provider on failure.

Link copied to clipboard
open override fun void(): IO<Unit>

Converts this IO into an IO that produces a Unit value.