/** * Represents a value that may or may not exist. * Eliminates null/undefined bugs by making optionality explicit. * * @example * ```ts * const user = Option.from(getUserById(id)); * const name = user.map(u => u.name).unwrapOr('Anonymous'); * ``` */ export type Option = SomeOption | NoneOption; declare class SomeOption { readonly value: T; readonly _tag: "Some"; constructor(value: T); isSome(): this is SomeOption; isNone(): this is NoneOption; /** Transform the contained value. */ map(fn: (value: T) => U): Option; /** Chain operations that return an Option (flatMap). */ andThen(fn: (value: T) => Option): Option; /** Return this Option if Some, otherwise return the other. */ orElse(_fn: () => Option): Option; /** Get the value, or throw if None. */ unwrap(): T; /** Get the value, or return a default. */ unwrapOr(_defaultValue: T): T; /** Get the value, or compute a default. */ unwrapOrElse(_fn: () => T): T; /** Pattern match on the Option. */ match(handlers: { some: (value: T) => U; none: () => U; }): U; /** Filter: return None if the predicate fails. */ filter(predicate: (value: T) => boolean): Option; /** Apply a side-effect function if Some. */ tap(fn: (value: T) => void): Option; /** Zip with another Option. */ zip(other: Option): Option<[T, U]>; toJSON(): { tag: 'Some'; value: T; }; toString(): string; } declare class NoneOption { readonly _tag: "None"; isSome(): this is SomeOption; isNone(): this is NoneOption; map(_fn: (value: T) => U): Option; andThen(_fn: (value: T) => Option): Option; orElse(fn: () => Option): Option; unwrap(): T; unwrapOr(defaultValue: T): T; unwrapOrElse(fn: () => T): T; match(handlers: { some: (value: T) => U; none: () => U; }): U; filter(_predicate: (value: T) => boolean): Option; tap(_fn: (value: T) => void): Option; zip(_other: Option): Option<[T, U]>; toJSON(): { tag: 'None'; }; toString(): string; } /** * Create an Option containing a value. */ export declare function Some(value: T): Option; /** * Create an empty Option. */ export declare function None(): Option; export declare const OptionUtils: { /** * Create an Option from a nullable value. * null | undefined → None, everything else → Some. * * @example * ```ts * Option.from(null) // None * Option.from(undefined) // None * Option.from(42) // Some(42) * Option.from('') // Some('') (empty string is still Some) * ``` */ from(value: T | null | undefined): Option; /** * Create an Option from a predicate check. */ fromPredicate(value: T, predicate: (v: T) => boolean): Option; /** * Check if a value is an Option. */ isOption(value: unknown): value is Option; /** * Collect an array of Options into an Option of array. * Returns None if any Option is None. */ all(options: Option[]): Option; }; export {}; //# sourceMappingURL=option.d.ts.map