@praha/byethrow
    Preparing search index...

    Function bind

    Chains another Result-producing computation and merges its success value into the existing object under the specified key.

    • If the original result is a Failure, it is returned as-is.
    • If the next result is a Failure, it is returned as-is.
    • If both are Success, a new object is returned by shallow-merging: the original success object and { [name]: nextSuccess }.

    This is useful for building up objects in a compositional and type-safe way, especially in validation or data-fetching pipelines.

    The key to assign the result of the fn computation.

    The input Result or ResultAsync.

    The result type returned by fn.

    import { Result } from '@praha/byethrow';

    const result = Result.pipe(
    Result.succeed({ name: 'Alice' }),
    Result.bind('age', (user) => Result.succeed(20)),
    );
    // { type: 'Success', value: { name: 1, age: 20 } }
    import { Result } from '@praha/byethrow';

    const result = Result.pipe(
    Result.fail('error'),
    Result.bind('age', (user) => Result.succeed(20)),
    );
    // { type: 'Failure', error: 'error' }
    import { Result } from '@praha/byethrow';

    const result = Result.pipe(
    Result.succeed({ name: 'Alice' }),
    Result.bind('age', (user) => Result.fail('error')),
    );
    // { type: 'Failure', error: 'error' }

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