happy-rusty 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.mjs","sources":["../src/enum/prelude.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/**\n * @fileoverview\n * A Rust-inspired [Option](https://doc.rust-lang.org/core/option/index.html) enum type, used as an alternative to the use of null and undefined.\n *\n * And [Result](https://doc.rust-lang.org/core/result/index.html) enum type, used for better error handling.\n *\n */\n\n/**\n * Symbol for Option kind: `Some` or `None`.\n */\nconst optionKindSymbol = Symbol('Option kind');\n\n/**\n * Symbol for Result kind: `Ok` or `Err`.\n */\nconst resultKindSymbol = Symbol('Result kind');\n\n/**\n * Type `Option` represents an optional value: every `Option` is either `Some` and contains a value, or `None`, and does not.\n * This interface includes methods that act on the `Option` type, similar to Rust's `Option` enum.\n *\n * As Rust Code:\n```rust\npub enum Option<T> {\n None,\n Some(T),\n}\n```\n * @typeParam T - The type of the value contained in the `Some` variant.\n */\nexport interface Option<T> {\n // #region Internal properties\n\n /**\n * Identify `Some` or `None`.\n *\n * @private\n */\n readonly [optionKindSymbol]: 'Some' | 'None';\n\n // #endregion\n\n // #region Querying the variant\n\n /**\n * The `isSome` and `isNone` methods return `true` if the `Option` is `Some` or `None`, respectively.\n */\n\n /**\n * Returns `true` if the Option is a `Some` value.\n */\n isSome(): boolean;\n\n /**\n * Returns `true` if the Option is a `None` value.\n */\n isNone(): boolean;\n\n /**\n * Returns `true` if the Option is a `Some` value and the predicate returns `true` for the contained value.\n * @param predicate - A function that takes the contained value and returns a boolean.\n */\n isSomeAnd(predicate: (value: T) => boolean): boolean;\n\n // #endregion\n\n // #region Extracting the contained value\n\n /**\n * These methods extract the contained value in an `Option<T>` when it is the `Some` variant:\n */\n\n /**\n * Returns the contained `Some` value, with a provided error message if the value is a `None`.\n * @param msg - The error message to provide if the value is a `None`.\n * @throws {TypeError} Throws an error with the provided message if the Option is a `None`.\n */\n expect(msg: string): T;\n\n /**\n * Returns the contained `Some` value.\n * @throws {TypeError} Throws an error if the value is a `None`.\n */\n unwrap(): T;\n\n /**\n * Returns the contained `Some` value or a provided default.\n * @param defaultValue - The value to return if the Option is a `None`.\n */\n unwrapOr(defaultValue: T): T;\n\n /**\n * Returns the contained `Some` value or computes it from a closure.\n * @param fn - A function that returns the default value.\n */\n unwrapOrElse(fn: () => T): T;\n\n // #endregion\n\n // #region Transforming contained values\n\n /**\n * These methods transform `Option` to `Result`:\n */\n\n /**\n * Transforms the `Option<T>` into a `Result<T, E>`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(err)`.\n * @typeParam E - The type of the error value in the `Err` variant of the resulting `Result`.\n * @param error - The error value to use if the Option is a `None`.\n */\n okOr<E>(error: E): Result<T, E>;\n\n /**\n * Transforms the `Option<T>` into a `Result<T, E>`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(err())`.\n * @typeParam E - The type of the error value in the `Err` variant of the resulting `Result`.\n * @param err - A function that returns the error value.\n */\n okOrElse<E>(err: () => E): Result<T, E>;\n\n /**\n * Transposes an `Option` of a `Result` into a `Result` of an `Option`.\n * @typeParam T - The type of the success value in the `Ok` variant of the `Result`.\n * @typeParam E - The type of the error value in the `Err` variant of the `Result`.\n * @returns `Ok` containing `Some` if the Option is a `Some` containing `Ok`,\n * `Err` containing the error if the Option is a `Some` containing `Err`,\n * `Ok` containing `None` if the Option is `None`.\n */\n transpose<T, E>(this: Option<Result<T, E>>): Result<Option<T>, E>;\n\n /**\n * These methods transform the `Some` variant:\n */\n\n /**\n * Returns `None` if the Option is `None`, otherwise calls predicate with the wrapped value and returns:\n * - `Some(t)` if predicate returns `true` (where `t` is the wrapped value), and\n * - `None` if predicate returns `false`.\n * @param predicate - A function that takes the contained value and returns a boolean.\n */\n filter(predicate: (value: T) => boolean): Option<T>;\n\n /**\n * Converts from `Option<Option<T>>` to `Option<T>`.\n * @returns `None` if the Option is `None`, otherwise returns the contained `Option`.\n */\n flatten<T>(this: Option<Option<T>>): Option<T>;\n\n /**\n * Maps an `Option<T>` to `Option<U>` by applying a function to a contained value.\n * @typeParam U - The type of the value returned by the map function.\n * @param fn - A function that takes the contained value and returns a new value.\n */\n map<U>(fn: (value: T) => U): Option<U>;\n\n /**\n * Maps an `Option<T>` to `U` by applying a function to the contained value (if any), or returns the provided default (if not).\n * @typeParam U - The type of the value returned by the map function or the default value.\n * @param defaultValue - The value to return if the Option is `None`.\n * @param fn - A function that takes the contained value and returns a new value.\n */\n mapOr<U>(defaultValue: U, fn: (value: T) => U): U;\n\n /**\n * Maps an `Option<T>` to `U` by applying a function to a contained value (if any), or computes a default (if not).\n * @typeParam U - The type of the value returned by the map function or the default function.\n * @param defaultFn - A function that returns the default value.\n * @param fn - A function that takes the contained value and returns a new value.\n */\n mapOrElse<U>(defaultFn: () => U, fn: (value: T) => U): U;\n\n /**\n * These methods combine the `Some` variants of two `Option` values:\n */\n\n /**\n * Combines `this` with another `Option` by zipping their contained values.\n * If `this` is `Some(s)` and `other` is `Some(o)`, returns `Some([s, o])`.\n * If either `this` or `other` is `None`, returns `None`.\n * @typeParam U - The type of the value in the other `Option`.\n * @param other - The other `Option` to zip with.\n * @returns An `Option` containing a tuple of the values if both are `Some`, otherwise `None`.\n */\n zip<U>(other: Option<U>): Option<[T, U]>;\n\n /**\n * Zips `this` with another `Option` using a provided function to combine their contained values.\n * If `this` is `Some(s)` and `other` is `Some(o)`, returns `Some(fn(s, o))`.\n * If either `this` or `other` is `None`, returns `None`.\n * @typeParam U - The type of the value in the other `Option`.\n * @typeParam R - The return type of the combining function.\n * @param other - The other `Option` to zip with.\n * @param fn - The function to combine the values from both `Options`.\n * @returns An `Option` containing the result of `fn` if both `Options` are `Some`, otherwise `None`.\n */\n zipWith<U, R>(other: Option<U>, fn: (value: T, otherValue: U) => R): Option<R>;\n\n /**\n * Converts from `Option<[T, U]>` to `[Option<T>, Option<U>]`.\n * If `this` is `Some([a, b])`, returns `[Some(a), Some(b)]`.\n * If `this` is `None`, returns `[None, None]`.\n * @typeParam T - The type of the first value in the tuple.\n * @typeParam U - The type of the second value in the tuple.\n * @returns A tuple of `Options`, one for each element in the original `Option` of a tuple.\n */\n unzip<T, U>(this: Option<[T, U]>): [Option<T>, Option<U>];\n\n // #endregion\n\n // #region Boolean operators\n\n /**\n * These methods treat the `Option` as a boolean value, where `Some` acts like `true` and `None` acts like `false`.\n */\n\n /**\n * Returns `None` if the Option is `None`, otherwise returns `other`.\n * This is sometimes called \"and then\" because it is similar to a logical AND operation.\n * @typeParam U - The type of the value in the other `Option`.\n * @param other - The `Option` to return if `this` is `Some`.\n * @returns `None` if `this` is `None`, otherwise returns `other`.\n */\n and<U>(other: Option<U>): Option<U>;\n\n /**\n * Returns `None` if the Option is `None`, otherwise calls `fn` with the wrapped value and returns the result.\n * This function can be used for control flow based on `Option` values.\n * @typeParam U - The type of the value returned by the function.\n * @param fn - A function that takes the contained value and returns an `Option`.\n * @returns The result of `fn` if `this` is `Some`, otherwise `None`.\n */\n andThen<U>(fn: (value: T) => Option<U>): Option<U>;\n\n /**\n * Returns the Option if it contains a value, otherwise returns `other`.\n * This can be used for providing a fallback `Option`.\n * @param other - The fallback `Option` to use if `this` is `None`.\n * @returns `this` if it is `Some`, otherwise `other`.\n */\n or(other: Option<T>): Option<T>;\n\n /**\n * Returns the Option if it contains a value, otherwise calls `fn` and returns the result.\n * This method can be used for lazy fallbacks, as `fn` is only evaluated if `this` is `None`.\n * @param fn - A function that produces an `Option`.\n * @returns `this` if it is `Some`, otherwise the result of `fn`.\n */\n orElse(fn: () => Option<T>): Option<T>;\n\n /**\n * Returns `Some` if exactly one of `this`, `other` is `Some`, otherwise returns `None`.\n * This can be thought of as an exclusive or operation on `Option` values.\n * @param other - The other `Option` to compare with.\n * @returns `Some` if exactly one of `this` and `other` is `Some`, otherwise `None`.\n */\n xor(other: Option<T>): Option<T>;\n\n // #endregion\n\n /**\n * Calls the provided function with the contained value if `this` is `Some`.\n * This is primarily for side effects and does not transform the `Option`.\n * @param fn - A function to call with the contained value.\n * @returns `this`, unmodified, for chaining additional methods.\n */\n inspect(fn: (value: T) => void): this;\n\n // #region Equals comparison\n\n /**\n * Tests whether `this` and `other` are both `Some` containing equal values, or both are `None`.\n * This method can be used for comparing `Option` instances in a value-sensitive manner.\n * @param other - The other `Option` to compare with.\n * @returns `true` if `this` and `other` are both `Some` with equal values, or both are `None`, otherwise `false`.\n */\n eq(other: Option<T>): boolean;\n\n // #endregion\n}\n\n/**\n * Represents the absence of a value, as a specialized `Option` type.\n * The type parameter is set to `never` because `None` does not hold a value.\n */\nexport interface None extends Option<never> {\n /**\n * When using `None` alone, the following overrides can make type inference more accurate.\n */\n\n readonly [optionKindSymbol]: 'None';\n\n unwrapOr<T>(defaultValue: T): T;\n unwrapOrElse<T>(fn: () => T): T;\n\n transpose(): Result<None, never>;\n\n filter(predicate: (value: never) => boolean): None;\n flatten(): None;\n map<U>(fn: (value: never) => U): None;\n\n zip<U>(other: Option<U>): None;\n zipWith<U, R>(other: Option<U>, fn: (value: never, otherValue: U) => R): None;\n unzip(): [None, None];\n\n and<U>(other: Option<U>): None;\n andThen<U>(fn: (value: never) => Option<U>): None;\n or<T>(other: Option<T>): Option<T>;\n orElse<T>(fn: () => Option<T>): Option<T>;\n xor<T>(other: Option<T>): Option<T>;\n\n eq<T>(other: Option<T>): boolean;\n}\n\n/**\n * The `Result` type is used for returning and propagating errors.\n * It is an enum with the variants, `Ok(T)`, representing success and containing a value, and `Err(E)`, representing error and containing an error value.\n * This interface includes methods that act on the `Result` type, similar to Rust's `Result` enum.\n *\n * As Rust Code:\n```rust\npub enum Result<T, E> {\n Ok(T),\n Err(E),\n}\n```\n * @typeParam T - The type of the value contained in a successful `Result`.\n * @typeParam E - The type of the error contained in an unsuccessful `Result`.\n */\nexport interface Result<T, E> {\n // #region Internal properties\n\n /**\n * Identify `Ok` or `Err`.\n *\n * @private\n */\n readonly [resultKindSymbol]: 'Ok' | 'Err';\n\n // #endregion\n\n // #region Querying the variant\n\n /**\n * The `isOk` and `isErr` methods return `true` if the `Result` is `Ok` or `Err`, respectively.\n */\n\n /**\n * Returns `true` if the result is `Ok`.\n */\n isOk(): boolean;\n\n /**\n * Returns `true` if the result is `Err`.\n */\n isErr(): boolean;\n\n /**\n * Returns `true` if the result is `Ok` and the provided predicate returns `true` for the contained value.\n * @param predicate - A function that takes the `Ok` value and returns a boolean.\n */\n isOkAnd(predicate: (value: T) => boolean): boolean;\n\n /**\n * Returns `true` if the result is `Err` and the provided predicate returns `true` for the contained error.\n * @param predicate - A function that takes the `Err` value and returns a boolean.\n */\n isErrAnd(predicate: (error: E) => boolean): boolean;\n\n // #endregion\n\n // #region Extracting the contained value\n\n /**\n * These methods extract the contained value in a `Result<T, E>` when it is the `Ok` variant.\n */\n\n /**\n * Returns the contained `Ok` value, with a provided error message if the result is `Err`.\n * @param msg - The error message to provide if the result is an `Err`.\n * @throws {TypeError} Throws an error with the provided message if the result is an `Err`.\n */\n expect(msg: string): T;\n\n /**\n * Returns the contained `Ok` value.\n * @throws {TypeError} Throws an error if the result is an `Err`.\n */\n unwrap(): T;\n\n /**\n * Returns the contained `Ok` value or a provided default.\n * @param defaultValue - The value to return if the result is an `Err`.\n */\n unwrapOr(defaultValue: T): T;\n\n /**\n * Returns the contained `Ok` value or computes it from a closure if the result is `Err`.\n * @param fn - A function that takes the `Err` value and returns an `Ok` value.\n */\n unwrapOrElse(fn: (error: E) => T): T;\n\n /**\n * These methods extract the contained value in a `Result<T, E>` when it is the `Err` variant.\n */\n\n /**\n * Returns the contained `Err` value, with a provided error message if the result is `Ok`.\n * @param msg - The error message to provide if the result is an `Ok`.\n * @throws {TypeError} Throws an error with the provided message if the result is an `Ok`.\n */\n expectErr(msg: string): E;\n\n /**\n * Returns the contained `Err` value.\n * @throws {TypeError} Throws an error if the result is an `Ok`.\n */\n unwrapErr(): E;\n\n // #endregion\n\n // #region Transforming contained values\n\n /**\n * These methods transform `Result` to `Option`:\n */\n\n /**\n * Converts from `Result<T, E>` to `Option<T>`.\n * If the result is `Ok`, returns `Some(T)`.\n * If the result is `Err`, returns `None`.\n */\n ok(): Option<T>;\n\n /**\n * Converts from `Result<T, E>` to `Option<E>`.\n * If the result is `Err`, returns `Some(E)`.\n * If the result is `Ok`, returns `None`.\n */\n err(): Option<E>;\n\n /**\n * Transposes a `Result` of an `Option` into an `Option` of a `Result`.\n * @typeParam T - The type of the success value in the `Ok` variant of the `Option`.\n * @returns `Some` containing `Ok` if the result is `Ok` containing `Some`,\n * `Some` containing `Err` if the result is `Err`,\n * `None` if the result is `Ok` containing `None`.\n */\n transpose<T>(this: Result<Option<T>, E>): Option<Result<T, E>>;\n\n /**\n * This method transforms the contained value of the `Ok` variant:\n */\n\n /**\n * Maps a `Result<T, E>` to `Result<U, E>` by applying a function to a contained `Ok` value,\n * leaving an `Err` value untouched.\n * @typeParam U - The type of the value returned by the map function.\n * @param fn - A function that takes the `Ok` value and returns a new value.\n */\n map<U>(fn: (value: T) => U): Result<U, E>;\n\n /**\n * This method transforms the contained value of the `Err` variant:\n */\n\n /**\n * Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a contained `Err` value,\n * leaving an `Ok` value untouched.\n * @typeParam F - The type of the error returned by the map function.\n * @param fn - A function that takes the `Err` value and returns a new error value.\n */\n mapErr<F>(fn: (error: E) => F): Result<T, F>;\n\n /**\n * These methods transform a `Result<T, E>` into a value of a possibly different type `U`:\n */\n\n /**\n * Maps a `Result<T, E>` to `U` by applying a function to the contained `Ok` value (if `Ok`), or returns the provided default (if `Err`).\n * @typeParam U - The type of the value returned by the map function or the default value.\n * @param defaultValue - The value to return if the result is `Err`.\n * @param fn - A function that takes the `Ok` value and returns a new value.\n */\n mapOr<U>(defaultValue: U, fn: (value: T) => U): U;\n\n /**\n * Maps a `Result<T, E>` to `U` by applying a function to the contained `Ok` value (if `Ok`), or computes a default (if `Err`).\n * @typeParam U - The type of the value returned by the map function or the default function.\n * @param defaultFn - A function that returns the default value.\n * @param fn - A function that takes the `Ok` value and returns a new value.\n */\n mapOrElse<U>(defaultFn: (error: E) => U, fn: (value: T) => U): U;\n\n /**\n * Converts from `Result<Result<T, E>, E>` to `Result<T, E>`.\n * If the result is `Ok(Ok(T))`, returns `Ok(T)`.\n * If the result is `Ok(Err(E))` or `Err(E)`, returns `Err(E)`.\n */\n flatten<T>(this: Result<Result<T, E>, E>): Result<T, E>;\n\n // #endregion\n\n // #region Boolean operators\n\n /**\n * These methods treat the `Result` as a boolean value, where `Ok` acts like `true` and `Err` acts like `false`.\n */\n\n /**\n * Returns `this` if the result is `Err`, otherwise returns the passed `Result`.\n * @typeParam U - The type of the value in the other `Result`.\n * @param other - The `Result` to return if `this` is `Ok`.\n * @returns The passed `Result` if `this` is `Ok`, otherwise returns `this` (which is `Err`).\n */\n and<U>(other: Result<U, E>): Result<U, E>;\n\n /**\n * Returns `this` if it is `Ok`, otherwise returns the passed `Result`.\n * @typeParam F - The type of the error in the other `Result`.\n * @param other - The `Result` to return if `this` is `Err`.\n * @returns `this` if it is `Ok`, otherwise returns `other`.\n */\n or<F>(other: Result<T, F>): Result<T, F>;\n\n /**\n * Calls the provided function with the contained value if `this` is `Ok`, otherwise returns `this` as `Err`.\n * @typeParam U - The type of the value returned by the function.\n * @param fn - A function that takes the `Ok` value and returns a `Result`.\n * @returns The result of `fn` if `this` is `Ok`, otherwise `this` as `Err`.\n */\n andThen<U>(fn: (value: T) => Result<U, E>): Result<U, E>;\n\n /**\n * Calls the provided function with the contained error if `this` is `Err`, otherwise returns `this` as `Ok`.\n * @typeParam F - The type of the error returned by the function.\n * @param fn - A function that takes the `Err` value and returns a `Result`.\n * @returns The result of `fn` if `this` is `Err`, otherwise `this` as `Ok`.\n */\n orElse<F>(fn: (error: E) => Result<T, F>): Result<T, F>;\n\n // #endregion\n\n /**\n * Calls the provided function with the contained value if `this` is `Ok`, for side effects only.\n * Does not modify the `Result`.\n * @param fn - A function to call with the `Ok` value.\n * @returns `this`, unmodified.\n */\n inspect(fn: (value: T) => void): this;\n\n /**\n * Calls the provided function with the contained error if `this` is `Err`, for side effects only.\n * Does not modify the `Result`.\n * @param fn - A function to call with the `Err` value.\n * @returns `this`, unmodified.\n */\n inspectErr(fn: (error: E) => void): this;\n\n // #region Equals comparison\n\n /**\n * Tests whether `this` and `other` are both `Ok` containing equal values, or both are `Err` containing equal errors.\n * @param other - The other `Result` to compare with.\n * @returns `true` if `this` and `other` are both `Ok` with equal values, or both are `Err` with equal errors, otherwise `false`.\n */\n eq(other: Result<T, E>): boolean;\n\n // #endregion\n}\n\n/**\n * Export some commonly used types.\n */\n\n/**\n * Represents an asynchronous operation that yields an `Option<T>`.\n * This is a promise that resolves to either `Some(T)` if the value is present, or `None` if the value is absent.\n *\n * @typeParam T - The type of the value that may be contained within the `Option`.\n */\nexport type AsyncOption<T> = Promise<Option<T>>;\n\n/**\n * Represents an asynchronous operation that yields a `Result<T, E>`.\n * This is a promise that resolves to `Ok(T)` if the operation was successful, or `Err(E)` if there was an error.\n *\n * @typeParam T - The type of the value that is produced by a successful operation.\n * @typeParam E - The type of the error that may be produced by a failed operation.\n */\nexport type AsyncResult<T, E> = Promise<Result<T, E>>;\n\n/**\n * Represents a synchronous operation that yields a `Result<T, Error>`.\n * This is a result that is either `Ok(T)` if the operation was successful, or `Err(Error)` if there was an error.\n *\n * @typeParam T - The type of the value that is produced by a successful operation.\n */\nexport type IOResult<T> = Result<T, Error>;\n\n/**\n * Represents an asynchronous I/O operation that yields a `Result<T, Error>`.\n * This is a promise that resolves to `Ok(T)` if the I/O operation was successful, or `Err(Error)` if there was an error.\n *\n * @typeParam T - The type of the value that is produced by a successful I/O operation.\n */\nexport type AsyncIOResult<T> = Promise<IOResult<T>>;\n\n/**\n * Creates an `Option<T>` representing the presence of a value.\n * This function is typically used to construct an `Option` that contains a value, indicating that the operation yielding the value was successful.\n *\n * @typeParam T - The type of the value to be wrapped in a `Some`.\n * @param value - The value to wrap as a `Some` option.\n * @returns An `Option<T>` that contains the provided value, representing the `Some` case.\n *\n * @example\n * ```ts\n * const maybeValue = Some(1); // Option<number> with a value\n * if (maybeValue.isSome()) {\n * console.log(maybeValue.unwrap()); // Outputs: 1\n * }\n * ```\n */\nexport function Some<T>(value: T): Option<T> {\n const some: Option<T> = {\n [optionKindSymbol]: 'Some',\n\n isSome: (): true => true,\n isNone: (): false => false,\n isSomeAnd: (predicate: (value: T) => boolean): boolean => predicate(value),\n\n expect: (_msg: string): T => value,\n unwrap: (): T => value,\n unwrapOr: (_defaultValue: T): T => value,\n unwrapOrElse: (_fn: () => T): T => value,\n\n okOr: <E>(_error: E): Result<T, E> => Ok(value),\n okOrElse: <E>(_err: () => E): Result<T, E> => Ok(value),\n transpose: <T, E>(): Result<Option<T>, E> => {\n const r = value as unknown as Result<T, E>;\n assertResult(r);\n return r.isOk() ? Ok(Some(r.unwrap())) : Err(r.unwrapErr());\n },\n\n filter: (predicate: (value: T) => boolean): Option<T> => predicate(value) ? some : None,\n flatten: <T>(): Option<T> => {\n const o = value as unknown as Option<T>;\n assertOption(o);\n return o;\n },\n map: <U>(fn: (value: T) => U): Option<U> => Some(fn(value)),\n\n mapOr: <U>(_defaultValue: U, fn: (value: T) => U): U => fn(value),\n mapOrElse: <U>(_defaultFn: () => U, fn: (value: T) => U): U => fn(value),\n\n zip: <U>(other: Option<U>): Option<[T, U]> => {\n assertOption(other);\n return other.isSome() ? Some([value, other.unwrap()]) : None;\n },\n zipWith: <U, R>(other: Option<U>, fn: (value: T, otherValue: U) => R): Option<R> => {\n assertOption(other);\n return other.isSome() ? Some(fn(value, other.unwrap())) : None;\n },\n unzip: <T, U>(): [Option<T>, Option<U>] => {\n const tuple = value as unknown as [T, U];\n\n if (!Array.isArray(tuple) || tuple.length !== 2) {\n throw new TypeError('Unzip format is incorrect.');\n }\n\n const [a, b] = tuple;\n return [Some(a), Some(b)];\n },\n\n and: <U>(other: Option<U>): Option<U> => {\n assertOption(other);\n return other;\n },\n andThen: <U>(fn: (value: T) => Option<U>): Option<U> => fn(value),\n or: (_other: Option<T>): Option<T> => some,\n orElse: (_fn: () => Option<T>): Option<T> => some,\n xor: (other: Option<T>): Option<T> => {\n assertOption(other);\n return other.isSome() ? None : some;\n },\n\n inspect: (fn: (value: T) => void): Option<T> => {\n fn(value);\n return some;\n },\n\n eq: (other: Option<T>): boolean => {\n assertOption(other);\n return other.isSome() && other.unwrap() === value;\n },\n } as const;\n\n return some;\n}\n\n/**\n * A constant representing the `None` case of an `Option`, indicating the absence of a value.\n * This constant is frozen to ensure it is immutable and cannot be altered, preserving the integrity of `None` throughout the application.\n */\nexport const None = Object.freeze<None>({\n [optionKindSymbol]: 'None',\n\n isSome: (): false => false,\n isNone: (): true => true,\n isSomeAnd: (_predicate: (value: never) => boolean): false => false,\n\n expect: (msg: string): never => {\n throw new TypeError(msg);\n },\n unwrap: (): never => {\n throw new TypeError('Called `Option::unwrap()` on a `None` value');\n },\n unwrapOr: <T>(defaultValue: T): T => defaultValue,\n unwrapOrElse: <T>(fn: () => T): T => fn(),\n\n okOr: <E>(error: E): Result<never, E> => Err(error),\n okOrElse: <E>(err: () => E): Result<never, E> => Err(err()),\n transpose: (): Result<None, never> => Ok(None),\n\n filter: (_predicate: (value: never) => boolean): None => None,\n flatten: (): None => None,\n map: <U>(_fn: (value: never) => U): None => None,\n\n mapOr: <U>(defaultValue: U, _fn: (value: never) => U): U => defaultValue,\n mapOrElse: <U>(defaultFn: () => U, _fn: (value: never) => U): U => defaultFn(),\n\n zip: <U>(_other: Option<U>): None => None,\n zipWith: <U, R>(_other: Option<U>, _fn: (value: never, otherValue: U) => R): None => None,\n unzip: (): [None, None] => [None, None],\n\n and: <U>(_other: Option<U>): None => None,\n andThen: <U>(_fn: (value: never) => Option<U>): None => None,\n or: <T>(other: Option<T>): Option<T> => {\n assertOption(other);\n return other;\n },\n orElse: <T>(fn: () => Option<T>): Option<T> => fn(),\n xor: <T>(other: Option<T>): Option<T> => {\n assertOption(other);\n return other.isSome() ? other : None;\n },\n\n inspect: (_fn: (value: never) => void): None => None,\n\n eq: <T>(other: Option<T>): boolean => {\n assertOption(other);\n return other === None;\n },\n}) as None;\n\n/**\n * Creates a `Result<T, E>` representing a successful outcome containing a value.\n * This function is used to construct a `Result` that signifies the operation was successful by containing the value `T`.\n *\n * @typeParam T - The type of the value to be contained in the `Ok` result.\n * @typeParam E - The type of the error that the result could potentially contain (not used in this case).\n * @param value - The value to wrap as an `Ok` result.\n * @returns A `Result<T, E>` that contains the provided value, representing the `Ok` case.\n *\n * @example\n * ```ts\n * const goodResult = Ok<number, Error>(1); // Result<number, Error> with a value\n * if (goodResult.isOk()) {\n * console.log(goodResult.unwrap()); // Outputs: 1\n * }\n * ```\n */\nexport function Ok<T, E>(value: T): Result<T, E> {\n const ok: Result<T, E> = {\n [resultKindSymbol]: 'Ok',\n\n isOk: (): true => true,\n isErr: (): false => false,\n isOkAnd: (predicate: (value: T) => boolean): boolean => predicate(value),\n isErrAnd: (_predicate: (error: E) => boolean): false => false,\n\n expect: (_msg: string): T => value,\n unwrap: (): T => value,\n unwrapOr: (_defaultValue: T): T => value,\n unwrapOrElse: (_fn: (error: E) => T): T => value,\n\n expectErr: (msg: string): E => {\n throw new TypeError(`${ msg }: ${ value }`);\n },\n unwrapErr: (): E => {\n throw new TypeError('Called `Result::unwrapErr()` on an `Ok` value');\n },\n\n ok: (): Option<T> => Some(value),\n err: (): None => None,\n transpose: <T>(): Option<Result<T, E>> => {\n const o = value as Option<T>;\n assertOption(o);\n return o.isSome() ? Some(Ok(o.unwrap())) : None;\n },\n\n map: <U>(fn: (value: T) => U): Result<U, E> => Ok(fn(value)),\n mapErr: <F>(_fn: (error: E) => F): Result<T, F> => Ok(value),\n mapOr: <U>(_defaultValue: U, fn: (value: T) => U): U => fn(value),\n mapOrElse: <U>(_defaultFn: (error: E) => U, fn: (value: T) => U): U => fn(value),\n flatten: <T>(): Result<T, E> => {\n const r = value as Result<T, E>;\n assertResult(r);\n return r;\n },\n\n and: <U>(other: Result<U, E>): Result<U, E> => {\n assertResult(other);\n return other;\n },\n or: <F>(_other: Result<T, F>): Result<T, F> => ok as unknown as Result<T, F>,\n andThen: <U>(fn: (value: T) => Result<U, E>): Result<U, E> => fn(value),\n orElse: <F>(_fn: (error: E) => Result<T, F>): Result<T, F> => ok as unknown as Result<T, F>,\n\n inspect: (fn: (value: T) => void): Result<T, E> => {\n fn(value);\n return ok;\n },\n inspectErr: (_fn: (error: E) => void): Result<T, E> => ok,\n\n eq: (other: Result<T, E>): boolean => {\n assertResult(other);\n return other.isOk() && other.unwrap() === value;\n },\n } as const;\n\n return ok;\n}\n\n/**\n * Creates a `Result<T, E>` representing a failed outcome containing an error.\n * This function is used to construct a `Result` that signifies the operation failed by containing the error `E`.\n *\n * @typeParam T - The type of the value that the result could potentially contain (not used in this case).\n * @typeParam E - The type of the error to be wrapped in the `Err` result.\n * @param error - The error to wrap as an `Err` result.\n * @returns A `Result<T, E>` that contains the provided error, representing the `Err` case.\n *\n * @example\n * ```ts\n * const badResult = Err<number, Error>(new Error('Something went wrong'));\n * if (badResult.isErr()) {\n * console.error(badResult.unwrapErr()); // Outputs: Error: Something went wrong\n * }\n * ```\n */\nexport function Err<T, E>(error: E): Result<T, E> {\n const err: Result<T, E> = {\n [resultKindSymbol]: 'Err',\n\n isOk: (): false => false,\n isErr: (): true => true,\n isOkAnd: (_predicate: (value: T) => boolean): false => false,\n isErrAnd: (predicate: (error: E) => boolean): boolean => predicate(error),\n\n expect: (msg: string): T => {\n throw new TypeError(`${ msg }: ${ error }`);\n },\n unwrap: (): T => {\n throw new TypeError('Called `Result::unwrap()` on an `Err` value');\n },\n unwrapOr: (defaultValue: T): T => defaultValue,\n unwrapOrElse: (fn: (error: E) => T): T => fn(error),\n\n expectErr: (_msg: string): E => error,\n unwrapErr: (): E => error,\n\n ok: (): None => None,\n err: (): Option<E> => Some(error),\n transpose: <T>(): Option<Result<T, E>> => Some(err as unknown as Result<T, E>),\n\n map: <U>(_fn: (value: T) => U): Result<U, E> => err as unknown as Result<U, E>,\n mapErr: <F>(fn: (error: E) => F): Result<T, F> => Err(fn(error)),\n mapOr: <U>(defaultValue: U, _fn: (value: T) => U): U => defaultValue,\n mapOrElse: <U>(defaultFn: (error: E) => U, _fn: (value: T) => U): U => defaultFn(error),\n flatten: <T>(): Result<T, E> => err as unknown as Result<T, E>,\n\n and: <U>(_other: Result<U, E>): Result<U, E> => err as unknown as Result<U, E>,\n or: <F>(other: Result<T, F>): Result<T, F> => {\n assertResult(other);\n return other;\n },\n andThen: <U>(_fn: (value: T) => Result<U, E>): Result<U, E> => err as unknown as Result<U, E>,\n orElse: <F>(fn: (error: E) => Result<T, F>): Result<T, F> => fn(error),\n\n inspect: (_fn: (value: T) => void): Result<T, E> => err,\n inspectErr: (fn: (error: E) => void): Result<T, E> => {\n fn(error);\n return err;\n },\n\n eq: (other: Result<T, E>): boolean => {\n assertResult(other);\n return other.isErr() && other.unwrapErr() === error;\n },\n } as const;\n\n return err;\n}\n\n/**\n * Asserts that a given value is an `Option`.\n *\n * @typeParam T - The expected type of the value contained within the `Option`.\n * @param o - The value to be checked as an `Option`.\n * @throws {TypeError} If the value is not an `Option`.\n */\nfunction assertOption<T>(o: Option<T>): void {\n // `Some` and `None` must be an object.\n if (o == null || typeof o !== 'object' || !(optionKindSymbol in o)) {\n throw new TypeError(`This(${ o }) is not an Option`);\n }\n}\n\n/**\n * Asserts that a given value is a `Result`.\n *\n * @typeParam T - The expected type of the success value contained within the `Result`.\n * @typeParam E - The expected type of the error value contained within the `Result`.\n * @param r - The value to be checked as a `Result`.\n * @throws {TypeError} If the value is not a `Result`.\n */\nfunction assertResult<T, E>(r: Result<T, E>): void {\n // `Ok` and `Err` must be an object.\n if (r == null || typeof r !== 'object' || !(resultKindSymbol in r)) {\n throw new TypeError(`This(${ r }) is not a Result`);\n }\n}\n\n/**\n * Converts a Promise to a Result type, capturing the resolved value in an `Ok`, or the error in an `Err`.\n * This allows for promise-based asynchronous operations to be handled in a way that is more in line with the Result pattern.\n *\n * @typeParam T - The type of the value that the promise resolves to.\n * @typeParam E - The type of the error that the promise may reject with, defaults to `Error`.\n * @param p - The promise to convert into a `Result` type.\n * @returns A promise that resolves to a `Result<T, E>`. If the input promise `p` resolves, the resulting promise will resolve with `Ok<T>`. If the input promise `p` rejects, the resulting promise will resolve with `Err<E>`.\n *\n * @example\n * ```ts\n * async function example() {\n * const result = await promiseToResult(fetchData());\n * if (result.isOk()) {\n * console.log('Data:', result.unwrap());\n * } else {\n * console.error('Error:', result.unwrapErr());\n * }\n * }\n * ```\n */\nexport function promiseToResult<T, E = Error>(p: Promise<T>): Promise<Result<T, E>> {\n return p.then((x): Result<T, E> => {\n return Ok(x);\n }).catch((err: E): Result<T, E> => {\n return Err(err);\n });\n}"],"names":[],"mappings":"AAYA,MAAM,gBAAA,GAAmB,OAAO,aAAa,CAAA,CAAA;AAK7C,MAAM,gBAAA,GAAmB,OAAO,aAAa,CAAA,CAAA;AA+lBtC,SAAS,KAAQ,KAAqB,EAAA;AACzC,EAAA,MAAM,IAAkB,GAAA;AAAA,IACpB,CAAC,gBAAgB,GAAG,MAAA;AAAA,IAEpB,QAAQ,MAAY,IAAA;AAAA,IACpB,QAAQ,MAAa,KAAA;AAAA,IACrB,SAAW,EAAA,CAAC,SAA8C,KAAA,SAAA,CAAU,KAAK,CAAA;AAAA,IAEzE,MAAA,EAAQ,CAAC,IAAoB,KAAA,KAAA;AAAA,IAC7B,QAAQ,MAAS,KAAA;AAAA,IACjB,QAAA,EAAU,CAAC,aAAwB,KAAA,KAAA;AAAA,IACnC,YAAA,EAAc,CAAC,GAAoB,KAAA,KAAA;AAAA,IAEnC,IAAM,EAAA,CAAI,MAA4B,KAAA,EAAA,CAAG,KAAK,CAAA;AAAA,IAC9C,QAAU,EAAA,CAAI,IAAgC,KAAA,EAAA,CAAG,KAAK,CAAA;AAAA,IACtD,WAAW,MAAkC;AACzC,MAAA,MAAM,CA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AAA,MAAM,IAAI,SAAA,CAAU,CAAS,KAAA,EAAA,CAAE,CAAmB,iBAAA,CAAA,CAAA,CAAA;AAAA,GACtD;AACJ,CAAA;AAuBO,SAAS,gBAA8B,CAAsC,EAAA;AAChF,EAAO,OAAA,CAAA,CAAE,IAAK,CAAA,CAAC,CAAoB,KAAA;AAC/B,IAAA,OAAO,GAAG,CAAC,CAAA,CAAA;AAAA,GACd,CAAA,CAAE,KAAM,CAAA,CAAC,GAAyB,KAAA;AAC/B,IAAA,OAAO,IAAI,GAAG,CAAA,CAAA;AAAA,GACjB,CAAA,CAAA;AACL;;;;"}
1
+ {"version":3,"file":"main.mjs","sources":["../src/enum/prelude.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/**\n * @fileoverview\n * A Rust-inspired [Option](https://doc.rust-lang.org/core/option/index.html) enum type, used as an alternative to the use of null and undefined.\n *\n * And [Result](https://doc.rust-lang.org/core/result/index.html) enum type, used for better error handling.\n *\n */\n\n/**\n * Symbol for Option kind: `Some` or `None`.\n */\nconst optionKindSymbol = Symbol('Option kind');\n\n/**\n * Symbol for Result kind: `Ok` or `Err`.\n */\nconst resultKindSymbol = Symbol('Result kind');\n\n/**\n * Type `Option` represents an optional value: every `Option` is either `Some` and contains a value, or `None`, and does not.\n * This interface includes methods that act on the `Option` type, similar to Rust's `Option` enum.\n *\n * As Rust Code:\n```rust\npub enum Option<T> {\n None,\n Some(T),\n}\n```\n * @typeParam T - The type of the value contained in the `Some` variant.\n */\nexport interface Option<T> {\n // #region Internal properties\n\n /**\n * [object Option].\n */\n [Symbol.toStringTag]: 'Option',\n\n /**\n * Identify `Some` or `None`.\n *\n * @private\n */\n readonly [optionKindSymbol]: 'Some' | 'None';\n\n // #endregion\n\n // #region Querying the variant\n\n /**\n * The `isSome` and `isNone` methods return `true` if the `Option` is `Some` or `None`, respectively.\n */\n\n /**\n * Returns `true` if the Option is a `Some` value.\n */\n isSome(): boolean;\n\n /**\n * Returns `true` if the Option is a `None` value.\n */\n isNone(): boolean;\n\n /**\n * Returns `true` if the Option is a `Some` value and the predicate returns `true` for the contained value.\n * @param predicate - A function that takes the contained value and returns a boolean.\n */\n isSomeAnd(predicate: (value: T) => boolean): boolean;\n\n // #endregion\n\n // #region Extracting the contained value\n\n /**\n * These methods extract the contained value in an `Option<T>` when it is the `Some` variant:\n */\n\n /**\n * Returns the contained `Some` value, with a provided error message if the value is a `None`.\n * @param msg - The error message to provide if the value is a `None`.\n * @throws {TypeError} Throws an error with the provided message if the Option is a `None`.\n */\n expect(msg: string): T;\n\n /**\n * Returns the contained `Some` value.\n * @throws {TypeError} Throws an error if the value is a `None`.\n */\n unwrap(): T;\n\n /**\n * Returns the contained `Some` value or a provided default.\n * @param defaultValue - The value to return if the Option is a `None`.\n */\n unwrapOr(defaultValue: T): T;\n\n /**\n * Returns the contained `Some` value or computes it from a closure.\n * @param fn - A function that returns the default value.\n */\n unwrapOrElse(fn: () => T): T;\n\n // #endregion\n\n // #region Transforming contained values\n\n /**\n * These methods transform `Option` to `Result`:\n */\n\n /**\n * Transforms the `Option<T>` into a `Result<T, E>`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(err)`.\n * @typeParam E - The type of the error value in the `Err` variant of the resulting `Result`.\n * @param error - The error value to use if the Option is a `None`.\n */\n okOr<E>(error: E): Result<T, E>;\n\n /**\n * Transforms the `Option<T>` into a `Result<T, E>`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(err())`.\n * @typeParam E - The type of the error value in the `Err` variant of the resulting `Result`.\n * @param err - A function that returns the error value.\n */\n okOrElse<E>(err: () => E): Result<T, E>;\n\n /**\n * Transposes an `Option` of a `Result` into a `Result` of an `Option`.\n * @typeParam T - The type of the success value in the `Ok` variant of the `Result`.\n * @typeParam E - The type of the error value in the `Err` variant of the `Result`.\n * @returns `Ok` containing `Some` if the Option is a `Some` containing `Ok`,\n * `Err` containing the error if the Option is a `Some` containing `Err`,\n * `Ok` containing `None` if the Option is `None`.\n */\n transpose<T, E>(this: Option<Result<T, E>>): Result<Option<T>, E>;\n\n /**\n * These methods transform the `Some` variant:\n */\n\n /**\n * Returns `None` if the Option is `None`, otherwise calls predicate with the wrapped value and returns:\n * - `Some(t)` if predicate returns `true` (where `t` is the wrapped value), and\n * - `None` if predicate returns `false`.\n * @param predicate - A function that takes the contained value and returns a boolean.\n */\n filter(predicate: (value: T) => boolean): Option<T>;\n\n /**\n * Converts from `Option<Option<T>>` to `Option<T>`.\n * @returns `None` if the Option is `None`, otherwise returns the contained `Option`.\n */\n flatten<T>(this: Option<Option<T>>): Option<T>;\n\n /**\n * Maps an `Option<T>` to `Option<U>` by applying a function to a contained value.\n * @typeParam U - The type of the value returned by the map function.\n * @param fn - A function that takes the contained value and returns a new value.\n */\n map<U>(fn: (value: T) => U): Option<U>;\n\n /**\n * Maps an `Option<T>` to `U` by applying a function to the contained value (if any), or returns the provided default (if not).\n * @typeParam U - The type of the value returned by the map function or the default value.\n * @param defaultValue - The value to return if the Option is `None`.\n * @param fn - A function that takes the contained value and returns a new value.\n */\n mapOr<U>(defaultValue: U, fn: (value: T) => U): U;\n\n /**\n * Maps an `Option<T>` to `U` by applying a function to a contained value (if any), or computes a default (if not).\n * @typeParam U - The type of the value returned by the map function or the default function.\n * @param defaultFn - A function that returns the default value.\n * @param fn - A function that takes the contained value and returns a new value.\n */\n mapOrElse<U>(defaultFn: () => U, fn: (value: T) => U): U;\n\n /**\n * These methods combine the `Some` variants of two `Option` values:\n */\n\n /**\n * Combines `this` with another `Option` by zipping their contained values.\n * If `this` is `Some(s)` and `other` is `Some(o)`, returns `Some([s, o])`.\n * If either `this` or `other` is `None`, returns `None`.\n * @typeParam U - The type of the value in the other `Option`.\n * @param other - The other `Option` to zip with.\n * @returns An `Option` containing a tuple of the values if both are `Some`, otherwise `None`.\n */\n zip<U>(other: Option<U>): Option<[T, U]>;\n\n /**\n * Zips `this` with another `Option` using a provided function to combine their contained values.\n * If `this` is `Some(s)` and `other` is `Some(o)`, returns `Some(fn(s, o))`.\n * If either `this` or `other` is `None`, returns `None`.\n * @typeParam U - The type of the value in the other `Option`.\n * @typeParam R - The return type of the combining function.\n * @param other - The other `Option` to zip with.\n * @param fn - The function to combine the values from both `Options`.\n * @returns An `Option` containing the result of `fn` if both `Options` are `Some`, otherwise `None`.\n */\n zipWith<U, R>(other: Option<U>, fn: (value: T, otherValue: U) => R): Option<R>;\n\n /**\n * Converts from `Option<[T, U]>` to `[Option<T>, Option<U>]`.\n * If `this` is `Some([a, b])`, returns `[Some(a), Some(b)]`.\n * If `this` is `None`, returns `[None, None]`.\n * @typeParam T - The type of the first value in the tuple.\n * @typeParam U - The type of the second value in the tuple.\n * @returns A tuple of `Options`, one for each element in the original `Option` of a tuple.\n */\n unzip<T, U>(this: Option<[T, U]>): [Option<T>, Option<U>];\n\n // #endregion\n\n // #region Boolean operators\n\n /**\n * These methods treat the `Option` as a boolean value, where `Some` acts like `true` and `None` acts like `false`.\n */\n\n /**\n * Returns `None` if the Option is `None`, otherwise returns `other`.\n * This is sometimes called \"and then\" because it is similar to a logical AND operation.\n * @typeParam U - The type of the value in the other `Option`.\n * @param other - The `Option` to return if `this` is `Some`.\n * @returns `None` if `this` is `None`, otherwise returns `other`.\n */\n and<U>(other: Option<U>): Option<U>;\n\n /**\n * Returns `None` if the Option is `None`, otherwise calls `fn` with the wrapped value and returns the result.\n * This function can be used for control flow based on `Option` values.\n * @typeParam U - The type of the value returned by the function.\n * @param fn - A function that takes the contained value and returns an `Option`.\n * @returns The result of `fn` if `this` is `Some`, otherwise `None`.\n */\n andThen<U>(fn: (value: T) => Option<U>): Option<U>;\n\n /**\n * Returns the Option if it contains a value, otherwise returns `other`.\n * This can be used for providing a fallback `Option`.\n * @param other - The fallback `Option` to use if `this` is `None`.\n * @returns `this` if it is `Some`, otherwise `other`.\n */\n or(other: Option<T>): Option<T>;\n\n /**\n * Returns the Option if it contains a value, otherwise calls `fn` and returns the result.\n * This method can be used for lazy fallbacks, as `fn` is only evaluated if `this` is `None`.\n * @param fn - A function that produces an `Option`.\n * @returns `this` if it is `Some`, otherwise the result of `fn`.\n */\n orElse(fn: () => Option<T>): Option<T>;\n\n /**\n * Returns `Some` if exactly one of `this`, `other` is `Some`, otherwise returns `None`.\n * This can be thought of as an exclusive or operation on `Option` values.\n * @param other - The other `Option` to compare with.\n * @returns `Some` if exactly one of `this` and `other` is `Some`, otherwise `None`.\n */\n xor(other: Option<T>): Option<T>;\n\n // #endregion\n\n /**\n * Calls the provided function with the contained value if `this` is `Some`.\n * This is primarily for side effects and does not transform the `Option`.\n * @param fn - A function to call with the contained value.\n * @returns `this`, unmodified, for chaining additional methods.\n */\n inspect(fn: (value: T) => void): this;\n\n // #region Equals comparison\n\n /**\n * Tests whether `this` and `other` are both `Some` containing equal values, or both are `None`.\n * This method can be used for comparing `Option` instances in a value-sensitive manner.\n * @param other - The other `Option` to compare with.\n * @returns `true` if `this` and `other` are both `Some` with equal values, or both are `None`, otherwise `false`.\n */\n eq(other: Option<T>): boolean;\n\n // #endregion\n\n /**\n * Custom `toString` implementation that uses the `Option`'s contained value.\n */\n toString(): string;\n}\n\n/**\n * Represents the absence of a value, as a specialized `Option` type.\n * The type parameter is set to `never` because `None` does not hold a value.\n */\nexport interface None extends Option<never> {\n /**\n * When using `None` alone, the following overrides can make type inference more accurate.\n */\n\n readonly [optionKindSymbol]: 'None';\n\n unwrapOr<T>(defaultValue: T): T;\n unwrapOrElse<T>(fn: () => T): T;\n\n transpose(): Result<None, never>;\n\n filter(predicate: (value: never) => boolean): None;\n flatten(): None;\n map<U>(fn: (value: never) => U): None;\n\n zip<U>(other: Option<U>): None;\n zipWith<U, R>(other: Option<U>, fn: (value: never, otherValue: U) => R): None;\n unzip(): [None, None];\n\n and<U>(other: Option<U>): None;\n andThen<U>(fn: (value: never) => Option<U>): None;\n or<T>(other: Option<T>): Option<T>;\n orElse<T>(fn: () => Option<T>): Option<T>;\n xor<T>(other: Option<T>): Option<T>;\n\n eq<T>(other: Option<T>): boolean;\n}\n\n/**\n * The `Result` type is used for returning and propagating errors.\n * It is an enum with the variants, `Ok(T)`, representing success and containing a value, and `Err(E)`, representing error and containing an error value.\n * This interface includes methods that act on the `Result` type, similar to Rust's `Result` enum.\n *\n * As Rust Code:\n```rust\npub enum Result<T, E> {\n Ok(T),\n Err(E),\n}\n```\n * @typeParam T - The type of the value contained in a successful `Result`.\n * @typeParam E - The type of the error contained in an unsuccessful `Result`.\n */\nexport interface Result<T, E> {\n // #region Internal properties\n\n /**\n * [object Result].\n */\n [Symbol.toStringTag]: 'Result',\n\n /**\n * Identify `Ok` or `Err`.\n *\n * @private\n */\n readonly [resultKindSymbol]: 'Ok' | 'Err';\n\n // #endregion\n\n // #region Querying the variant\n\n /**\n * The `isOk` and `isErr` methods return `true` if the `Result` is `Ok` or `Err`, respectively.\n */\n\n /**\n * Returns `true` if the result is `Ok`.\n */\n isOk(): boolean;\n\n /**\n * Returns `true` if the result is `Err`.\n */\n isErr(): boolean;\n\n /**\n * Returns `true` if the result is `Ok` and the provided predicate returns `true` for the contained value.\n * @param predicate - A function that takes the `Ok` value and returns a boolean.\n */\n isOkAnd(predicate: (value: T) => boolean): boolean;\n\n /**\n * Returns `true` if the result is `Err` and the provided predicate returns `true` for the contained error.\n * @param predicate - A function that takes the `Err` value and returns a boolean.\n */\n isErrAnd(predicate: (error: E) => boolean): boolean;\n\n // #endregion\n\n // #region Extracting the contained value\n\n /**\n * These methods extract the contained value in a `Result<T, E>` when it is the `Ok` variant.\n */\n\n /**\n * Returns the contained `Ok` value, with a provided error message if the result is `Err`.\n * @param msg - The error message to provide if the result is an `Err`.\n * @throws {TypeError} Throws an error with the provided message if the result is an `Err`.\n */\n expect(msg: string): T;\n\n /**\n * Returns the contained `Ok` value.\n * @throws {TypeError} Throws an error if the result is an `Err`.\n */\n unwrap(): T;\n\n /**\n * Returns the contained `Ok` value or a provided default.\n * @param defaultValue - The value to return if the result is an `Err`.\n */\n unwrapOr(defaultValue: T): T;\n\n /**\n * Returns the contained `Ok` value or computes it from a closure if the result is `Err`.\n * @param fn - A function that takes the `Err` value and returns an `Ok` value.\n */\n unwrapOrElse(fn: (error: E) => T): T;\n\n /**\n * These methods extract the contained value in a `Result<T, E>` when it is the `Err` variant.\n */\n\n /**\n * Returns the contained `Err` value, with a provided error message if the result is `Ok`.\n * @param msg - The error message to provide if the result is an `Ok`.\n * @throws {TypeError} Throws an error with the provided message if the result is an `Ok`.\n */\n expectErr(msg: string): E;\n\n /**\n * Returns the contained `Err` value.\n * @throws {TypeError} Throws an error if the result is an `Ok`.\n */\n unwrapErr(): E;\n\n // #endregion\n\n // #region Transforming contained values\n\n /**\n * These methods transform `Result` to `Option`:\n */\n\n /**\n * Converts from `Result<T, E>` to `Option<T>`.\n * If the result is `Ok`, returns `Some(T)`.\n * If the result is `Err`, returns `None`.\n */\n ok(): Option<T>;\n\n /**\n * Converts from `Result<T, E>` to `Option<E>`.\n * If the result is `Err`, returns `Some(E)`.\n * If the result is `Ok`, returns `None`.\n */\n err(): Option<E>;\n\n /**\n * Transposes a `Result` of an `Option` into an `Option` of a `Result`.\n * @typeParam T - The type of the success value in the `Ok` variant of the `Option`.\n * @returns `Some` containing `Ok` if the result is `Ok` containing `Some`,\n * `Some` containing `Err` if the result is `Err`,\n * `None` if the result is `Ok` containing `None`.\n */\n transpose<T>(this: Result<Option<T>, E>): Option<Result<T, E>>;\n\n /**\n * This method transforms the contained value of the `Ok` variant:\n */\n\n /**\n * Maps a `Result<T, E>` to `Result<U, E>` by applying a function to a contained `Ok` value,\n * leaving an `Err` value untouched.\n * @typeParam U - The type of the value returned by the map function.\n * @param fn - A function that takes the `Ok` value and returns a new value.\n */\n map<U>(fn: (value: T) => U): Result<U, E>;\n\n /**\n * This method transforms the contained value of the `Err` variant:\n */\n\n /**\n * Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a contained `Err` value,\n * leaving an `Ok` value untouched.\n * @typeParam F - The type of the error returned by the map function.\n * @param fn - A function that takes the `Err` value and returns a new error value.\n */\n mapErr<F>(fn: (error: E) => F): Result<T, F>;\n\n /**\n * These methods transform a `Result<T, E>` into a value of a possibly different type `U`:\n */\n\n /**\n * Maps a `Result<T, E>` to `U` by applying a function to the contained `Ok` value (if `Ok`), or returns the provided default (if `Err`).\n * @typeParam U - The type of the value returned by the map function or the default value.\n * @param defaultValue - The value to return if the result is `Err`.\n * @param fn - A function that takes the `Ok` value and returns a new value.\n */\n mapOr<U>(defaultValue: U, fn: (value: T) => U): U;\n\n /**\n * Maps a `Result<T, E>` to `U` by applying a function to the contained `Ok` value (if `Ok`), or computes a default (if `Err`).\n * @typeParam U - The type of the value returned by the map function or the default function.\n * @param defaultFn - A function that returns the default value.\n * @param fn - A function that takes the `Ok` value and returns a new value.\n */\n mapOrElse<U>(defaultFn: (error: E) => U, fn: (value: T) => U): U;\n\n /**\n * Converts from `Result<Result<T, E>, E>` to `Result<T, E>`.\n * If the result is `Ok(Ok(T))`, returns `Ok(T)`.\n * If the result is `Ok(Err(E))` or `Err(E)`, returns `Err(E)`.\n */\n flatten<T>(this: Result<Result<T, E>, E>): Result<T, E>;\n\n // #endregion\n\n // #region Boolean operators\n\n /**\n * These methods treat the `Result` as a boolean value, where `Ok` acts like `true` and `Err` acts like `false`.\n */\n\n /**\n * Returns `this` if the result is `Err`, otherwise returns the passed `Result`.\n * @typeParam U - The type of the value in the other `Result`.\n * @param other - The `Result` to return if `this` is `Ok`.\n * @returns The passed `Result` if `this` is `Ok`, otherwise returns `this` (which is `Err`).\n */\n and<U>(other: Result<U, E>): Result<U, E>;\n\n /**\n * Returns `this` if it is `Ok`, otherwise returns the passed `Result`.\n * @typeParam F - The type of the error in the other `Result`.\n * @param other - The `Result` to return if `this` is `Err`.\n * @returns `this` if it is `Ok`, otherwise returns `other`.\n */\n or<F>(other: Result<T, F>): Result<T, F>;\n\n /**\n * Calls the provided function with the contained value if `this` is `Ok`, otherwise returns `this` as `Err`.\n * @typeParam U - The type of the value returned by the function.\n * @param fn - A function that takes the `Ok` value and returns a `Result`.\n * @returns The result of `fn` if `this` is `Ok`, otherwise `this` as `Err`.\n */\n andThen<U>(fn: (value: T) => Result<U, E>): Result<U, E>;\n\n /**\n * Calls the provided function with the contained error if `this` is `Err`, otherwise returns `this` as `Ok`.\n * @typeParam F - The type of the error returned by the function.\n * @param fn - A function that takes the `Err` value and returns a `Result`.\n * @returns The result of `fn` if `this` is `Err`, otherwise `this` as `Ok`.\n */\n orElse<F>(fn: (error: E) => Result<T, F>): Result<T, F>;\n\n // #endregion\n\n /**\n * Calls the provided function with the contained value if `this` is `Ok`, for side effects only.\n * Does not modify the `Result`.\n * @param fn - A function to call with the `Ok` value.\n * @returns `this`, unmodified.\n */\n inspect(fn: (value: T) => void): this;\n\n /**\n * Calls the provided function with the contained error if `this` is `Err`, for side effects only.\n * Does not modify the `Result`.\n * @param fn - A function to call with the `Err` value.\n * @returns `this`, unmodified.\n */\n inspectErr(fn: (error: E) => void): this;\n\n // #region Equals comparison\n\n /**\n * Tests whether `this` and `other` are both `Ok` containing equal values, or both are `Err` containing equal errors.\n * @param other - The other `Result` to compare with.\n * @returns `true` if `this` and `other` are both `Ok` with equal values, or both are `Err` with equal errors, otherwise `false`.\n */\n eq(other: Result<T, E>): boolean;\n\n // #endregion\n\n /**\n * Transforms the current Result into a new Result where the type of the error result is replaced with a new type `F`.\n * The type of the success result remains unchanged.\n * Just same as `result as unknown as Result<T, F>`.\n *\n * @typeParam F - The new type for the error result.\n * @returns `this` but the error result type is `F`.\n */\n asOk<F>(): Result<T, F>;\n\n /**\n * Transforms the current Result into a new Result where the type of the success result is replaced with a new type `U`.\n * The type of the error result remains unchanged.\n * Useful where you need to return an Error chained to another type.\n * Just same as `result as unknown as Result<U, E>`.\n *\n * @typeParam U - The new type for the success result.\n * @returns `this` but the success result type is `U`.\n */\n asErr<U>(): Result<U, E>;\n\n /**\n * Custom `toString` implementation that uses the `Result`'s contained value.\n */\n toString(): string;\n}\n\n/**\n * Export some commonly used types.\n */\n\n/**\n * Represents an asynchronous operation that yields an `Option<T>`.\n * This is a promise that resolves to either `Some(T)` if the value is present, or `None` if the value is absent.\n *\n * @typeParam T - The type of the value that may be contained within the `Option`.\n */\nexport type AsyncOption<T> = Promise<Option<T>>;\n\n/**\n * Represents an asynchronous operation that yields a `Result<T, E>`.\n * This is a promise that resolves to `Ok(T)` if the operation was successful, or `Err(E)` if there was an error.\n *\n * @typeParam T - The type of the value that is produced by a successful operation.\n * @typeParam E - The type of the error that may be produced by a failed operation.\n */\nexport type AsyncResult<T, E> = Promise<Result<T, E>>;\n\n/**\n * Represents a synchronous operation that yields a `Result<T, Error>`.\n * This is a result that is either `Ok(T)` if the operation was successful, or `Err(Error)` if there was an error.\n *\n * @typeParam T - The type of the value that is produced by a successful operation.\n */\nexport type IOResult<T> = Result<T, Error>;\n\n/**\n * Represents an asynchronous I/O operation that yields a `Result<T, Error>`.\n * This is a promise that resolves to `Ok(T)` if the I/O operation was successful, or `Err(Error)` if there was an error.\n *\n * @typeParam T - The type of the value that is produced by a successful I/O operation.\n */\nexport type AsyncIOResult<T> = Promise<IOResult<T>>;\n\n/**\n * Creates an `Option<T>` representing the presence of a value.\n * This function is typically used to construct an `Option` that contains a value, indicating that the operation yielding the value was successful.\n *\n * @typeParam T - The type of the value to be wrapped in a `Some`.\n * @param value - The value to wrap as a `Some` option.\n * @returns An `Option<T>` that contains the provided value, representing the `Some` case.\n *\n * @example\n * ```ts\n * const maybeValue = Some(1); // Option<number> with a value\n * if (maybeValue.isSome()) {\n * console.log(maybeValue.unwrap()); // Outputs: 1\n * }\n * ```\n */\nexport function Some<T>(value: T): Option<T> {\n const some: Option<T> = {\n [Symbol.toStringTag]: 'Option',\n [optionKindSymbol]: 'Some',\n\n isSome(): true {\n return true;\n },\n isNone(): false {\n return false;\n },\n isSomeAnd(predicate: (value: T) => boolean): boolean {\n return predicate(value);\n },\n\n expect(_msg: string): T {\n return value;\n },\n unwrap(): T {\n return value;\n },\n unwrapOr(_defaultValue: T): T {\n return value;\n },\n unwrapOrElse(_fn: () => T): T {\n return value;\n },\n\n okOr<E>(_error: E): Result<T, E> {\n return Ok(value);\n },\n okOrElse<E>(_err: () => E): Result<T, E> {\n return Ok(value);\n },\n transpose<T, E>(): Result<Option<T>, E> {\n const r = value as unknown as Result<T, E>;\n assertResult(r);\n return r.isOk() ? Ok(Some(r.unwrap())) : Err(r.unwrapErr());\n },\n\n filter(predicate: (value: T) => boolean): Option<T> {\n return predicate(value) ? some : None;\n },\n flatten<T>(): Option<T> {\n const o = value as unknown as Option<T>;\n assertOption(o);\n return o;\n },\n map<U>(fn: (value: T) => U): Option<U> {\n return Some(fn(value));\n },\n\n mapOr<U>(_defaultValue: U, fn: (value: T) => U): U {\n return fn(value);\n },\n mapOrElse<U>(_defaultFn: () => U, fn: (value: T) => U): U {\n return fn(value);\n },\n\n zip<U>(other: Option<U>): Option<[T, U]> {\n assertOption(other);\n return other.isSome() ? Some([value, other.unwrap()]) : None;\n },\n zipWith<U, R>(other: Option<U>, fn: (value: T, otherValue: U) => R): Option<R> {\n assertOption(other);\n return other.isSome() ? Some(fn(value, other.unwrap())) : None;\n },\n unzip<T, U>(): [Option<T>, Option<U>] {\n const tuple = value as unknown as [T, U];\n\n if (!Array.isArray(tuple) || tuple.length !== 2) {\n throw new TypeError('Unzip format is incorrect.');\n }\n\n const [a, b] = tuple;\n return [Some(a), Some(b)];\n },\n\n and<U>(other: Option<U>): Option<U> {\n assertOption(other);\n return other;\n },\n andThen<U>(fn: (value: T) => Option<U>): Option<U> {\n return fn(value);\n },\n or(_other: Option<T>): Option<T> {\n return some;\n },\n orElse(_fn: () => Option<T>): Option<T> {\n return some;\n },\n xor(other: Option<T>): Option<T> {\n assertOption(other);\n return other.isSome() ? None : some;\n },\n\n inspect(fn: (value: T) => void): Option<T> {\n fn(value);\n return some;\n },\n\n eq(other: Option<T>): boolean {\n assertOption(other);\n return other.isSome() && other.unwrap() === value;\n },\n\n toString(): string {\n return `Some(${ value })`;\n },\n } as const;\n\n return some;\n}\n\n/**\n * A constant representing the `None` case of an `Option`, indicating the absence of a value.\n * This constant is frozen to ensure it is immutable and cannot be altered, preserving the integrity of `None` throughout the application.\n */\nexport const None = Object.freeze<None>({\n [Symbol.toStringTag]: 'Option',\n [optionKindSymbol]: 'None',\n\n isSome(): false {\n return false;\n },\n isNone(): true {\n return true;\n },\n isSomeAnd(_predicate: (value: never) => boolean): false {\n return false;\n },\n\n expect(msg: string): never {\n throw new TypeError(msg);\n },\n unwrap(): never {\n throw new TypeError('Called `Option::unwrap()` on a `None` value');\n },\n unwrapOr<T>(defaultValue: T): T {\n return defaultValue;\n },\n unwrapOrElse<T>(fn: () => T): T {\n return fn();\n },\n\n okOr<E>(error: E): Result<never, E> {\n return Err(error);\n },\n okOrElse<E>(err: () => E): Result<never, E> {\n return Err(err());\n },\n transpose(): Result<None, never> {\n return Ok(None);\n },\n\n filter(_predicate: (value: never) => boolean): None {\n return None;\n },\n flatten(): None {\n return None;\n },\n map<U>(_fn: (value: never) => U): None {\n return None;\n },\n\n mapOr<U>(defaultValue: U, _fn: (value: never) => U): U {\n return defaultValue;\n },\n mapOrElse<U>(defaultFn: () => U, _fn: (value: never) => U): U {\n return defaultFn();\n },\n\n zip<U>(_other: Option<U>): None {\n return None;\n },\n zipWith<U, R>(_other: Option<U>, _fn: (value: never, otherValue: U) => R): None {\n return None;\n },\n unzip(): [None, None] {\n return [None, None];\n },\n\n and<U>(_other: Option<U>): None {\n return None;\n },\n andThen<U>(_fn: (value: never) => Option<U>): None {\n return None;\n },\n or<T>(other: Option<T>): Option<T> {\n assertOption(other);\n return other;\n },\n orElse<T>(fn: () => Option<T>): Option<T> {\n return fn();\n },\n xor<T>(other: Option<T>): Option<T> {\n assertOption(other);\n return other.isSome() ? other : None;\n },\n\n inspect(_fn: (value: never) => void): None {\n return None;\n },\n\n eq<T>(other: Option<T>): boolean {\n assertOption(other);\n return other === None;\n },\n\n toString(): string {\n return 'None';\n },\n}) as None;\n\n/**\n * Creates a `Result<T, E>` representing a successful outcome containing a value.\n * This function is used to construct a `Result` that signifies the operation was successful by containing the value `T`.\n *\n * @typeParam T - The type of the value to be contained in the `Ok` result.\n * @typeParam E - The type of the error that the result could potentially contain (not used in this case).\n * @param value - The value to wrap as an `Ok` result.\n * @returns A `Result<T, E>` that contains the provided value, representing the `Ok` case.\n *\n * @example\n * ```ts\n * const goodResult = Ok<number, Error>(1); // Result<number, Error> with a value\n * if (goodResult.isOk()) {\n * console.log(goodResult.unwrap()); // Outputs: 1\n * }\n * ```\n */\nexport function Ok<T, E>(value: T): Result<T, E> {\n const ok: Result<T, E> = {\n [Symbol.toStringTag]: 'Result',\n [resultKindSymbol]: 'Ok',\n\n isOk(): true {\n return true;\n },\n isErr(): false {\n return false;\n },\n isOkAnd(predicate: (value: T) => boolean): boolean {\n return predicate(value);\n },\n isErrAnd(_predicate: (error: E) => boolean): false {\n return false;\n },\n\n expect(_msg: string): T {\n return value;\n },\n unwrap(): T {\n return value;\n },\n unwrapOr(_defaultValue: T): T {\n return value;\n },\n unwrapOrElse(_fn: (error: E) => T): T {\n return value;\n },\n\n expectErr(msg: string): E {\n throw new TypeError(`${ msg }: ${ value }`);\n },\n unwrapErr(): E {\n throw new TypeError('Called `Result::unwrapErr()` on an `Ok` value');\n },\n\n ok(): Option<T> {\n return Some(value);\n },\n err(): None {\n return None;\n },\n transpose<T>(): Option<Result<T, E>> {\n const o = value as Option<T>;\n assertOption(o);\n return o.isSome() ? Some(Ok(o.unwrap())) : None;\n },\n\n map<U>(fn: (value: T) => U): Result<U, E> {\n return Ok(fn(value));\n },\n mapErr<F>(_fn: (error: E) => F): Result<T, F> {\n return Ok(value);\n },\n mapOr<U>(_defaultValue: U, fn: (value: T) => U): U {\n return fn(value);\n },\n mapOrElse<U>(_defaultFn: (error: E) => U, fn: (value: T) => U): U {\n return fn(value);\n },\n flatten<T>(): Result<T, E> {\n const r = value as Result<T, E>;\n assertResult(r);\n return r;\n },\n\n and<U>(other: Result<U, E>): Result<U, E> {\n assertResult(other);\n return other;\n },\n or<F>(_other: Result<T, F>): Result<T, F> {\n return ok as unknown as Result<T, F>;\n },\n andThen<U>(fn: (value: T) => Result<U, E>): Result<U, E> {\n return fn(value);\n },\n orElse<F>(_fn: (error: E) => Result<T, F>): Result<T, F> {\n return ok as unknown as Result<T, F>;\n },\n\n inspect(fn: (value: T) => void): Result<T, E> {\n fn(value);\n return ok;\n },\n inspectErr(_fn: (error: E) => void): Result<T, E> {\n return ok;\n },\n\n eq(other: Result<T, E>): boolean {\n assertResult(other);\n return other.isOk() && other.unwrap() === value;\n },\n\n asOk<F>(): Result<T, F> {\n return ok as unknown as Result<T, F>;\n },\n asErr(): never {\n throw new TypeError('Called `Result::asErr()` on an `Ok` value');\n },\n\n toString(): string {\n return `Ok(${ value })`;\n },\n } as const;\n\n return ok;\n}\n\n/**\n * Creates a `Result<T, E>` representing a failed outcome containing an error.\n * This function is used to construct a `Result` that signifies the operation failed by containing the error `E`.\n *\n * @typeParam T - The type of the value that the result could potentially contain (not used in this case).\n * @typeParam E - The type of the error to be wrapped in the `Err` result.\n * @param error - The error to wrap as an `Err` result.\n * @returns A `Result<T, E>` that contains the provided error, representing the `Err` case.\n *\n * @example\n * ```ts\n * const badResult = Err<number, Error>(new Error('Something went wrong'));\n * if (badResult.isErr()) {\n * console.error(badResult.unwrapErr()); // Outputs: Error: Something went wrong\n * }\n * ```\n */\nexport function Err<T, E>(error: E): Result<T, E> {\n const err: Result<T, E> = {\n [Symbol.toStringTag]: 'Result',\n [resultKindSymbol]: 'Err',\n\n isOk(): false {\n return false;\n },\n isErr(): true {\n return true;\n },\n isOkAnd(_predicate: (value: T) => boolean): false {\n return false;\n },\n isErrAnd(predicate: (error: E) => boolean): boolean {\n return predicate(error);\n },\n\n expect(msg: string): T {\n throw new TypeError(`${ msg }: ${ error }`);\n },\n unwrap(): T {\n throw new TypeError('Called `Result::unwrap()` on an `Err` value');\n },\n unwrapOr(defaultValue: T): T {\n return defaultValue;\n },\n unwrapOrElse(fn: (error: E) => T): T {\n return fn(error);\n },\n\n expectErr(_msg: string): E {\n return error;\n },\n unwrapErr(): E {\n return error;\n },\n\n ok(): None {\n return None;\n },\n err(): Option<E> {\n return Some(error);\n },\n transpose<T>(): Option<Result<T, E>> {\n return Some(err as unknown as Result<T, E>);\n },\n\n map<U>(_fn: (value: T) => U): Result<U, E> {\n return err as unknown as Result<U, E>;\n },\n mapErr<F>(fn: (error: E) => F): Result<T, F> {\n return Err(fn(error));\n },\n mapOr<U>(defaultValue: U, _fn: (value: T) => U): U {\n return defaultValue;\n },\n mapOrElse<U>(defaultFn: (error: E) => U, _fn: (value: T) => U): U {\n return defaultFn(error);\n },\n flatten<T>(): Result<T, E> {\n return err as unknown as Result<T, E>;\n },\n\n and<U>(_other: Result<U, E>): Result<U, E> {\n return err as unknown as Result<U, E>;\n },\n or<F>(other: Result<T, F>): Result<T, F> {\n assertResult(other);\n return other;\n },\n andThen<U>(_fn: (value: T) => Result<U, E>): Result<U, E> {\n return err as unknown as Result<U, E>;\n },\n orElse<F>(fn: (error: E) => Result<T, F>): Result<T, F> {\n return fn(error);\n },\n\n inspect(_fn: (value: T) => void): Result<T, E> {\n return err;\n },\n inspectErr(fn: (error: E) => void): Result<T, E> {\n fn(error);\n return err;\n },\n\n eq(other: Result<T, E>): boolean {\n assertResult(other);\n return other.isErr() && other.unwrapErr() === error;\n },\n\n asOk(): never {\n throw new TypeError('Called `Result::asOk()` on an `Err` value');\n },\n asErr<U>(): Result<U, E> {\n return err as unknown as Result<U, E>;\n },\n\n toString(): string {\n return `Err(${ error })`;\n },\n } as const;\n\n return err;\n}\n\n/**\n * Asserts that a given value is an `Option`.\n *\n * @typeParam T - The expected type of the value contained within the `Option`.\n * @param o - The value to be checked as an `Option`.\n * @throws {TypeError} If the value is not an `Option`.\n */\nfunction assertOption<T>(o: Option<T>): void {\n if (!isOption(o)) {\n throw new TypeError(`This(${ o }) is not an Option`);\n }\n}\n\n/**\n * Asserts that a given value is a `Result`.\n *\n * @typeParam T - The expected type of the success value contained within the `Result`.\n * @typeParam E - The expected type of the error value contained within the `Result`.\n * @param r - The value to be checked as a `Result`.\n * @throws {TypeError} If the value is not a `Result`.\n */\nfunction assertResult<T, E>(r: Result<T, E>): void {\n if (!isResult(r)) {\n throw new TypeError(`This(${ r }) is not a Result`);\n }\n}\n\n/**\n * Converts a Promise to a Result type, capturing the resolved value in an `Ok`, or the error in an `Err`.\n * This allows for promise-based asynchronous operations to be handled in a way that is more in line with the Result pattern.\n *\n * @typeParam T - The type of the value that the promise resolves to.\n * @typeParam E - The type of the error that the promise may reject with, defaults to `Error`.\n * @param p - The promise to convert into a `Result` type.\n * @returns A promise that resolves to a `Result<T, E>`. If the input promise `p` resolves, the resulting promise will resolve with `Ok<T>`. If the input promise `p` rejects, the resulting promise will resolve with `Err<E>`.\n *\n * @example\n * ```ts\n * async function example() {\n * const result = await promiseToResult(fetchData());\n * if (result.isOk()) {\n * console.log('Data:', result.unwrap());\n * } else {\n * console.error('Error:', result.unwrapErr());\n * }\n * }\n * ```\n */\nexport function promiseToResult<T, E = Error>(p: Promise<T>): Promise<Result<T, E>> {\n return p.then((x): Result<T, E> => {\n return Ok(x);\n }).catch((err: E): Result<T, E> => {\n return Err(err);\n });\n}\n\n/**\n * Checks if a value is an `Option`.\n *\n * @typeParam T - The expected type of the value contained within the `Option`.\n * @param o - The value to be checked as an `Option`.\n * @returns `true` if the value is an `Option`, otherwise `false`.\n */\nexport function isOption<T>(o: unknown): o is Option<T> {\n // `Some` and `None` must be an object.\n return o != null && typeof o === 'object' && optionKindSymbol in o;\n}\n\n/**\n * Checks if a value is a `Result`.\n *\n * @typeParam T - The expected type of the success value contained within the `Result`.\n * @typeParam E - The expected type of the error value contained within the `Result`.\n * @param r - The value to be checked as a `Result`.\n * @returns `true` if the value is a `Result`, otherwise `false`.\n */\nexport function isResult<T, E>(r: unknown): r is Result<T, E> {\n // `Ok` and `Err` must be an object.\n return r != null && typeof r === 'object' && resultKindSymbol in r;\n}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ist/types.d.ts CHANGED
@@ -27,6 +27,10 @@ pub enum Option<T> {
27
27
  * @typeParam T - The type of the value contained in the `Some` variant.
28
28
  */
29
29
  interface Option<T> {
30
+ /**
31
+ * [object Option].
32
+ */
33
+ [Symbol.toStringTag]: 'Option';
30
34
  /**
31
35
  * Identify `Some` or `None`.
32
36
  *
@@ -218,6 +222,10 @@ interface Option<T> {
218
222
  * @returns `true` if `this` and `other` are both `Some` with equal values, or both are `None`, otherwise `false`.
219
223
  */
220
224
  eq(other: Option<T>): boolean;
225
+ /**
226
+ * Custom `toString` implementation that uses the `Option`'s contained value.
227
+ */
228
+ toString(): string;
221
229
  }
222
230
  /**
223
231
  * The `Result` type is used for returning and propagating errors.
@@ -235,6 +243,10 @@ pub enum Result<T, E> {
235
243
  * @typeParam E - The type of the error contained in an unsuccessful `Result`.
236
244
  */
237
245
  interface Result<T, E> {
246
+ /**
247
+ * [object Result].
248
+ */
249
+ [Symbol.toStringTag]: 'Result';
238
250
  /**
239
251
  * Identify `Ok` or `Err`.
240
252
  *
@@ -417,6 +429,29 @@ interface Result<T, E> {
417
429
  * @returns `true` if `this` and `other` are both `Ok` with equal values, or both are `Err` with equal errors, otherwise `false`.
418
430
  */
419
431
  eq(other: Result<T, E>): boolean;
432
+ /**
433
+ * Transforms the current Result into a new Result where the type of the error result is replaced with a new type `F`.
434
+ * The type of the success result remains unchanged.
435
+ * Just same as `result as unknown as Result<T, F>`.
436
+ *
437
+ * @typeParam F - The new type for the error result.
438
+ * @returns `this` but the error result type is `F`.
439
+ */
440
+ asOk<F>(): Result<T, F>;
441
+ /**
442
+ * Transforms the current Result into a new Result where the type of the success result is replaced with a new type `U`.
443
+ * The type of the error result remains unchanged.
444
+ * Useful where you need to return an Error chained to another type.
445
+ * Just same as `result as unknown as Result<U, E>`.
446
+ *
447
+ * @typeParam U - The new type for the success result.
448
+ * @returns `this` but the success result type is `U`.
449
+ */
450
+ asErr<U>(): Result<U, E>;
451
+ /**
452
+ * Custom `toString` implementation that uses the `Result`'s contained value.
453
+ */
454
+ toString(): string;
420
455
  }
421
456
  /**
422
457
  * Export some commonly used types.
@@ -555,6 +590,23 @@ declare function Err<T, E>(error: E): Result<T, E>;
555
590
  * ```
556
591
  */
557
592
  declare function promiseToResult<T, E = Error>(p: Promise<T>): Promise<Result<T, E>>;
593
+ /**
594
+ * Checks if a value is an `Option`.
595
+ *
596
+ * @typeParam T - The expected type of the value contained within the `Option`.
597
+ * @param o - The value to be checked as an `Option`.
598
+ * @returns `true` if the value is an `Option`, otherwise `false`.
599
+ */
600
+ declare function isOption<T>(o: unknown): o is Option<T>;
601
+ /**
602
+ * Checks if a value is a `Result`.
603
+ *
604
+ * @typeParam T - The expected type of the success value contained within the `Result`.
605
+ * @typeParam E - The expected type of the error value contained within the `Result`.
606
+ * @param r - The value to be checked as a `Result`.
607
+ * @returns `true` if the value is a `Result`, otherwise `false`.
608
+ */
609
+ declare function isResult<T, E>(r: unknown): r is Result<T, E>;
558
610
 
559
- export { type AsyncIOResult, type AsyncOption, type AsyncResult, Err, type IOResult, None, Ok, type Option, type Result, Some, promiseToResult };
611
+ export { type AsyncIOResult, type AsyncOption, type AsyncResult, Err, type IOResult, None, Ok, type Option, type Result, Some, isOption, isResult, promiseToResult };
560
612
  //# sourceMappingURL=types.d.ts.map
package/docs/README.md CHANGED
@@ -34,4 +34,6 @@
34
34
  | [Err](functions/Err.md) | Creates a `Result<T, E>` representing a failed outcome containing an error. This function is used to construct a `Result` that signifies the operation failed by containing the error `E`. |
35
35
  | [Ok](functions/Ok.md) | Creates a `Result<T, E>` representing a successful outcome containing a value. This function is used to construct a `Result` that signifies the operation was successful by containing the value `T`. |
36
36
  | [Some](functions/Some.md) | Creates an `Option<T>` representing the presence of a value. This function is typically used to construct an `Option` that contains a value, indicating that the operation yielding the value was successful. |
37
+ | [isOption](functions/isOption.md) | Checks if a value is an `Option`. |
38
+ | [isResult](functions/isResult.md) | Checks if a value is a `Result`. |
37
39
  | [promiseToResult](functions/promiseToResult.md) | Converts a Promise to a Result type, capturing the resolved value in an `Ok`, or the error in an `Err`. This allows for promise-based asynchronous operations to be handled in a way that is more in line with the Result pattern. |
@@ -43,4 +43,4 @@ if (badResult.isErr()) {
43
43
 
44
44
  ## Defined in
45
45
 
46
- [prelude.ts:853](https://github.com/JiangJie/happy-rusty/blob/82bfb94138be23b97750c830432d7e013c0e5b80/src/enum/prelude.ts#L853)
46
+ [prelude.ts:1024](https://github.com/JiangJie/happy-rusty/blob/28ebaeb1ee8fded97e00cb58a36e776fbc44e585/src/enum/prelude.ts#L1024)
@@ -43,4 +43,4 @@ if (goodResult.isOk()) {
43
43
 
44
44
  ## Defined in
45
45
 
46
- [prelude.ts:774](https://github.com/JiangJie/happy-rusty/blob/82bfb94138be23b97750c830432d7e013c0e5b80/src/enum/prelude.ts#L774)
46
+ [prelude.ts:897](https://github.com/JiangJie/happy-rusty/blob/28ebaeb1ee8fded97e00cb58a36e776fbc44e585/src/enum/prelude.ts#L897)
@@ -42,4 +42,4 @@ if (maybeValue.isSome()) {
42
42
 
43
43
  ## Defined in
44
44
 
45
- [prelude.ts:625](https://github.com/JiangJie/happy-rusty/blob/82bfb94138be23b97750c830432d7e013c0e5b80/src/enum/prelude.ts#L625)
45
+ [prelude.ts:666](https://github.com/JiangJie/happy-rusty/blob/28ebaeb1ee8fded97e00cb58a36e776fbc44e585/src/enum/prelude.ts#L666)
@@ -0,0 +1,35 @@
1
+ [**happy-rusty**](../README.md) • **Docs**
2
+
3
+ ***
4
+
5
+ [happy-rusty](../README.md) / isOption
6
+
7
+ # Function: isOption()
8
+
9
+ ```ts
10
+ function isOption<T>(o): o is Option<T>
11
+ ```
12
+
13
+ Checks if a value is an `Option`.
14
+
15
+ ## Type Parameters
16
+
17
+ | Type Parameter | Description |
18
+ | ------ | ------ |
19
+ | `T` | The expected type of the value contained within the `Option`. |
20
+
21
+ ## Parameters
22
+
23
+ | Parameter | Type | Description |
24
+ | ------ | ------ | ------ |
25
+ | `o` | `unknown` | The value to be checked as an `Option`. |
26
+
27
+ ## Returns
28
+
29
+ `o is Option<T>`
30
+
31
+ `true` if the value is an `Option`, otherwise `false`.
32
+
33
+ ## Defined in
34
+
35
+ [prelude.ts:1193](https://github.com/JiangJie/happy-rusty/blob/28ebaeb1ee8fded97e00cb58a36e776fbc44e585/src/enum/prelude.ts#L1193)
@@ -0,0 +1,36 @@
1
+ [**happy-rusty**](../README.md) • **Docs**
2
+
3
+ ***
4
+
5
+ [happy-rusty](../README.md) / isResult
6
+
7
+ # Function: isResult()
8
+
9
+ ```ts
10
+ function isResult<T, E>(r): r is Result<T, E>
11
+ ```
12
+
13
+ Checks if a value is a `Result`.
14
+
15
+ ## Type Parameters
16
+
17
+ | Type Parameter | Description |
18
+ | ------ | ------ |
19
+ | `T` | The expected type of the success value contained within the `Result`. |
20
+ | `E` | The expected type of the error value contained within the `Result`. |
21
+
22
+ ## Parameters
23
+
24
+ | Parameter | Type | Description |
25
+ | ------ | ------ | ------ |
26
+ | `r` | `unknown` | The value to be checked as a `Result`. |
27
+
28
+ ## Returns
29
+
30
+ `r is Result<T, E>`
31
+
32
+ `true` if the value is a `Result`, otherwise `false`.
33
+
34
+ ## Defined in
35
+
36
+ [prelude.ts:1206](https://github.com/JiangJie/happy-rusty/blob/28ebaeb1ee8fded97e00cb58a36e776fbc44e585/src/enum/prelude.ts#L1206)
@@ -47,4 +47,4 @@ async function example() {
47
47
 
48
48
  ## Defined in
49
49
 
50
- [prelude.ts:957](https://github.com/JiangJie/happy-rusty/blob/82bfb94138be23b97750c830432d7e013c0e5b80/src/enum/prelude.ts#L957)
50
+ [prelude.ts:1178](https://github.com/JiangJie/happy-rusty/blob/28ebaeb1ee8fded97e00cb58a36e776fbc44e585/src/enum/prelude.ts#L1178)