import { Result, Ok, Err } from './result'; 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 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; 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; 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