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.andThrough.md.
  • 日本語
  • Function: andThrough()

    Runs an additional computation using the success value of a Result or ResultAsync, but returns the original result if the additional computation is successful.

    If either the original result or the side effect result is a Failure, that failure is returned. Useful for running validations or side effects without altering the main result on success.

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

    Type Param

    R1

    The input Result or ResultAsync.

    Type Param

    R2

    The result type returned by fn.

    Examples

    Success Case

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const result: Result.Result<5, "Must be > 0">
    result
    =
    import Result
    Result
    .
    function pipe<Result.Result<5, never>, Result.Result<5, "Must be > 0">>(a: Result.Result<5, never>, ab: (a: Result.Result<5, never>) => Result.Result<5, "Must be > 0">): Result.Result<5, "Must be > 0"> (+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<5>(value: 5): Result.Result<5, 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
    (5),
    import Result
    Result
    .
    function andThrough<Result.Result<5, never>, Result.Success<null> | Result.Failure<"Must be > 0">>(fn: (a: 5) => Result.Success<null> | Result.Failure<"Must be > 0">): (result: Result.Result<5, never>) => Result.Result<5, "Must be > 0"> (+1 overload)

    Runs an additional computation using the success value of a Result or ResultAsync , but returns the original result if the additional computation is successful.

    If either the original result or the side effect result is a Failure , that failure is returned. Useful for running validations or side effects without altering the main result on success.

    @typeParamR1 - The input Result or ResultAsync .@typeParamR2 - The result type returned by fn.@example

    Success Case

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.succeed(5),
    Result.andThrough((x) => {
    return x > 0 ? Result.succeed(null) : Result.fail('Must be > 0');
    }),
    );
    // { type: 'Success', value: 5 }
    @example

    Failure Case (input is a Failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.fail('error'),
    Result.andThrough((x) => {
    return x > 0 ? Result.succeed(null) : Result.fail('Must be > 0');
    }),
    );
    // { type: 'Failure', error: 'error' }
    @example

    Failure Case (function returns a Failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.succeed(-10),
    Result.andThrough((x) => {
    return x > 0 ? Result.succeed(null) : Result.fail('Must be > 0');
    }),
    );
    // { type: 'Failure', error: 'Must be > 0' }
    @seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators
    andThrough
    ((
    x: 5
    x
    ) => {
    return
    x: 5
    x
    > 0 ?
    import Result
    Result
    .
    function succeed<null>(value: null): Result.Result<null, 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
    (null) :
    import Result
    Result
    .
    function fail<"Must be > 0">(error: "Must be > 0"): Result.Result<never, "Must be > 0"> (+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
    ('Must be > 0');
    }), ); // { type: 'Success', value: 5 }

    Failure Case (input is a Failure)

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const result: Result.Result<never, "error" | "Must be > 0">
    result
    =
    import Result
    Result
    .
    function pipe<Result.Result<never, "error">, Result.Result<never, "error" | "Must be > 0">>(a: Result.Result<never, "error">, ab: (a: Result.Result<never, "error">) => Result.Result<never, "error" | "Must be > 0">): Result.Result<never, "error" | "Must be > 0"> (+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 andThrough<Result.Result<never, "error">, Result.Success<null> | Result.Failure<"Must be > 0">>(fn: (a: never) => Result.Success<null> | Result.Failure<"Must be > 0">): (result: Result.Result<never, "error">) => Result.Result<never, "error" | "Must be > 0"> (+1 overload)

    Runs an additional computation using the success value of a Result or ResultAsync , but returns the original result if the additional computation is successful.

    If either the original result or the side effect result is a Failure , that failure is returned. Useful for running validations or side effects without altering the main result on success.

    @typeParamR1 - The input Result or ResultAsync .@typeParamR2 - The result type returned by fn.@example

    Success Case

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.succeed(5),
    Result.andThrough((x) => {
    return x > 0 ? Result.succeed(null) : Result.fail('Must be > 0');
    }),
    );
    // { type: 'Success', value: 5 }
    @example

    Failure Case (input is a Failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.fail('error'),
    Result.andThrough((x) => {
    return x > 0 ? Result.succeed(null) : Result.fail('Must be > 0');
    }),
    );
    // { type: 'Failure', error: 'error' }
    @example

    Failure Case (function returns a Failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.succeed(-10),
    Result.andThrough((x) => {
    return x > 0 ? Result.succeed(null) : Result.fail('Must be > 0');
    }),
    );
    // { type: 'Failure', error: 'Must be > 0' }
    @seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators
    andThrough
    ((
    x: never
    x
    ) => {
    return
    x: never
    x
    > 0 ?
    import Result
    Result
    .
    function succeed<null>(value: null): Result.Result<null, 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
    (null) :
    import Result
    Result
    .
    function fail<"Must be > 0">(error: "Must be > 0"): Result.Result<never, "Must be > 0"> (+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
    ('Must be > 0');
    }), ); // { type: 'Failure', error: 'error' }

    Failure Case (function returns a Failure)

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const result: Result.Result<-10, "Must be > 0">
    result
    =
    import Result
    Result
    .
    function pipe<Result.Result<-10, never>, Result.Result<-10, "Must be > 0">>(a: Result.Result<-10, never>, ab: (a: Result.Result<-10, never>) => Result.Result<-10, "Must be > 0">): Result.Result<-10, "Must be > 0"> (+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<-10>(value: -10): Result.Result<-10, 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
    (-10),
    import Result
    Result
    .
    function andThrough<Result.Result<-10, never>, Result.Success<null> | Result.Failure<"Must be > 0">>(fn: (a: -10) => Result.Success<null> | Result.Failure<"Must be > 0">): (result: Result.Result<-10, never>) => Result.Result<-10, "Must be > 0"> (+1 overload)

    Runs an additional computation using the success value of a Result or ResultAsync , but returns the original result if the additional computation is successful.

    If either the original result or the side effect result is a Failure , that failure is returned. Useful for running validations or side effects without altering the main result on success.

    @typeParamR1 - The input Result or ResultAsync .@typeParamR2 - The result type returned by fn.@example

    Success Case

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.succeed(5),
    Result.andThrough((x) => {
    return x > 0 ? Result.succeed(null) : Result.fail('Must be > 0');
    }),
    );
    // { type: 'Success', value: 5 }
    @example

    Failure Case (input is a Failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.fail('error'),
    Result.andThrough((x) => {
    return x > 0 ? Result.succeed(null) : Result.fail('Must be > 0');
    }),
    );
    // { type: 'Failure', error: 'error' }
    @example

    Failure Case (function returns a Failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.succeed(-10),
    Result.andThrough((x) => {
    return x > 0 ? Result.succeed(null) : Result.fail('Must be > 0');
    }),
    );
    // { type: 'Failure', error: 'Must be > 0' }
    @seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators
    andThrough
    ((
    x: -10
    x
    ) => {
    return
    x: -10
    x
    > 0 ?
    import Result
    Result
    .
    function succeed<null>(value: null): Result.Result<null, 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
    (null) :
    import Result
    Result
    .
    function fail<"Must be > 0">(error: "Must be > 0"): Result.Result<never, "Must be > 0"> (+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
    ('Must be > 0');
    }), ); // { type: 'Failure', error: 'Must be > 0' }

    See

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

    Call Signature

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

    Type Parameters

    R1

    R1 extends ResultMaybeAsync<any, any>

    R2

    R2 extends ResultMaybeAsync<any, any>

    Parameters

    fn

    (a) => R2

    Returns

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

    Call Signature

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

    Type Parameters

    F

    F extends (a) => ResultMaybeAsync<any, any>

    Parameters

    fn

    F

    Returns

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