For AI agents: the complete documentation index is available at /byethrow/llms.txt, the full documentation bundle is available at /byethrow/llms-full.txt, and this page is available as Markdown at /byethrow/api/functions/Result.inspect.md.
  • English
  • Function: inspect()

    Executes a side effect function on the success value of a Result or ResultAsync, without modifying the original result. This is useful for debugging, logging, or performing other side effects while maintaining the original value and error state.

    inspect(fn)Select a case to follow its path

    Type Param

    R1

    The input Result or ResultAsync.

    Type Param

    R2

    The return type of the inspection function.

    Examples

    Success Case

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const result: Result.Result<42, never>
    result
    =
    import Result
    Result
    .
    function pipe<Result.Result<42, never>, Result.Result<42, never>>(a: Result.Result<42, never>, ab: (a: Result.Result<42, never>) => Result.Result<42, never>): Result.Result<42, never> (+25 overloads)

    Applies a sequence of functions to a value, from left to right.

    This utility enables function composition in a left-to-right manner. It supports up to 26 chained functions from A through Z.

    @typeParamA - The initial input value type.@typeParamB-Z - Intermediate and final function return types.@paramvalue - The initial input value.@paramfunctions - Additional unary functions composing of the previous result.@returnsThe final result after applying all functions.@example
    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
      2,
      x => x + 1,
      x => x * 3,
      x => `Result: ${x}`
    );
    // Result: 9
    @categoryUtilities
    pipe
    (
    import Result
    Result
    .
    function succeed<42>(value: 42): Result.Result<42, never> (+1 overload)

    Creates a Success result from a given value.

    Passing a Promise is allowed, but it is recommended to await it before passing to succeed.

    @typeParamT - The type of the value to wrap.@returnsA Result containing the given value.@example

    Synchronous Usage

    import { Result } from '@praha/byethrow';
    
    const result = Result.succeed(42);
    // Result.Result<42, never>
    @example

    With No Value

    import { Result } from '@praha/byethrow';
    
    const result = Result.succeed();
    // Result.Result<void, never>
    @seecollect - For collect multiple Results into a single Result.@seesequence - For sequence multiple Results into a single Result.@categoryCreators
    succeed
    (42),
    import Result
    Result
    .
    function inspect<Result.Result<42, never>, void>(fn: (a: 42) => void): (result: Result.Result<42, never>) => Result.Result<42, never> (+1 overload)

    Executes a side effect function on the success value of a Result or ResultAsync , without modifying the original result. This is useful for debugging, logging, or performing other side effects while maintaining the original value and error state.

    @typeParamR1 - The input Result or ResultAsync .@typeParamR2 - The return type of the inspection function.@example

    Success Case

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.succeed(42),
    Result.inspect((value) => console.log('Debug:', value)),
    );
    // Console output: "Debug: 42"
    // Result: { type: 'Success', value: 42 }
    @example

    Failure Case

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.fail('error'),
    Result.inspect((value) => console.log('Debug:', value)),
    );
    // No console output
    // Result: { type: 'Failure', error: 'error' }
    @seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators
    inspect
    ((
    value: 42
    value
    ) =>
    var console: Console
    console
    .
    Console.log(...data: any[]): void

    The console.log() static method outputs a message to the console.

    MDN Reference

    log
    ('Debug:',
    value: 42
    value
    )),
    ); // Console output: "Debug: 42" // Result: { type: 'Success', value: 42 }

    Failure Case

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const result: Result.Result<never, "error">
    result
    =
    import Result
    Result
    .
    function pipe<Result.Result<never, "error">, Result.Result<never, "error">>(a: Result.Result<never, "error">, ab: (a: Result.Result<never, "error">) => Result.Result<never, "error">): Result.Result<never, "error"> (+25 overloads)

    Applies a sequence of functions to a value, from left to right.

    This utility enables function composition in a left-to-right manner. It supports up to 26 chained functions from A through Z.

    @typeParamA - The initial input value type.@typeParamB-Z - Intermediate and final function return types.@paramvalue - The initial input value.@paramfunctions - Additional unary functions composing of the previous result.@returnsThe final result after applying all functions.@example
    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
      2,
      x => x + 1,
      x => x * 3,
      x => `Result: ${x}`
    );
    // Result: 9
    @categoryUtilities
    pipe
    (
    import Result
    Result
    .
    function fail<"error">(error: "error"): Result.Result<never, "error"> (+1 overload)

    Creates a Failure result from a given error.

    Passing a Promise is allowed, but it is recommended to await it before passing to fail.

    @typeParamE - The type of the error to wrap.@returnsA Result containing the given error.@example

    Synchronous Usage

    import { Result } from '@praha/byethrow';
    
    const result = Result.fail('Something went wrong');
    // Result.Result<never, string>
    @example

    With No Value

    import { Result } from '@praha/byethrow';
    
    const result = Result.fail();
    // Result.Result<never, void>
    @seecollect - For collect multiple Results into a single Result.@seesequence - For sequence multiple Results into a single Result.@categoryCreators
    fail
    ('error'),
    import Result
    Result
    .
    function inspect<Result.Result<never, "error">, void>(fn: (a: never) => void): (result: Result.Result<never, "error">) => Result.Result<never, "error"> (+1 overload)

    Executes a side effect function on the success value of a Result or ResultAsync , without modifying the original result. This is useful for debugging, logging, or performing other side effects while maintaining the original value and error state.

    @typeParamR1 - The input Result or ResultAsync .@typeParamR2 - The return type of the inspection function.@example

    Success Case

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.succeed(42),
    Result.inspect((value) => console.log('Debug:', value)),
    );
    // Console output: "Debug: 42"
    // Result: { type: 'Success', value: 42 }
    @example

    Failure Case

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.fail('error'),
    Result.inspect((value) => console.log('Debug:', value)),
    );
    // No console output
    // Result: { type: 'Failure', error: 'error' }
    @seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators
    inspect
    ((
    value: never
    value
    ) =>
    var console: Console
    console
    .
    Console.log(...data: any[]): void

    The console.log() static method outputs a message to the console.

    MDN Reference

    log
    ('Debug:',
    value: never
    value
    )),
    ); // No console output // Result: { type: 'Failure', error: 'error' }

    See

    pipe - It is recommended to use this function with the pipe function for better readability and composability.

    Call Signature

    inspect<R1, R2>(fn): (result) => ResultFor<R1 | R2, InferSuccess<R1>, InferFailure<R1>>

    Type Parameters

    R1

    R1 extends ResultMaybeAsync<any, any>

    R2

    R2

    Parameters

    fn

    (a) => R2

    Returns

    (result) => ResultFor<R1 | R2, InferSuccess<R1>, InferFailure<R1>>

    Call Signature

    inspect<F>(fn): <R1>(result) => ResultFor<R1 | ReturnType<F>, InferSuccess<R1>, InferFailure<R1>>

    Type Parameters

    F

    F extends (a) => unknown

    Parameters

    fn

    F

    Returns

    <R1>(result) => ResultFor<R1 | ReturnType<F>, InferSuccess<R1>, InferFailure<R1>>