/** * A container object which may or may not contain a non-`nullish` value. * * @template TValue The type of value. */ export declare class Optional { #private; private constructor(); /** * Returns an empty `Optional` instance. No value is present for this `Optional`. * * @template TValue The type of value. * @returns {Optional} An empty `Optional` instance. */ static empty(): Optional; /** * Returns an `Optional` instance describing the given non-`nullish` value. * * @template TValue The type of value. * @param {TValue} value The value to describe, which must be non-`nullish`. * @returns {Optional} An `Optional` instance with the value present. * @throws {TypeError} If value is `nullish`. */ static of(value: TValue): Optional; /** * Returns an `Optional` instance describing the given value, if non-`nullish`, * otherwise returns an empty `Optional` instance. * * @template TValue The type of value. * @param {TValue} value The possibly-`nullish` value to describe. * @returns {Optional} An `Optional` instance with a present value if the specified value is non-`nullish`, * otherwise an empty `Optional` instance. */ static ofNullable(value?: TValue): Optional; /** * Indicates whether some other `Optional` instance is "equal to" this `Optional` instance. * The other `Optional` instance is considered equal if: * - both instances have no value present or; * - the present values are "equal to" each other. * * @param {Optional} other An `Optional` instance to be tested for equality. * @returns {boolean} `true` if the other `Optional` instance is "equal to" this `Optional` instance, otherwise `false`. */ equals(other: Optional): boolean; /** * If a value is present, and the value matches the given `predicate`, * returns an `Optional` instance describing the value, * otherwise returns an empty `Optional` instance. * * @param {(value: TValue) => boolean} predicate The `predicate` to apply to the value, if present. * @returns {Optional} An `Optional` instance describing the value of this `Optional`, * if a value is present and the value matches the given `predicate`, otherwise an empty `Optional` instance. * @throws {TypeError} If `predicate` is not a `function`. */ filter(predicate: (value: TValue) => boolean): Optional; /** * If a value is present, returns the result of applying the given `Optional`-bearing * mapping `function` to the value, otherwise returns an empty `Optional` instance. * * @template UValue The type of value of the `Optional` instance returned by the mapping `function`. * @param {(value: TValue) => Optional} mapper The mapping `function` to apply to the value, if present. * @returns {Optional} The result of applying an `Optional`-bearing mapping `function` to the value of * this `Optional`, if a value is present, otherwise an empty `Optional` instance. * @throws {TypeError} If `mapper` is not a `function` or does not return an `Optional` instance. */ flatMap(mapper: (value: TValue) => Optional): Optional; /** * If a value is present, returns the value, otherwise throws. * * @returns {TValue} The non-`nullish` value described by this `Optional` instance. * @throws {Error} If no value is present. */ get(): TValue; /** * If a value is present, performs the given `action` with the value, otherwise does nothing. * * @param {(value: TValue) => void} action The `action` to be performed, if a value is present. * @throws {TypeError} If `action` is not a `function`. */ ifPresent(action: (value: TValue) => void): void; /** * If a value is present, performs the given `action` with the value, * otherwise performs the given empty-based `action`. * * @param {(value: TValue) => void} action The `action` to be performed, if a value is present. * @param {() => void} emptyAction The empty-based `action` to be performed, if no value is present. * @throws {TypeError} If `action` or `emptyAction` is not a `function`. */ ifPresentOrElse(action: (value: TValue) => void, emptyAction: () => void): void; /** * If a value is not present, returns `true`, otherwise `false`. * * @returns {boolean} `true` if a value is not present, otherwise `false`. */ isEmpty(): boolean; /** * If a value is present, returns `true`, otherwise `false`. * * @returns {boolean} `true` if a value is present, otherwise `false`. */ isPresent(): boolean; /** * If a value is present, returns an `Optional` instance describing * the result of applying the given mapping `function` to the value, * otherwise returns an empty `Optional` instance. * * @template UValue The type of the value returned from the mapping `function`. * @param {(value: TValue) => UValue} mapper The mapping `function` to apply to a value, if present. * @returns {Optional} An `Optional` instance describing the result of applying a mapping `function` * to the value of this `Optional`, if a value is present, otherwise an empty `Optional` instance. * @throws {TypeError} If `mapper` is not a `function`. */ map(mapper: (value: TValue) => UValue): Optional; /** * If a value is present, returns an `Optional` instance describing the value, * otherwise returns an `Optional` instance produced by the supplying `function`. * * @param {() => Optional} supplier The supplying `function` that produces an `Optional` instance to be returned. * @returns {Optional} An `Optional` instance describing the value of this `Optional`, if a value is present, * otherwise an `Optional` instance produced by the supplying `function`. * @throws {TypeError} If `supplier` is not a `function` or does not return an `Optional` instance. */ or(supplier: () => Optional): Optional; /** * If a value is present, returns the value, otherwise returns other. * * @param {TValue | null} other The value to be returned, if no value is present. May be `nullish`. * @returns {TValue | null} The value, if present, otherwise other. */ orElse(other?: TValue | null): TValue | null; /** * If a value is present, returns the value, otherwise returns the result produced by the supplying `function`. * * @param {() => TValue | null} supplier The supplying `function` that produces a value to be returned. * @returns {TValue | null} The value, if present, otherwise the result produced by the supplying `function`. * @throws {TypeError} If `supplier` is not a `function`. */ orElseGet(supplier: () => TValue | null): TValue | null; /** * If a value is present, returns the value, otherwise throws. * * @returns {TValue} The non-`nullish` value described by this `Optional`. * @throws {Error} If no value is present. */ orElseThrow(): TValue; /** * If a value is present, returns the value, otherwise throws an error produced by the error supplying `function`. * * @template TError Type of the error to be thrown. * @param {() => TError} errorSupplier The supplying `function` that produces an error to be thrown. * @returns {TValue} The value, if present. * @throws {TError} If no value is present. * @throws {TypeError} If `errorSupplier` is not a `function` or does not return an `Error` instance. */ orElseGetThrow(errorSupplier: () => TError): TValue; /** * Returns a non-empty `string` representation of this `Optional` suitable for debugging. * * @returns {string} The `string` representation of this instance. */ toString(): string; } //# sourceMappingURL=index.d.ts.map