Function SyncEffect

  • Creates an SyncEffect<T, E> that represents a computation that may fail. This function does not execute the computation immediately, but defers execution.

    Type Parameters

    • T

      The type of the successful value.

    • E = unknown

      The type of the error.

    Parameters

    • fn: (() => T)

      A function that produces a value (or throws an error).

        • (): T
        • Returns T

    Returns SyncEffect<T, E>

    • A lazy effect that can be executed later.
    const safeDivide = SyncEffect(() => 10 / 2);
    console.log(safeDivide.run()); // Ok(5)