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

    Executes a side effect function on the error 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.

    inspectError(fn)ケースを選ぶと、その流れだけを追えます

    Type Param

    R1

    The input Result or ResultAsync.

    Type Param

    R2

    The return type of the inspection function.

    Examples

    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 inspectError<Result.Result<never, "error">, void>(fn: (a: "error") => void): (result: Result.Result<never, "error">) => Result.Result<never, "error"> (+1 overload)

    Executes a side effect function on the error 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

    Failure Case

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.fail('error'),
    Result.inspectError((error) => console.log('Debug error:', error)),
    );
    // Console output: "Debug error: error"
    // Result: { type: 'Failure', error: 'error' }
    @example

    Success Case

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

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

    MDN Reference

    log
    ('Debug error:',
    error: "error"
    error
    )),
    ); // Console output: "Debug error: error" // Result: { type: 'Failure', error: 'error' }

    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 inspectError<Result.Result<42, never>, void>(fn: (a: never) => void): (result: Result.Result<42, never>) => Result.Result<42, never> (+1 overload)

    Executes a side effect function on the error 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

    Failure Case

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.fail('error'),
    Result.inspectError((error) => console.log('Debug error:', error)),
    );
    // Console output: "Debug error: error"
    // Result: { type: 'Failure', error: 'error' }
    @example

    Success Case

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

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

    MDN Reference

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

    See

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

    Call Signature

    inspectError<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

    inspectError<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>>