rhodonite
    Preparing search index...

    Class Ok<T, ErrObj>

    Represents a successful result containing a value. This class indicates that an operation completed successfully.

    Type Parameters

    • T

      The type of the success value

    • ErrObj

      The type of the error object (for type compatibility)

    Hierarchy

    Implements

    Index
    • Creates a new CResult instance.

      Type Parameters

      • T

        The type of the success value

      • ErrObj

        The type of the error object (for type compatibility)

      Parameters

      • Optionalval: T | RnError<ErrObj>

        The value to store (either success value or error)

      Returns Ok<T, ErrObj>

    val?: T | RnError<ErrObj>

    The value to store (either success value or error)

    • Chains operations on this successful result. Applies the provided function to the contained value.

      Type Parameters

      • U

        The type of the new success value

      Parameters

      • f: (value: T) => Result<U, ErrObj>

        Function to apply to the success value

      Returns Result<U, ErrObj>

      The result of applying the function

    • Safely extracts the contained success value.

      Returns T

      The contained success value

    • Type guard indicating this is not an Err result.

      Returns this is Err<T, ErrObj>

      Always false for Ok instances

    • Type guard indicating this is an Ok result.

      Returns this is Ok<T, ErrObj>

      Always true for Ok instances

    • Pattern matching implementation for Result types.

      Type Parameters

      • R

        The type of the return value from the Ok function

      • ErrObj2

        The type of the new error object

      Parameters

      Returns Result<R, ErrObj2>

      A new Result containing the result of the pattern matching

      If the result is neither Ok nor Err

    • Gets the name of this result class.

      Returns string

      The constructor name ('Ok' or 'Err')

    • Returns this Ok result unchanged since it's already successful. The alternative function is not called.

      Type Parameters

      • U

        The type of the alternative success value

      Parameters

      Returns Result<U, ErrObj>

      This Ok result cast to the new type

    • Always returns true for Ok results.

      Returns this is Ok<T, ErrObj>

      Always true

      Use isOk() instead

    • Safely returns the contained value.

      Returns T

      The contained success value

    • Returns the contained value since this is a successful result. The compensation function is not called.

      Parameters

      Returns T

      The contained success value