Chains another Result-producing computation and merges its success value into the existing object under the specified key.
{ [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.
fn
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 } } Copy
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' } Copy
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' } Copy
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.
Chains another Result-producing computation and merges its success value into the existing object under the specified key.
{ [name]: nextSuccess }
.This is useful for building up objects in a compositional and type-safe way, especially in validation or data-fetching pipelines.
Type Param: N
The key to assign the result of the
fn
computation.Type Param: R1
The input Result or ResultAsync.
Type Param: R2
The result type returned by
fn
.Example: Success Case
Example: Failure Case (input is a Failure)
Example: Failure Case (function returns a Failure)
See
pipe - It is recommended to use this function with the pipe function for better readability and composability.