export type Nullable = T | undefined | null; /** * Java-like optional implementation */ export declare class Optional { private readonly value?; private constructor(); /** * Map value to a new one. * * @param fn the mapping function * @returns new optional with mapped value */ readonly map: (fn: (val: T) => Nullable) => Optional; /** * Same as map(): * * @param fn mapping function to new optional * @returns new optional with mapped value */ readonly flatMap: (fn: (val: T) => Optional) => Optional; /** * If predicate evaluates to false; a new empty optional will be returned. * * @param fn the predicate function * @returns new empty optional or this */ readonly filter: (fn: (val: T) => boolean) => Optional; /** * Get the internal value. * * @returns internal value * @throws if no value is present */ readonly get: () => T; /** * Returns undefined. * * @returns always return undefined */ readonly elseUndefined: () => T | undefined; /** * Get internal value or given alternative. * * @param other alternative value * @returns internal value or given one */ readonly orElse: (other: T) => T; /** * Get internal value or from given function. * * @param fn alternative supplier * @returns internal value or return value from function */ readonly orElseGet: (fn: () => T) => T; /** * Returns the value if present or throws given error. * * @param err error supplier function * @returns the value if present * @throws the supplied error */ readonly elseThrow: (err: () => Error) => T; /** * Switch to alternative optional if this is empty. * * @param fn alternative optional supplier * @returns this or alternative optional */ readonly or: (fn: () => Optional) => Optional; /** * Checks if a value is present. * * @returns true or false */ readonly isPresent: () => boolean; /** * Check if a value is not present. * * @returns true or false */ readonly isNotPresent: () => boolean; /** * Consume value if present. * * @param fn the value consumer */ readonly ifPresent: (fn: (val: T) => void) => void; /** * Perform action if value is not present. * * @param fn the action to perform */ readonly ifNotPresent: (fn: () => void) => void; /** * Create an Optional for given value. * * @param value the optional value * @returns the Optional instance */ static readonly of: (value?: Nullable) => Optional; }