UNPKG

@rbxts/rotype

Version:

Advanced runtime type checking library

48 lines (47 loc) 1.93 kB
import type { Result as ResultType } from "./result"; export declare class Option<T> { protected readonly value: T | undefined; protected constructor(value: T | undefined); static none<T>(): Option<T>; static some<T>(val: T): Option<T>; static wrap<T>(val: T | undefined): Option<T>; toString(): string; isSome(): boolean; isNone(): boolean; contains(x: T): boolean; expect(msg: unknown): T | never; unwrap(): T | never; unwrapOr(def: T): T; unwrapOrElse(gen: () => T): T; map<U>(func: (item: T) => U): Option<U>; inspect(func: (item: T) => void): this; mapOr<U>(def: U, func: (item: T) => U): U; mapOrElse<U>(def: () => U, func: (item: T) => U): U; okOr<E>(err: E): ResultType<T, E>; okOrElse<E>(err: () => E): ResultType<T, E>; and<U>(other: Option<U>): Option<U>; andWith<U>(other: (val: T) => Option<U>): Option<U>; filter(func: (val: T) => boolean): Option<T>; or(other: Option<T>): Option<T>; orElse(other: () => Option<T>): Option<T>; xor(other: Option<T>): Option<T>; zip<U>(other: Option<U>): Option<[T, U]>; zipWith<U, R>(other: Option<U>, func: (self: T, other: U) => R): Option<R>; copied(): Option<T>; cloned(this: Option<{ cloned: () => T; }>): Option<T>; transpose<R, E>(this: Option<ResultType<R, E>>): ResultType<Option<R>, E>; flatten<I>(this: Option<Option<I>>): Option<I>; /** * Executes one of two callbacks based on the type of the contained value. * Replacement for Rust's `match` expression. * @param ifSome Callback executed when this Option contains a Some value. * @param ifNone Callback executed when this Option contains a None value. */ match<R>(ifSome: (val: T) => R, ifNone: () => R): R; /** * Returns the contained value directly. Only meant for special cases like serialisation. */ asPtr(): T | undefined; }