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

    Processes multiple Result or ResultAsync values into a single result. If all results are Success, returns a Success containing all values. If any result is a Failure, immediately stops processing and returns a Failure with that single error.

    Unlike collect, which processes all results and collects all errors, sequence stops at the first error and returns only that error.

    sequence(results)Select a case to follow its path

    Type Param

    X

    The input type (object or array of Results).

    Examples

    Object of Results (all succeed)

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const result: Result.Result<{
        name: "Alice";
        age: 20;
    }, never>
    result
    =
    import Result
    Result
    .
    function sequence<{
        name: Result.Result<"Alice", never>;
        age: Result.Result<20, never>;
    }>(x: {
        name: Result.Result<"Alice", never>;
        age: Result.Result<20, never>;
    }): Result.Result<{
        name: "Alice";
        age: 20;
    }, never> (+4 overloads)

    Processes multiple Result or ResultAsync values into a single result. If all results are Success , returns a Success containing all values. If any result is a Failure , immediately stops processing and returns a Failure with that single error.

    Unlike collect , which processes all results and collects all errors, sequence stops at the first error and returns only that error.

    @typeParamX - The input type (object or array of Results).@example

    Object of Results (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence({
    name: Result.succeed('Alice'),
    age: Result.succeed(20),
    });
    // { type: 'Success', value: { name: 'Alice', age: 20 } }
    @example

    Object of Results (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence({
    name: Result.succeed('Alice'),
    age: Result.fail('Invalid age'),
    });
    // { type: 'Failure', error: 'Invalid age' }
    @example

    Array of Results (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence([
    Result.succeed(1),
    Result.succeed(2),
    ]);
    // { type: 'Success', value: [1, 2, 3] }
    @example

    Array of Results (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence([
    Result.succeed(1),
    Result.fail('error1'),
    ]);
    // { type: 'Failure', error: 'error1' }
    @example

    Using a mapper function (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence(['1', '2', '3'], (value) => {
    const number = Number(value);
    return Number.isNaN(number)
    ? Result.fail(`Invalid number: ${value}`)
    : Result.succeed(number);
    });
    // { type: 'Success', value: [1, 2, 3] }
    @example

    Using a mapper function (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence(['1', 'invalid', '3'], (value) => {
    const number = Number(value);
    return Number.isNaN(number)
    ? Result.fail(`Invalid number: ${value}`)
    : Result.succeed(number);
    });
    // { type: 'Failure', error: 'Invalid number: invalid' }
    @categoryUtilities
    sequence
    ({
    name: Result.Result<"Alice", never>
    name
    :
    import Result
    Result
    .
    function succeed<"Alice">(value: "Alice"): Result.Result<"Alice", 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
    ('Alice'),
    age: Result.Result<20, never>
    age
    :
    import Result
    Result
    .
    function succeed<20>(value: 20): Result.Result<20, 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
    (20),
    }); // { type: 'Success', value: { name: 'Alice', age: 20 } }

    Object of Results (stops at first failure)

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const result: Result.Result<{
        name: "Alice";
        age: never;
    }, "Invalid age">
    result
    =
    import Result
    Result
    .
    function sequence<{
        name: Result.Result<"Alice", never>;
        age: Result.Result<never, "Invalid age">;
    }>(x: {
        name: Result.Result<"Alice", never>;
        age: Result.Result<never, "Invalid age">;
    }): Result.Result<{
        name: "Alice";
        age: never;
    }, "Invalid age"> (+4 overloads)

    Processes multiple Result or ResultAsync values into a single result. If all results are Success , returns a Success containing all values. If any result is a Failure , immediately stops processing and returns a Failure with that single error.

    Unlike collect , which processes all results and collects all errors, sequence stops at the first error and returns only that error.

    @typeParamX - The input type (object or array of Results).@example

    Object of Results (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence({
    name: Result.succeed('Alice'),
    age: Result.succeed(20),
    });
    // { type: 'Success', value: { name: 'Alice', age: 20 } }
    @example

    Object of Results (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence({
    name: Result.succeed('Alice'),
    age: Result.fail('Invalid age'),
    });
    // { type: 'Failure', error: 'Invalid age' }
    @example

    Array of Results (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence([
    Result.succeed(1),
    Result.succeed(2),
    ]);
    // { type: 'Success', value: [1, 2, 3] }
    @example

    Array of Results (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence([
    Result.succeed(1),
    Result.fail('error1'),
    ]);
    // { type: 'Failure', error: 'error1' }
    @example

    Using a mapper function (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence(['1', '2', '3'], (value) => {
    const number = Number(value);
    return Number.isNaN(number)
    ? Result.fail(`Invalid number: ${value}`)
    : Result.succeed(number);
    });
    // { type: 'Success', value: [1, 2, 3] }
    @example

    Using a mapper function (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence(['1', 'invalid', '3'], (value) => {
    const number = Number(value);
    return Number.isNaN(number)
    ? Result.fail(`Invalid number: ${value}`)
    : Result.succeed(number);
    });
    // { type: 'Failure', error: 'Invalid number: invalid' }
    @categoryUtilities
    sequence
    ({
    name: Result.Result<"Alice", never>
    name
    :
    import Result
    Result
    .
    function succeed<"Alice">(value: "Alice"): Result.Result<"Alice", 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
    ('Alice'),
    age: Result.Result<never, "Invalid age">
    age
    :
    import Result
    Result
    .
    function fail<"Invalid age">(error: "Invalid age"): Result.Result<never, "Invalid age"> (+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
    ('Invalid age'),
    }); // { type: 'Failure', error: 'Invalid age' }

    Array of Results (all succeed)

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const result: Result.Result<[1, 2], never>
    result
    =
    import Result
    Result
    .
    function sequence<[Result.Result<1, never>, Result.Result<2, never>]>(x: [Result.Result<1, never>, Result.Result<2, never>]): Result.Result<[1, 2], never> (+4 overloads)

    Processes multiple Result or ResultAsync values into a single result. If all results are Success , returns a Success containing all values. If any result is a Failure , immediately stops processing and returns a Failure with that single error.

    Unlike collect , which processes all results and collects all errors, sequence stops at the first error and returns only that error.

    @typeParamX - The input type (object or array of Results).@example

    Object of Results (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence({
    name: Result.succeed('Alice'),
    age: Result.succeed(20),
    });
    // { type: 'Success', value: { name: 'Alice', age: 20 } }
    @example

    Object of Results (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence({
    name: Result.succeed('Alice'),
    age: Result.fail('Invalid age'),
    });
    // { type: 'Failure', error: 'Invalid age' }
    @example

    Array of Results (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence([
    Result.succeed(1),
    Result.succeed(2),
    ]);
    // { type: 'Success', value: [1, 2, 3] }
    @example

    Array of Results (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence([
    Result.succeed(1),
    Result.fail('error1'),
    ]);
    // { type: 'Failure', error: 'error1' }
    @example

    Using a mapper function (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence(['1', '2', '3'], (value) => {
    const number = Number(value);
    return Number.isNaN(number)
    ? Result.fail(`Invalid number: ${value}`)
    : Result.succeed(number);
    });
    // { type: 'Success', value: [1, 2, 3] }
    @example

    Using a mapper function (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence(['1', 'invalid', '3'], (value) => {
    const number = Number(value);
    return Number.isNaN(number)
    ? Result.fail(`Invalid number: ${value}`)
    : Result.succeed(number);
    });
    // { type: 'Failure', error: 'Invalid number: invalid' }
    @categoryUtilities
    sequence
    ([
    import Result
    Result
    .
    function succeed<1>(value: 1): Result.Result<1, 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
    (1),
    import Result
    Result
    .
    function succeed<2>(value: 2): Result.Result<2, 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
    (2),
    ]); // { type: 'Success', value: [1, 2, 3] }

    Array of Results (stops at first failure)

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const result: Result.Result<[1, never], "error1">
    result
    =
    import Result
    Result
    .
    function sequence<[Result.Result<1, never>, Result.Result<never, "error1">]>(x: [Result.Result<1, never>, Result.Result<never, "error1">]): Result.Result<[1, never], "error1"> (+4 overloads)

    Processes multiple Result or ResultAsync values into a single result. If all results are Success , returns a Success containing all values. If any result is a Failure , immediately stops processing and returns a Failure with that single error.

    Unlike collect , which processes all results and collects all errors, sequence stops at the first error and returns only that error.

    @typeParamX - The input type (object or array of Results).@example

    Object of Results (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence({
    name: Result.succeed('Alice'),
    age: Result.succeed(20),
    });
    // { type: 'Success', value: { name: 'Alice', age: 20 } }
    @example

    Object of Results (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence({
    name: Result.succeed('Alice'),
    age: Result.fail('Invalid age'),
    });
    // { type: 'Failure', error: 'Invalid age' }
    @example

    Array of Results (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence([
    Result.succeed(1),
    Result.succeed(2),
    ]);
    // { type: 'Success', value: [1, 2, 3] }
    @example

    Array of Results (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence([
    Result.succeed(1),
    Result.fail('error1'),
    ]);
    // { type: 'Failure', error: 'error1' }
    @example

    Using a mapper function (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence(['1', '2', '3'], (value) => {
    const number = Number(value);
    return Number.isNaN(number)
    ? Result.fail(`Invalid number: ${value}`)
    : Result.succeed(number);
    });
    // { type: 'Success', value: [1, 2, 3] }
    @example

    Using a mapper function (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence(['1', 'invalid', '3'], (value) => {
    const number = Number(value);
    return Number.isNaN(number)
    ? Result.fail(`Invalid number: ${value}`)
    : Result.succeed(number);
    });
    // { type: 'Failure', error: 'Invalid number: invalid' }
    @categoryUtilities
    sequence
    ([
    import Result
    Result
    .
    function succeed<1>(value: 1): Result.Result<1, 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
    (1),
    import Result
    Result
    .
    function fail<"error1">(error: "error1"): Result.Result<never, "error1"> (+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
    ('error1'),
    ]); // { type: 'Failure', error: 'error1' }

    Using a mapper function (all succeed)

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const result: Result.Result<[number, number, number], "Invalid number: 1" | "Invalid number: 2" | "Invalid number: 3">
    result
    =
    import Result
    Result
    .
    function sequence<["1", "2", "3"], (value: "1" | "2" | "3") => Result.Failure<"Invalid number: 1" | "Invalid number: 2" | "Invalid number: 3"> | Result.Success<number>>(x: ["1", "2", "3"], fn: (value: "1" | "2" | "3") => Result.Failure<"Invalid number: 1" | "Invalid number: 2" | "Invalid number: 3"> | Result.Success<number>): Result.Result<[number, number, number], "Invalid number: 1" | "Invalid number: 2" | "Invalid number: 3"> (+4 overloads)

    Processes multiple Result or ResultAsync values into a single result. If all results are Success , returns a Success containing all values. If any result is a Failure , immediately stops processing and returns a Failure with that single error.

    Unlike collect , which processes all results and collects all errors, sequence stops at the first error and returns only that error.

    @typeParamX - The input type (object or array of Results).@example

    Object of Results (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence({
    name: Result.succeed('Alice'),
    age: Result.succeed(20),
    });
    // { type: 'Success', value: { name: 'Alice', age: 20 } }
    @example

    Object of Results (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence({
    name: Result.succeed('Alice'),
    age: Result.fail('Invalid age'),
    });
    // { type: 'Failure', error: 'Invalid age' }
    @example

    Array of Results (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence([
    Result.succeed(1),
    Result.succeed(2),
    ]);
    // { type: 'Success', value: [1, 2, 3] }
    @example

    Array of Results (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence([
    Result.succeed(1),
    Result.fail('error1'),
    ]);
    // { type: 'Failure', error: 'error1' }
    @example

    Using a mapper function (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence(['1', '2', '3'], (value) => {
    const number = Number(value);
    return Number.isNaN(number)
    ? Result.fail(`Invalid number: ${value}`)
    : Result.succeed(number);
    });
    // { type: 'Success', value: [1, 2, 3] }
    @example

    Using a mapper function (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence(['1', 'invalid', '3'], (value) => {
    const number = Number(value);
    return Number.isNaN(number)
    ? Result.fail(`Invalid number: ${value}`)
    : Result.succeed(number);
    });
    // { type: 'Failure', error: 'Invalid number: invalid' }
    @categoryUtilities
    sequence
    (['1', '2', '3'], (
    value: "1" | "2" | "3"
    value
    ) => {
    const
    const number: number
    number
    =
    var Number: NumberConstructor
    (value?: any) => number

    An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.

    Number
    (
    value: "1" | "2" | "3"
    value
    );
    return
    var Number: NumberConstructor

    An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.

    Number
    .
    NumberConstructor.isNaN(number: unknown): boolean

    Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number). Unlike the global isNaN(), Number.isNaN() doesn't forcefully convert the parameter to a number. Only values of the type number, that are also NaN, result in true.

    @paramnumber A numeric value.
    isNaN
    (
    const number: number
    number
    )
    ?
    import Result
    Result
    .
    function fail<"Invalid number: 1" | "Invalid number: 2" | "Invalid number: 3">(error: "Invalid number: 1" | "Invalid number: 2" | "Invalid number: 3"): Result.Result<never, "Invalid number: 1" | "Invalid number: 2" | "Invalid number: 3"> (+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
    (`Invalid number: ${
    value: "1" | "2" | "3"
    value
    }`)
    :
    import Result
    Result
    .
    function succeed<number>(value: number): Result.Result<number, 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
    (
    const number: number
    number
    );
    }); // { type: 'Success', value: [1, 2, 3] }

    Using a mapper function (stops at first failure)

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const result: Result.Result<[number, number, number], "Invalid number: 1" | "Invalid number: invalid" | "Invalid number: 3">
    result
    =
    import Result
    Result
    .
    function sequence<["1", "invalid", "3"], (value: "1" | "invalid" | "3") => Result.Failure<"Invalid number: 1" | "Invalid number: invalid" | "Invalid number: 3"> | Result.Success<number>>(x: ["1", "invalid", "3"], fn: (value: "1" | "invalid" | "3") => Result.Failure<"Invalid number: 1" | "Invalid number: invalid" | "Invalid number: 3"> | Result.Success<number>): Result.Result<[number, number, number], "Invalid number: 1" | "Invalid number: invalid" | "Invalid number: 3"> (+4 overloads)

    Processes multiple Result or ResultAsync values into a single result. If all results are Success , returns a Success containing all values. If any result is a Failure , immediately stops processing and returns a Failure with that single error.

    Unlike collect , which processes all results and collects all errors, sequence stops at the first error and returns only that error.

    @typeParamX - The input type (object or array of Results).@example

    Object of Results (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence({
    name: Result.succeed('Alice'),
    age: Result.succeed(20),
    });
    // { type: 'Success', value: { name: 'Alice', age: 20 } }
    @example

    Object of Results (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence({
    name: Result.succeed('Alice'),
    age: Result.fail('Invalid age'),
    });
    // { type: 'Failure', error: 'Invalid age' }
    @example

    Array of Results (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence([
    Result.succeed(1),
    Result.succeed(2),
    ]);
    // { type: 'Success', value: [1, 2, 3] }
    @example

    Array of Results (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence([
    Result.succeed(1),
    Result.fail('error1'),
    ]);
    // { type: 'Failure', error: 'error1' }
    @example

    Using a mapper function (all succeed)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence(['1', '2', '3'], (value) => {
    const number = Number(value);
    return Number.isNaN(number)
    ? Result.fail(`Invalid number: ${value}`)
    : Result.succeed(number);
    });
    // { type: 'Success', value: [1, 2, 3] }
    @example

    Using a mapper function (stops at first failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.sequence(['1', 'invalid', '3'], (value) => {
    const number = Number(value);
    return Number.isNaN(number)
    ? Result.fail(`Invalid number: ${value}`)
    : Result.succeed(number);
    });
    // { type: 'Failure', error: 'Invalid number: invalid' }
    @categoryUtilities
    sequence
    (['1', 'invalid', '3'], (
    value: "1" | "invalid" | "3"
    value
    ) => {
    const
    const number: number
    number
    =
    var Number: NumberConstructor
    (value?: any) => number

    An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.

    Number
    (
    value: "1" | "invalid" | "3"
    value
    );
    return
    var Number: NumberConstructor

    An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.

    Number
    .
    NumberConstructor.isNaN(number: unknown): boolean

    Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number). Unlike the global isNaN(), Number.isNaN() doesn't forcefully convert the parameter to a number. Only values of the type number, that are also NaN, result in true.

    @paramnumber A numeric value.
    isNaN
    (
    const number: number
    number
    )
    ?
    import Result
    Result
    .
    function fail<"Invalid number: 1" | "Invalid number: invalid" | "Invalid number: 3">(error: "Invalid number: 1" | "Invalid number: invalid" | "Invalid number: 3"): Result.Result<never, "Invalid number: 1" | "Invalid number: invalid" | "Invalid number: 3"> (+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
    (`Invalid number: ${
    value: "1" | "invalid" | "3"
    value
    }`)
    :
    import Result
    Result
    .
    function succeed<number>(value: number): Result.Result<number, 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
    (
    const number: number
    number
    );
    }); // { type: 'Failure', error: 'Invalid number: invalid' }

    Call Signature

    sequence<X>(x): ResultFor<X[keyof X], { [K in string | number | symbol]: InferSuccess<X[K]> }, InferFailure<X[keyof X]>>

    Type Parameters

    X

    X extends Record<string, ResultMaybeAsync<any, any>>

    Parameters

    x

    X

    Returns

    ResultFor<X[keyof X], { [K in string | number | symbol]: InferSuccess<X[K]> }, InferFailure<X[keyof X]>>

    Call Signature

    sequence<X>(x): ResultFor<X[number], { [K in string | number | symbol]: InferSuccess<X[K]> }, InferFailure<X[number]>>

    Type Parameters

    X

    X extends ResultMaybeAsync<any, any>[]

    Parameters

    x

    X

    Returns

    ResultFor<X[number], { [K in string | number | symbol]: InferSuccess<X[K]> }, InferFailure<X[number]>>

    Call Signature

    sequence<X>(x): ResultFor<X[number], { [K in string | number | symbol]: InferSuccess<X[K]> }, InferFailure<X[number]>>

    Type Parameters

    X

    X extends readonly ResultMaybeAsync<any, any>[]

    Parameters

    x

    X

    Returns

    ResultFor<X[number], { [K in string | number | symbol]: InferSuccess<X[K]> }, InferFailure<X[number]>>

    Call Signature

    sequence<X, Fn>(x, fn): ResultFor<ReturnType<Fn>, { [K in string | number | symbol]: InferSuccess<Fn> }, InferFailure<Fn>>

    Type Parameters

    X

    X extends unknown[]

    Fn

    Fn extends (value) => ResultMaybeAsync<any, any>

    Parameters

    x

    X

    fn

    Fn

    Returns

    ResultFor<ReturnType<Fn>, { [K in string | number | symbol]: InferSuccess<Fn> }, InferFailure<Fn>>

    Call Signature

    sequence<X, Fn>(x, fn): ResultFor<ReturnType<Fn>, { [K in string | number | symbol]: InferSuccess<Fn> }, InferFailure<Fn>>

    Type Parameters

    X

    X extends readonly unknown[]

    Fn

    Fn extends (value) => ResultMaybeAsync<any, any>

    Parameters

    x

    X

    fn

    Fn

    Returns

    ResultFor<ReturnType<Fn>, { [K in string | number | symbol]: InferSuccess<Fn> }, InferFailure<Fn>>