/** * Represents a value that might be absent (null, undefined, or void). * 値が存在しない可能性を示します(null, undefined, または void)。 */ type None = null | undefined | void; /** * A `Maybe` type that encapsulates an optional value and provides methods to handle presence and absence. * オプションの値を包み込み、その存在と欠如を処理するためのメソッドを提供する `Maybe` 型。 */ export type Maybe = Just | Nothing; /** * Adapter type for Do's `$` parameter. * `$` は `yield* $(Maybe.pack(...))` のためのアダプタ関数です。 */ export type $Maybe = (fa: Maybe) => Generator; /** * Represents a `Just` value, encapsulating a present value. * 値が存在していることを表す `Just` 型。 */ export type Just = { readonly isMaybe: true; readonly isJust: true; readonly isNothing: false; /** * Applies a function to the value inside the `Just` and returns a new `Maybe`. * `Just` 内の値に関数を適用し、新しい `Maybe` を返します。 * @param fn - A function to apply to the `Just` value. / `Just` の値に適用する関数。 */ readonly map: (fn: (value: T) => U) => Maybe; /** * Applies a function to the value inside the `Just` and returns a new `Maybe`. * Alias for `map`. * `Just` 内の値に関数を適用し、新しい `Maybe` を返します。 * `map` のエイリアス。 * @param fn - A function to apply to the `Just` value. / `Just` の値に適用する関数。 */ readonly "<$>": (fn: (value: T) => U) => Maybe; /** * Applies a boxed function to the value inside the `Just` and returns a new `Maybe`. * `Just` に包まれた関数を別の `Maybe` に適用し、新しい `Maybe` を返します。 * @param boxValue - A `Maybe` containing a value to apply the function to. * / 関数を適用する値を含む `Maybe`。 */ readonly apply: (this: Maybe<(a: A) => B>, boxValue: Maybe) => Maybe; /** * Applies a boxed function to the value inside the `Just` and returns a new `Maybe`. * Alias for `apply`. * `Just` に包まれた関数を別の `Maybe` に適用し、新しい `Maybe` を返します。 * `apply` のエイリアス。 * @param boxValue - A `Maybe` containing a value to apply the function to. * / 関数を適用する値を含む `Maybe`。 */ readonly "<*>": (this: Maybe<(a: A) => B>, boxValue: Maybe) => Maybe; /** * Applies a function that returns a `Maybe` to the value inside this `Just` and flattens the result. * `Just` 内の値に `Maybe` を返す関数を適用し、その結果を平坦化して返します。 * @param fn - A function that returns a `Maybe`. / `Maybe` を返す関数。 */ readonly flatMap: (fn: (value: T) => Maybe) => Maybe; /** * Applies a function that returns a `Maybe` to the value inside this `Just` and flattens the result. * Alias for `flatMap`. * `Just` 内の値に `Maybe` を返す関数を適用し、その結果を平坦化して返します。 * `flatMap` のエイリアス。 * @param fn - A function that returns a `Maybe`. / `Maybe` を返す関数。 */ readonly ">>=": (fn: (value: T) => Maybe) => Maybe; /** * Gets the value inside the `Just`. * `Just` 内の値を取得します。 */ readonly getValue: () => T; /** * Returns the current `Just` if present, or the given default value. * 現在の `Just` が存在すればそれを返し、存在しなければ指定されたデフォルト値を返します。 * @param defaultValue - The default `Maybe` to return if absent. / 存在しない場合に返すデフォルトの `Maybe`。 */ readonly orElse: (defaultValue: Maybe) => Maybe; /** * Returns the current `Just` if present, or the given default value. * Alias for `orElse`. * 現在の `Just` が存在すればそれを返し、存在しなければ指定されたデフォルト値を返します。 * `orElse` のエイリアス。 * @param defaultValue - The default `Maybe` to return if absent. / 存在しない場合に返すデフォルトの `Maybe`。 */ readonly "": (defaultValue: Maybe) => Maybe; /** * Returns the value inside the `Just`, or a provided default value if absent. * `Just` 内の値を返し、存在しなければ指定されたデフォルト値を返します。 * @param defaultValue - The default value to return if absent. / 存在しない場合に返すデフォルト値。 */ readonly getOrElse: (defaultValue: U) => T | U; /** * Returns the value inside the `Just`, or a provided default value if absent. * Alias for `getOrElse`. * `Just` 内の値を返し、存在しなければ指定されたデフォルト値を返します。 * `getOrElse` のエイリアス。 * @param defaultValue - The default value to return if absent. / 存在しない場合に返すデフォルト値。 */ readonly "<|>": (defaultValue: U) => T | U; /** * Matches the `Just` or `Nothing` case and applies the corresponding function. * `Just` または `Nothing` の場合に対応する関数を適用します。 * @param onJust - A function to apply if `Just`. / `Just` の場合に適用する関数。 * @param onNothing - A function to apply if `Nothing`. / `Nothing` の場合に適用する関数。 */ readonly match: (onJust: (value: T) => U, onNothing: () => U) => U; }; /** * Represents a `Nothing` value, encapsulating absence. * 値が存在しないことを表す `Nothing` 型。 */ export type Nothing = { readonly isMaybe: true; readonly isJust: false; readonly isNothing: true; /** * Returns itself since there is no value to map. * 値が存在しないため、自身をそのまま返します。 * @param _fn - Ignored function. / 無視される関数。 */ readonly map: (_fn: (value: never) => U) => Nothing; /** * Returns itself since there is no value. * Alias for `map`. * 値が存在しないため、自身をそのまま返します。 * `map` のエイリアス。 * @param _fn - Ignored function. / 無視される関数。 */ readonly "<$>": (_fn: (value: never) => U) => Nothing; /** * Returns itself since there is no value to apply. * 値が存在しないため、自身をそのまま返します。 * @param this - Ignored boxed function. / 無視される関数。 * @param boxValue - Ignored boxed value. / 無視される値。 */ readonly apply: (this: Maybe<(a: A) => B>, boxValue: Maybe) => Maybe; /** * Returns itself since there is no value to apply. * Alias for `apply`. * 値が存在しないため、自身をそのまま返します。 * `apply` のエイリアス。 * @param this - Ignored boxed function. / 無視される関数。 * @param boxValue - Ignored boxed value. / 無視される値。 */ readonly "<*>": (this: Maybe<(a: A) => B>, boxValue: Maybe) => Maybe; /** * Returns itself since there is no value to flatMap. * 値が存在しないため、自身をそのまま返します。 * @param _fn - Ignored function. / 無視される関数。 */ readonly flatMap: (_fn: (value: never) => Maybe) => Nothing; /** * Returns itself since there is no value to flatMap. * Alias for `flatMap`. * 値が存在しないため、自身をそのまま返します。 * `flatMap` のエイリアス。 * @param _fn - Ignored function. / 無視される関数。 */ readonly ">>=": (_fn: (value: never) => Maybe) => Nothing; /** * Always returns `null` for a `Nothing` type. * `Nothing` 型の場合は常に `null` を返します。 */ readonly getValue: () => null; /** * Returns the provided default value. * 指定されたデフォルト値を返します。 * @param defaultValue - The default value to return. / 返すデフォルト値。 */ readonly orElse: (defaultValue: Maybe) => Maybe; /** * Returns the provided default value. * Alias for `orElse`. * 指定されたデフォルト値を返します。 * `orElse` のエイリアス。 * @param defaultValue - The default value to return. / 返すデフォルト値。 */ readonly "": (defaultValue: Maybe) => Maybe; /** * Returns the provided default value since there is no value. * 値が存在しないため、指定されたデフォルト値を返します。 * @param defaultValue - The default value to return. / 返すデフォルト値。 */ readonly getOrElse: (defaultValue: U) => U; /** * Returns the provided default value since there is no value. * Alias for `getOrElse`. * 値が存在しないため、指定されたデフォルト値を返します。 * `getOrElse` のエイリアス。 * @param defaultValue - The default value to return. / 返すデフォルト値。 */ readonly "<|>": (defaultValue: U) => U; /** * Applies the `onNothing` function since there is no value. * 値が存在しないため、`onNothing` 関数を適用します。 * @param _onJust - Ignored function. / 無視される関数。 * @param onNothing - A function to handle the `Nothing` case. / `Nothing` を処理する関数。 */ readonly match: (_onJust: (value: never) => U, onNothing: () => U) => U; }; /** * Creates a new `Maybe` instance based on the given value. * 指定された値に基づいて新しい `Maybe` インスタンスを作成します。 * If the value is `null`, `undefined`, or `void`, it returns `Nothing`. * If the value is present, it returns a `Just`. * 値が `null`、`undefined`、または `void` の場合は `Nothing` を返し、 * 値が存在する場合は `Just` を返します。 * @param value - The value to encapsulate. / 包み込む値。 */ declare const maybe: (value: T | None) => Maybe; /** * Returns the singleton instance of `Nothing`. * `Nothing` のシングルトンインスタンスを返します。 */ declare const nothing: () => Nothing; /** * Creates a new `Just` instance containing the given value. * 指定された値を含む新しい `Just` インスタンスを作成します。 * @param value - The non-null value to encapsulate. / 包み込む非 null の値。 */ declare const just: (value: NonNullable) => Just; /** * 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 a `Maybe`. * 指定された値が `Maybe` かどうかを判定します。 * @param value - The value to check. / 判定する値。 */ declare const isMaybe: (value: unknown) => value is Maybe; /** * Checks if the given value is a `Just`. * 指定された値が `Just` かどうかを判定します。 * @param value - The value to check. / 判定する値。 */ declare const isJust: (value: Maybe) => value is Just; /** * Checks if the given value is `Nothing`. * 指定された値が `Nothing` かどうかを判定します。 * @param value - The value to check. / 判定する値。 */ declare const isNothing: (value: Maybe) => value is Nothing; declare function Do(generatorFunc: () => Generator, U | Maybe, T>): Maybe; declare function Do(g: ($: (fa: Maybe) => Generator) => Generator): Maybe; /** * A utility object containing constructors and helpers for `Maybe`. * `Maybe` のコンストラクタおよびヘルパーを含むユーティリティオブジェクト。 */ export declare const Maybe: { do: typeof Do; pack: typeof maybe; just: typeof just; nothing: typeof nothing; isNone: typeof isNone; isMaybe: typeof isMaybe; isNothing: typeof isNothing; isJust: typeof isJust; }; export {};