import { Result, Ok, Err } from './result.js'; interface BaseOption extends Iterable ? U : never> { /** `true` when the Option is Some */ readonly some: boolean; /** `true` when the Option is None */ readonly none: boolean; /** * Returns the contained `Some` value, if exists. Throws an error if not. * @param msg the message to throw if no Some value. */ expect(msg: string): T; /** * Returns the contained `Some` value. * Because this function may throw, its use is generally discouraged. * Instead, prefer to handle the `None` case explicitly. * * Throws if the value is `None`. */ unwrap(): T; /** * Returns the contained `Some` value or a provided default. * * (This is the `unwrap_or` in rust) */ unwrapOr(val: T2): T | T2; /** * Calls `mapper` if the Option is `Some`, otherwise returns `None`. * This function can be used for control flow based on `Option` values. */ andThen(mapper: (val: T) => Option): Option; /** * Maps an `Option` to `Option` by applying a function to a contained `Some` value, * leaving a `None` value untouched. * * This function can be used to compose the Options of two functions. */ map(mapper: (val: T) => U): Option; /** * Maps an `Option` to `Option` by either converting `T` to `U` using `mapper` (in case * of `Some`) or using the `default_` value (in case of `None`). * * If `default` is a result of a function call consider using `mapOrElse` instead, it will * only evaluate the function when needed. */ mapOr(default_: U, mapper: (val: T) => U): U; /** * Maps an `Option` to `Option` by either converting `T` to `U` using `mapper` (in case * of `Some`) or producing a default value using the `default` function (in case of `None`). */ mapOrElse(default_: () => U, mapper: (val: T) => U): U; /** * Maps an `Option` to a `Result`. */ toResult(error: E): Result; } /** * Contains the None value */ declare class NoneImpl implements BaseOption { readonly some = false; readonly none = true; [Symbol.iterator](): Iterator; unwrapOr(val: T2): T2; expect(msg: string): never; unwrap(): never; map(_mapper: unknown): None; mapOr(default_: T2, _mapper: unknown): T2; mapOrElse(default_: () => U, _mapper: unknown): U; andThen(op: unknown): None; toResult(error: E): Err; toString(): string; } export declare const None: NoneImpl; export declare type None = NoneImpl; /** * Contains the success value */ declare class SomeImpl implements BaseOption { static readonly EMPTY: SomeImpl; readonly some: true; readonly none: false; readonly val: T; /** * Helper function if you know you have an Some and T is iterable */ [Symbol.iterator](): Iterator ? U : never>; constructor(val: T); unwrapOr(_val: unknown): T; expect(_msg: string): T; unwrap(): T; map(mapper: (val: T) => T2): Some; mapOr(_default_: T2, mapper: (val: T) => T2): T2; mapOrElse(_default_: () => U, mapper: (val: T) => U): U; andThen(mapper: (val: T) => Option): Option; toResult(error: E): Ok; /** * Returns the contained `Some` value, but never throws. * Unlike `unwrap()`, this method doesn't throw and is only callable on an Some * * Therefore, it can be used instead of `unwrap()` as a maintainability safeguard * that will fail to compile if the type of the Option is later changed to a None that can actually occur. * * (this is the `into_Some()` in rust) */ safeUnwrap(): T; toString(): string; } export declare const Some: typeof SomeImpl & ((val: T) => SomeImpl); export declare type Some = SomeImpl; export declare type Option = Some | None; export declare type OptionSomeType> = T extends Some ? U : never; export declare type OptionSomeTypes[]> = { [key in keyof T]: T[key] extends Option ? OptionSomeType : never; }; export declare namespace Option { /** * Parse a set of `Option`s, returning an array of all `Some` values. * Short circuits with the first `None` found, if any */ function all[]>(...options: T): Option>; /** * Parse a set of `Option`s, short-circuits when an input value is `Some`. * If no `Some` is found, returns `None`. */ function any[]>(...options: T): Option[number]>; function isOption(value: unknown): value is Option; } export {}; //# sourceMappingURL=option.d.ts.map