@praha/byethrow
    Preparing search index...

    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.

    The input Result or ResultAsync.

    The result type returned by fn.

    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 }
    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' }
    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' }

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