type None = null | undefined | void; /** * Represents a value that can be either `Left` or `Right`. * `Left` または `Right` のいずれかである値を表します。 */ export type Either = Left | Right; /** * Adapter type for Do's `$` parameter. * `$` は `yield* $(Either.right(...))` のためのアダプタ関数です。 */ export type $Either = (fa: Either) => Generator; /** * Represents a `Left` value, encapsulating an error or invalid result. * エラーや無効な結果を包み込む `Left` 型。 */ export type Left = { readonly isEither: true; readonly isLeft: true; readonly isRight: false; /** * Ignores the provided function and returns itself since there is no valid value. * 指定された関数を無視し、有効な値が存在しないため自身を返します。 * @param _fn - Ignored function. / 無視される関数。 */ readonly map: (_fn: (value: R) => U) => Left; /** * Ignores the provided function and returns itself since there is no valid value. * Alias for `map`. * 指定された関数を無視し、有効な値が存在しないため自身を返します。 * `map` のエイリアス。 * @param _fn - Ignored function. / 無視される関数。 */ readonly "<$>": (_fn: (value: R) => U) => Left; /** * Ignores the provided function and boxed value, returning itself since there is no valid value. * 指定された関数とボックス化された値を無視し、有効な値が存在しないため自身を返します。 * @param this - Ignored boxed function. / 無視されるボックス化された関数。 * @param boxValue - Ignored boxed value. / 無視されるボックス化された値。 */ readonly apply: (this: Either B>, boxValue: Either) => Either; /** * Ignores the provided function and boxed value, returning itself since there is no valid value. * Alias for `apply`. * 指定された関数とボックス化された値を無視し、有効な値が存在しないため自身を返します。 * `apply` のエイリアス。 * @param this - Ignored boxed function. / 無視されるボックス化された関数。 * @param boxValue - Ignored boxed value. / 無視されるボックス化された値。 */ readonly "<*>": (this: Either B>, boxValue: Either) => Either; /** * Ignores the provided function, returning itself since there is no valid value. * 指定された関数を無視し、有効な値が存在しないため自身を返します。 * @param _fn - Ignored function. / 無視される関数。 */ readonly flatMap: (_fn: (value: R) => Either) => Left; /** * Ignores the provided function, returning itself since there is no valid value. * Alias for `flatMap`. * 指定された関数を無視し、有効な値が存在しないため自身を返します。 * `flatMap` のエイリアス。 * @param _fn - Ignored function. / 無視される関数。 */ readonly ">>=": (_fn: (value: R) => Either) => Left; /** * Gets the value inside the `Left`. * `Left` 内の値を取得します。 */ readonly getValue: () => L; /** * Returns the provided default value since this represents an invalid result. * 無効な結果を表しているため、指定されたデフォルト値を返します。 * @param defaultValue - The default value to return. / 返すデフォルト値。 */ readonly orElse: (defaultValue: Either) => Either; /** * Returns the provided default value since this represents an invalid result. * Alias for `orElse`. * 無効な結果を表しているため、指定されたデフォルト値を返します。 * `orElse` のエイリアス。 * @param defaultValue - The default value to return. / 返すデフォルト値。 */ readonly "": (defaultValue: Either) => Either; /** * Returns the provided default value since this represents an invalid result. * 無効な結果を表しているため、指定されたデフォルト値を返します。 * @param defaultValue - The default value to return. / 返すデフォルト値。 */ readonly getOrElse: (defaultValue: R) => R; /** * Returns the provided default value since this represents an invalid result. * Alias for `getOrElse`. * 無効な結果を表しているため、指定されたデフォルト値を返します。 * `getOrElse` のエイリアス。 * @param defaultValue - The default value to return. / 返すデフォルト値。 */ readonly "<|>": (defaultValue: R) => R; /** * Matches the `Left` case and applies the corresponding function. * `Left` の場合に対応する関数を適用します。 * @param onLeft - A function to apply if `Left`. / `Left` の場合に適用する関数。 * @param _onRight - Ignored function. / 無視される関数。 */ readonly match: (onLeft: (value: L) => U, _onRight: (value: R) => U) => U; }; /** * Represents a `Right` value, encapsulating a valid result. * 有効な結果を包み込む `Right` 型。 */ export type Right = { readonly isEither: true; readonly isLeft: false; readonly isRight: true; /** * Applies a function to the value inside the `Right` and returns a new `Either`. * `Right` 内の値に関数を適用し、新しい `Either` を返します。 * @param fn - A function to apply to the `Right` value. / `Right` の値に適用する関数。 */ readonly map: (fn: (value: R) => U) => Either; /** * Applies a function to the value inside the `Right` and returns a new `Either`. * Alias for `map`. * `Right` 内の値に関数を適用し、新しい `Either` を返します。 * `map` のエイリアス。 * @param fn - A function to apply to the `Right` value. / `Right` の値に適用する関数。 */ readonly "<$>": (fn: (value: R) => U) => Either; /** * Applies a boxed function to the value inside the `Right` and returns a new `Either`. * `Right` に包まれた関数を別の `Either` に適用し、新しい `Either` を返します。 * @param boxValue - A boxed value to apply the function to. / 関数を適用する値を含むボックス。 */ readonly apply: (this: Either B>, boxValue: Either) => Either; /** * Applies a boxed function to the value inside the `Right` and returns a new `Either`. * Alias for `apply`. * `Right` に包まれた関数を別の `Either` に適用し、新しい `Either` を返します。 * `apply` のエイリアス。 * @param boxValue - A boxed value to apply the function to. / 関数を適用する値を含むボックス。 */ readonly "<*>": (this: Either B>, boxValue: Either) => Either; /** * Applies a function that returns an `Either` to the value inside this `Right` and flattens the result. * `Right` 内の値に `Either` を返す関数を適用し、その結果を平坦化して返します。 * @param fn - A function that returns an `Either`. / `Either` を返す関数。 */ readonly flatMap: (fn: (value: R) => Either) => Either; /** * Applies a function that returns an `Either` to the value inside this `Right` and flattens the result. * Alias for `flatMap`. * `Right` 内の値に `Either` を返す関数を適用し、その結果を平坦化して返します。 * `flatMap` のエイリアス。 * @param fn - A function that returns an `Either`. / `Either` を返す関数。 */ readonly ">>=": (fn: (value: R) => Either) => Either; /** * Gets the value inside the `Right`. * `Right` 内の値を取得します。 */ readonly getValue: () => R; /** * Returns the current `Right` since it represents a valid result. * 有効な結果を表しているため、現在の `Right` を返します。 * @param defaultValue - Ignored value. / 無視される値。 */ readonly orElse: (defaultValue: Either) => Either; /** * Returns the current `Right` since it represents a valid result. * Alias for `orElse`. * 有効な結果を表しているため、現在の `Right` を返します。 * `orElse` のエイリアス。 * @param defaultValue - Ignored value. / 無視される値。 */ readonly "": (defaultValue: Either) => Either; /** * Returns the value inside the `Right`, ignoring the provided default value. * `Right` 内の値を返し、指定されたデフォルト値は無視されます。 * @param defaultValue - Ignored value. / 無視される値。 */ readonly getOrElse: (defaultValue: R) => R; /** * Returns the value inside the `Right`, ignoring the provided default value. * Alias for `getOrElse`. * `Right` 内の値を返し、指定されたデフォルト値は無視されます。 * `getOrElse` のエイリアス。 * @param defaultValue - Ignored value. / 無視される値。 */ readonly "<|>": (defaultValue: R) => R; /** * Matches the `Right` case and applies the corresponding function. * `Right` の場合に対応する関数を適用します。 * @param _onLeft - Ignored function. / 無視される関数。 * @param onRight - A function to apply if `Right`. / `Right` の場合に適用する関数。 */ readonly match: (_onLeft: (value: L) => U, onRight: (value: R) => U) => U; }; /** * Constructs a `Left` instance containing the given value. * 指定された値を含む `Left` インスタンスを作成します。 * @param value - The error or invalid state to encapsulate. / 包み込むエラーまたは無効な状態。 */ declare const left: (value: L) => Left; /** * Constructs a `Right` instance containing the given value. * 指定された値を含む `Right` インスタンスを作成します。 * @param value - The valid result to encapsulate. / 包み込む有効な結果。 */ declare const right: (value: R) => Right; /** * A convenience alias for the `right` constructor. * `right` コンストラクタの簡易エイリアス。 */ declare const either: (value: R) => Right; /** * Executes a computation and captures any thrown errors, returning an `Either`. * 計算を実行し、例外が発生した場合は `Left` を返す `Either` を作成します。 * * @param fn - A function that performs the computation. / 計算を実行する関数。 * @param onError - A function that converts an error into a `Left` value. / エラーを `Left` の値に変換する関数。 * @returns `Right` if the computation succeeds, otherwise `Left`. / 計算が成功すれば `Right`、失敗すれば `Left`。 */ declare const tryCatch: (fn: () => R, onError: (error: any) => L) => Either; /** * Checks if the given value is `None` (null, undefined, or void). * 指定された値が `None`(null、undefined、または void)かどうかを判定します。 * @param value - The value to check. / 判定する値。 */ declare const isNone: (value: unknown) => value is None; /** * Checks if the given value is an `Either`. * 指定された値が `Either` かどうかを判定します。 * @param value - The value to check. / 判定する値。 */ declare const isEither: (value: unknown) => value is Either; /** * Checks if the given `Either` is a `Left`. * 指定された `Either` が `Left` かどうかを判定します。 * @param value - The `Either` to check. / 判定する `Either`。 */ declare const isLeft: (value: Either) => value is Left; /** * Checks if the given `Either` is a `Right`. * 指定された `Either` が `Right` かどうかを判定します。 * @param value - The `Either` to check. / 判定する `Either`。 */ declare const isRight: (value: Either) => value is Right; declare function Do(generatorFunc: () => Generator, U | Either, R>): Either; declare function Do(g: ($: (fa: Either) => Generator) => Generator): Either; /** * A utility object containing constructors and helpers for `Either`. * `Either` のコンストラクタおよびヘルパーを含むユーティリティオブジェクト。 */ export declare const Either: { do: typeof Do; pack: typeof either; right: typeof right; left: typeof left; tryCatch: typeof tryCatch; isNone: typeof isNone; isEither: typeof isEither; isLeft: typeof isLeft; isRight: typeof isRight; }; export {};