import type { MapOption, Option, OptionMapOption, OptionMapOrElse, OptionMapResult, OptionPromise, Result, ResultPromise } from "./mod"; export interface OptionCombinators { [Symbol.iterator]: () => IterableIterator; /** * Returns None if the option is None, otherwise returns optb. * * Arguments passed to and are eagerly evaluated; if you are passing the result of a function call, * it is recommended to use {@linkcode andThen}, which is lazily evaluated. */ and(optb: Option): Option; /** * Returns None if the option is None, otherwise calls f with the wrapped value and returns the result. * * Some languages call this operation flatmap. */ andThen(fn: (some: T) => OptionPromise): OptionPromise; andThen(fn: (some: T) => Promise>): OptionPromise; andThen(fn: (some: T) => Option): Option; /** * Converts from Option> to Option. */ flatten(this: Option>): Option; flatten(this: Option): Option; /** * Returns None if the option is None, otherwise calls predicate with the wrapped value and returns: * * - Some(t) if predicate returns true (where t is the wrapped value), and * - None if predicate returns false. */ filter(predicate: (some: T) => boolean): Option; isSome(): boolean; isNone(): boolean; /** * Maps an Option to an Option by applying a function to a contained value. */ map(fn: (some: T) => U): MapOption; /** * Computes a default function result (if None), or applies a different function to the contained value (if Some). * * When U is `Promise>`, the actual return type will be `OptionPromise`. * U should not be `Promise

` where P is not Option, @see {@linkcode mapOrElse} or @see {@linkcode mapResult}for returning non-Option promises */ mapOption(def: () => U, fn: (some: T) => U): OptionMapOption; /** * Computes a default function result (if None), or applies a different function to the contained value (if Some). * * When U is `Promise>`, the actual return type will be `ResultPromise`. * U should not be `Promise

` where P is not Option, @see {@linkcode mapOrElse} or {@linkcode mapOption} for returning other promises */ mapResult(def: () => U, fn: (some: T) => U): OptionMapResult; /** * Computes a default function result (if None), or applies a different function to the contained value (if Some). * * U should not be `Promise>` @see {@linkcode mapOption}, nor `Promise>`{@linkcode mapResult} for * returning promises to Option or Result */ mapOrElse(def: () => U, fn: (some: T) => U): OptionMapOrElse; /** * Transforms the {@linkcode Option} into a {@linkcode Result}, * mapping {@linkcode Some(v)} to {@linkcode Ok(v)} and {@linkcode None} to {@linkcode Err(err)}. * * Arguments passed to okOr are eagerly evaluated; if you are passing the result of a function call, * it is recommended to use {@linkcode okOrElse}, which is lazily evaluated. */ okOr(err: E): Result; /** * Transforms the {@linkcode Option} into a {@linkcode Result}, * mapping {@linkcode Some(v)} to {@linkcode Ok(v)} and {@linkcode None} to {@linkcode Err(fn())}. */ okOrElse(fn: () => Promise): ResultPromise; okOrElse(fn: () => E): Result; /** * Returns the option if it contains a value, otherwise returns optb. * * Arguments passed to or are eagerly evaluated; if you are passing the result of a function call, * it is recommended to use {@linkcode orElse}, which is lazily evaluated. */ or(optb: Option): Option; /** * Returns the option if it contains a value, otherwise calls f and returns the result. */ orElse(fn: () => Promise>): OptionPromise; orElse(fn: () => Option): Option; /** * Returns the contained Some value or a provided default. * * Arguments passed to unwrap_or are eagerly evaluated; * if you are passing the result of a function call, * it is recommended to use {@linkcode unwrapOrElse}, which is lazily evaluated. */ unwrapOr(def: T): T; /** * Returns the contained Some value or computes it from a closure. */ unwrapOrElse(def: () => T): T; unwrapOrElse(def: () => Promise): Promise | T; /** * Returns Some if exactly one of self, optb is Some, otherwise returns None. */ xor(optb: Option): Option; } export interface UnwrapableOption extends OptionCombinators { type: symbol; unwrap(): T; }