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/guide/best-practices/importing-result.md.
  • 日本語
  • Result のインポート方法

    @praha/byethrow は、同じ関数群を Result と R の 2 つの名前でエクスポートしています。 どちらもツリーシェイキングに完全に対応しているため、どちらを選ぶかは純粋にスタイルの問題です。

    2 つのインポート方法

    Result:明示的なアプローチ

    Result ネームスペースを使うと、各関数がどこから来たものかが一目でわかります。

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const validateUser: (id: string) => Result.Failure<Error> | Result.Success<string>
    validateUser
    = (
    id: string
    id
    : string) => {
    if (!
    id: string
    id
    .
    String.startsWith(searchString: string, position?: number): boolean

    Returns true if the sequence of elements of searchString converted to a String is the same as the corresponding elements of this object (converted to a String) starting at position. Otherwise returns false.

    startsWith
    ('u')) {
    return
    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
    (new
    var Error: ErrorConstructor
    new (message?: string, options?: ErrorOptions) => Error (+1 overload)
    Error
    ('Invalid ID format'));
    } return
    import Result
    Result
    .
    function succeed<string>(value: string): Result.Result<string, 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
    (
    id: string
    id
    );
    }; const
    const result: Result.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error>
    result
    =
    import Result
    Result
    .
    function pipe<Result.Result<"u123", never>, Result.Result<string, Error>, Result.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error>>(a: Result.Result<"u123", never>, ab: (a: Result.Result<"u123", never>) => Result.Result<string, Error>, bc: (b: Result.Result<string, Error>) => Result.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error>): Result.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error> (+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<"u123">(value: "u123"): Result.Result<"u123", 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
    ('u123'),
    import Result
    Result
    .
    function andThen<Result.Result<"u123", never>, Result.Failure<Error> | Result.Success<string>>(fn: (a: "u123") => Result.Failure<Error> | Result.Success<string>): (result: Result.Result<"u123", never>) => Result.Result<string, Error> (+1 overload)

    Chains the next computation using the success value of a Result or ResultAsync . If the original result is a Failure , it is returned unchanged. Otherwise, the provided function is called, and its result is returned as-is.

    @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(3),
    Result.andThen((x) => Result.succeed(x * 2)),
    );
    // { type: 'Success', value: 6 }
    @example

    Failure Case (input is a Failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.fail('error'),
    Result.andThen((x) => Result.succeed(x * 2)),
    );
    // result: { type: 'Failure', error: 'error' }
    @example

    Failure Case (function returns a Failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.succeed(3),
    Result.andThen((x) => Result.fail('error: ' + x)),
    );
    // result: { type: 'Failure', error: 'error: 3' }
    @seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators
    andThen
    (
    const validateUser: (id: string) => Result.Failure<Error> | Result.Success<string>
    validateUser
    ),
    import Result
    Result
    .
    function map<Result.Result<string, Error>, {
        readonly id: string;
        readonly name: "John Doe";
    }>(fn: (a: string) => {
        readonly id: string;
        readonly name: "John Doe";
    }): (result: Result.Result<string, Error>) => Result.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error> (+1 overload)

    Applies a transformation function to the success value of a Result or ResultAsync . If the input is a Failure , it will be returned unchanged.

    @typeParamR1 - The input Result or ResultAsync .@typeParamT2 - The transformed success value type.@example

    Success Case

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.succeed(2),
    Result.map((x) => x * 10),
    );
    // { type: 'Success', value: 20 }
    @example

    Failure Case (unchanged)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.fail('error'),
    Result.map((x) => x * 10),
    );
    // { type: 'Failure', error: 'error' }
    @seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators
    map
    ((
    id: string
    id
    ) => ({
    id: string
    id
    ,
    name: "John Doe"
    name
    : 'John Doe' })),
    ); if (
    import Result
    Result
    .
    function isSuccess<Result.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error>>(result: Result.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error>): result is Result.Success<{
        readonly id: string;
        readonly name: "John Doe";
    }>

    Type guard to check if a Result is a Success .

    @typeParamR - The type of the result to check.@paramresult - The Result to check.@returnstrue if the result is a Success , otherwise false.@example
    import { Result } from '@praha/byethrow';
    
    const result: Result.Result<number, string> = { type: 'Success', value: 10 };
    if (Result.isSuccess(result)) {
      console.log(result.value); // Safe access to value
    }
    @categoryType Guards
    isSuccess
    (
    const result: Result.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error>
    result
    )) {
    var console: Console
    console
    .
    Console.log(...data: any[]): void

    The console.log() static method outputs a message to the console.

    MDN Reference

    log
    (
    const result: Result.Success<{
        readonly id: string;
        readonly name: "John Doe";
    }>
    result
    .
    value: {
        readonly id: string;
        readonly name: "John Doe";
    }
    value
    );
    }

    R:簡潔なエイリアス

    R エイリアスを使うと、パイプラインを短く書けます。

    import { 
    import R
    R
    } from '@praha/byethrow';
    const
    const validateUser: (id: string) => R.Failure<Error> | R.Success<string>
    validateUser
    = (
    id: string
    id
    : string) => {
    if (!
    id: string
    id
    .
    String.startsWith(searchString: string, position?: number): boolean

    Returns true if the sequence of elements of searchString converted to a String is the same as the corresponding elements of this object (converted to a String) starting at position. Otherwise returns false.

    startsWith
    ('u')) {
    return
    import R
    R
    .
    function fail<Error>(error: Error): R.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
    (new
    var Error: ErrorConstructor
    new (message?: string, options?: ErrorOptions) => Error (+1 overload)
    Error
    ('Invalid ID format'));
    } return
    import R
    R
    .
    function succeed<string>(value: string): R.Result<string, 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
    (
    id: string
    id
    );
    }; const
    const result: R.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error>
    result
    =
    import R
    R
    .
    function pipe<R.Result<"u123", never>, R.Result<string, Error>, R.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error>>(a: R.Result<"u123", never>, ab: (a: R.Result<"u123", never>) => R.Result<string, Error>, bc: (b: R.Result<string, Error>) => R.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error>): R.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error> (+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 R
    R
    .
    function succeed<"u123">(value: "u123"): R.Result<"u123", 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
    ('u123'),
    import R
    R
    .
    function andThen<R.Result<"u123", never>, R.Failure<Error> | R.Success<string>>(fn: (a: "u123") => R.Failure<Error> | R.Success<string>): (result: R.Result<"u123", never>) => R.Result<string, Error> (+1 overload)

    Chains the next computation using the success value of a Result or ResultAsync . If the original result is a Failure , it is returned unchanged. Otherwise, the provided function is called, and its result is returned as-is.

    @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(3),
    Result.andThen((x) => Result.succeed(x * 2)),
    );
    // { type: 'Success', value: 6 }
    @example

    Failure Case (input is a Failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.fail('error'),
    Result.andThen((x) => Result.succeed(x * 2)),
    );
    // result: { type: 'Failure', error: 'error' }
    @example

    Failure Case (function returns a Failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.succeed(3),
    Result.andThen((x) => Result.fail('error: ' + x)),
    );
    // result: { type: 'Failure', error: 'error: 3' }
    @seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators
    andThen
    (
    const validateUser: (id: string) => R.Failure<Error> | R.Success<string>
    validateUser
    ),
    import R
    R
    .
    function map<R.Result<string, Error>, {
        readonly id: string;
        readonly name: "John Doe";
    }>(fn: (a: string) => {
        readonly id: string;
        readonly name: "John Doe";
    }): (result: R.Result<string, Error>) => R.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error> (+1 overload)

    Applies a transformation function to the success value of a Result or ResultAsync . If the input is a Failure , it will be returned unchanged.

    @typeParamR1 - The input Result or ResultAsync .@typeParamT2 - The transformed success value type.@example

    Success Case

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.succeed(2),
    Result.map((x) => x * 10),
    );
    // { type: 'Success', value: 20 }
    @example

    Failure Case (unchanged)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.fail('error'),
    Result.map((x) => x * 10),
    );
    // { type: 'Failure', error: 'error' }
    @seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators
    map
    ((
    id: string
    id
    ) => ({
    id: string
    id
    ,
    name: "John Doe"
    name
    : 'John Doe' })),
    ); if (
    import R
    R
    .
    function isSuccess<R.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error>>(result: R.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error>): result is R.Success<{
        readonly id: string;
        readonly name: "John Doe";
    }>

    Type guard to check if a Result is a Success .

    @typeParamR - The type of the result to check.@paramresult - The Result to check.@returnstrue if the result is a Success , otherwise false.@example
    import { Result } from '@praha/byethrow';
    
    const result: Result.Result<number, string> = { type: 'Success', value: 10 };
    if (Result.isSuccess(result)) {
      console.log(result.value); // Safe access to value
    }
    @categoryType Guards
    isSuccess
    (
    const result: R.Result<{
        readonly id: string;
        readonly name: "John Doe";
    }, Error>
    result
    )) {
    var console: Console
    console
    .
    Console.log(...data: any[]): void

    The console.log() static method outputs a message to the console.

    MDN Reference

    log
    (
    const result: R.Success<{
        readonly id: string;
        readonly name: "John Doe";
    }>
    result
    .
    value: {
        readonly id: string;
        readonly name: "John Doe";
    }
    value
    );
    }

    このドキュメントの例では Result を使っていますが、R でもすべて同じように動作します。

    ツリーシェイキング

    名前空間としてインポートしていても、各関数は独立したエクスポートです。 モダンなバンドラーは、実際に使っている関数だけをバンドルに含めます。

    import { 
    import R
    R
    } from '@praha/byethrow';
    // バンドルに含まれるのは `fn` とその依存コードだけ。 // `andThen` や `pipe` などの関数は取り除かれる。 const
    const parseNumber: (input: string) => R.Result<number, Error>
    parseNumber
    =
    import R
    R
    .
    function fn<(input: string) => number, Error>(options: {
        try: (input: string) => number;
        catch: (error: unknown) => Error;
    }): (input: string) => R.Result<number, Error> (+3 overloads)

    Wraps a function that may throw and returns a new function that returns a Result or ResultAsync .

    You can use either a custom catch handler or rely on the safe: true option to assume the function cannot throw.

    @typeParamT - The function type to execute (sync or async) or a Promise type.@typeParamE - The error type to return if catch is used.@returnsA new function that returns a Result or ResultAsync wrapping the original function's return value or the caught error.@example

    Sync try-catch

    import { Result } from '@praha/byethrow';
    
    const fn = Result.fn({
    try: (x: number) => {
    if (x < 0) throw new Error('Negative!');
    return x * 2;
    },
    catch: (error) => new Error('Oops!', { cause: error }),
    });
    
    const result = fn(5); // Result.Result<number, Error>
    @example

    Sync safe

    import { Result } from '@praha/byethrow';
    
    const fn = Result.fn({
    safe: true,
    try: (x: number) => x + 1,
    });
    
    const result = fn(1); // Result.Result<number, never>
    @example

    Async try-catch

    import { Result } from '@praha/byethrow';
    
    const fn = Result.fn({
    try: async (id: string) => await fetch(`/api/data/${id}`),
    catch: (error) => new Error('Oops!', { cause: error }),
    });
    
    const result = await fn('abc'); // Result.ResultAsync<Response, Error>
    @example

    Async safe

    import { Result } from '@praha/byethrow';
    
    const fn = Result.fn({
    safe: true,
    try: async () => await Promise.resolve('ok'),
    });
    
    const result = await fn(); // Result.ResultAsync<string, never>
    @categoryCreators
    fn
    ({
    try: (input: string) => number
    try
    : (
    input: string
    input
    : string) =>
    function parseInt(string: string, radix?: number): number

    Converts a string to an integer.

    @paramstring A string to convert into a number.@paramradix A value between 2 and 36 that specifies the base of the number in string. If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal. All other strings are considered decimal.
    parseInt
    (
    input: string
    input
    , 10),
    catch: (error: unknown) => Error
    catch
    : () => new
    var Error: ErrorConstructor
    new (message?: string, options?: ErrorOptions) => Error (+1 overload)
    Error
    ('Invalid number'),
    });

    スタイルの選び方

    • Result:明示的で意味がわかりやすいコードを好む場合。初めて触れる人にとっても検索しやすくなります。
    • R:タイプ量を減らし、パイプラインをコンパクトに書きたい場合。

    2 つを混在させない

    どちらか一方のスタイルを選び、コードベース全体で統一することを強く推奨します。 混在させると、コードの一貫性が失われ、検索もしにくくなります。

    // @filename: mixed-imports.ts
    // ❌ 両方のスタイルを混在させている
    import { 
    import Result
    Result
    ,
    import R
    R
    } from '@praha/byethrow';
    const
    const validateId: (id: string) => Result.Result<string, never>
    validateId
    = (
    id: string
    id
    : string) => {
    return
    import Result
    Result
    .
    function succeed<string>(value: string): Result.Result<string, 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
    (
    id: string
    id
    );
    }; const
    const processData: Result.Result<string, never>
    processData
    =
    import R
    R
    .
    function pipe<Result.Result<"data", never>, Result.Result<string, never>>(a: Result.Result<"data", never>, ab: (a: Result.Result<"data", never>) => Result.Result<string, never>): Result.Result<string, never> (+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 R
    R
    .
    function succeed<"data">(value: "data"): Result.Result<"data", 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
    ('data'),
    import R
    R
    .
    function andThen<Result.Result<"data", never>, Result.Result<string, never>>(fn: (a: "data") => Result.Result<string, never>): (result: Result.Result<"data", never>) => Result.Result<string, never> (+1 overload)

    Chains the next computation using the success value of a Result or ResultAsync . If the original result is a Failure , it is returned unchanged. Otherwise, the provided function is called, and its result is returned as-is.

    @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(3),
    Result.andThen((x) => Result.succeed(x * 2)),
    );
    // { type: 'Success', value: 6 }
    @example

    Failure Case (input is a Failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.fail('error'),
    Result.andThen((x) => Result.succeed(x * 2)),
    );
    // result: { type: 'Failure', error: 'error' }
    @example

    Failure Case (function returns a Failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.succeed(3),
    Result.andThen((x) => Result.fail('error: ' + x)),
    );
    // result: { type: 'Failure', error: 'error: 3' }
    @seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators
    andThen
    (
    const validateId: (id: string) => Result.Result<string, never>
    validateId
    ),
    ); // @filename: consistent-imports.ts // ✅ 1 つのスタイルで統一している import {
    import Result
    Result
    } from '@praha/byethrow';
    const
    const validateId: (id: string) => Result.Result<string, never>
    validateId
    = (
    id: string
    id
    : string) => {
    return
    import Result
    Result
    .
    function succeed<string>(value: string): Result.Result<string, 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
    (
    id: string
    id
    );
    }; const
    const processData: Result.Result<string, never>
    processData
    =
    import Result
    Result
    .
    function pipe<Result.Result<"data", never>, Result.Result<string, never>>(a: Result.Result<"data", never>, ab: (a: Result.Result<"data", never>) => Result.Result<string, never>): Result.Result<string, never> (+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<"data">(value: "data"): Result.Result<"data", 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
    ('data'),
    import Result
    Result
    .
    function andThen<Result.Result<"data", never>, Result.Result<string, never>>(fn: (a: "data") => Result.Result<string, never>): (result: Result.Result<"data", never>) => Result.Result<string, never> (+1 overload)

    Chains the next computation using the success value of a Result or ResultAsync . If the original result is a Failure , it is returned unchanged. Otherwise, the provided function is called, and its result is returned as-is.

    @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(3),
    Result.andThen((x) => Result.succeed(x * 2)),
    );
    // { type: 'Success', value: 6 }
    @example

    Failure Case (input is a Failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.fail('error'),
    Result.andThen((x) => Result.succeed(x * 2)),
    );
    // result: { type: 'Failure', error: 'error' }
    @example

    Failure Case (function returns a Failure)

    import { Result } from '@praha/byethrow';
    
    const result = Result.pipe(
    Result.succeed(3),
    Result.andThen((x) => Result.fail('error: ' + x)),
    );
    // result: { type: 'Failure', error: 'error: 3' }
    @seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators
    andThen
    (
    const validateId: (id: string) => Result.Result<string, never>
    validateId
    ),
    );

    Lint ルールの consistent-namespace を使うと、選んだスタイルを強制し、違反を自動で修正できます。