import { Box } from "./box"; import { DefaultOrFunc } from "./fn"; import { Result } from "./result"; /** Means no value */ export declare type None = null | undefined; /** May have no value * ```ts * type Maybe = T | None * ``` */ export declare type Maybe = T | None; /** T or null */ export declare type Nullable = T | null; /** T or undefined */ export declare type Voidable = T | undefined; /** Check is value */ export declare function isSome(v: Maybe): v is T; /** Check is no value */ export declare function isNone(v: Maybe): v is None; export declare namespace Maybe { /** Map if there is a value, otherwise return undefined * * ## Example * ```ts * let a: 2 = map(1, v => v + 1) * let b: undefined = map(null, v => v + 1) * ``` */ function map(v: Maybe, f: (v: T) => U): Voidable; /** Map if there is a value, otherwise return default value * * ## Example * ```ts * let a: 2 = map(1, 3, v => v + 1) * let b: 3 = map(null, 3, v => v + 1) * ``` */ function mapOr(v: Maybe, defv: DefaultOrFunc, f: (v: T) => U): U; /** If there is a value, pack it as ok, otherwise pack err * ``` */ function okOr(v: Maybe, e: DefaultOrFunc): Result; /** Return undefined if the value is None, otherwise return other. */ function and(v: Maybe, other: Maybe): Maybe; /** Return undefined if the value is None, otherwise call f with the value and return the result */ function then(v: Maybe, f: (v: T) => Maybe): Maybe; /** Return the value if the value is value, otherwise return other */ function or(v: Maybe, other: Maybe): Maybe; /** return value if exactly one of `v`, `other` is value, otherwise return undefined */ function xor(v: Maybe, other: Maybe): Voidable; /** Transpose to result */ function transpose(v?: Maybe>): Result, E>; /** Take the value, set the value in the box to undefined */ function take(v: Box>): Voidable; /** Replace the value in the box */ function replace(v: Box>, val: T): Maybe; /** As long as any value in the tuple is None, return undefined * * ## Example * ```ts * let a: [1, 2, 3] = zip(1, 2, 3) * let b: undefined = zip(1, null, 3) * let c: undefined = zip(1, 2, undefined) * ``` */ function zip[]>(...o: O): Voidable<{ [I in keyof O]: O[I] extends Maybe ? V : never; }>; }