UNPKG

ts-data-forge

Version:

[![npm version](https://img.shields.io/npm/v/ts-data-forge.svg)](https://www.npmjs.com/package/ts-data-forge) [![npm downloads](https://img.shields.io/npm/dm/ts-data-forge.svg)](https://www.npmjs.com/package/ts-data-forge) [![License](https://img.shields.

32 lines 1.22 kB
import { type Unwrap } from './types.mjs'; /** * Filters an `Optional` based on a predicate. If the `Optional` is `Some` and * the predicate returns true, returns the original `Optional`. Otherwise * returns `None`. * * @example * * ```ts * const even = Optional.filter(Optional.some(4), (value) => value % 2 === 0); * * const odd = Optional.filter(Optional.some(3), (value) => value % 2 === 0); * * assert.deepStrictEqual(even, Optional.some(4)); * * assert.deepStrictEqual(odd, Optional.none); * * const filterEven = Optional.filter((value: number) => value % 2 === 0); * * assert.deepStrictEqual(filterEven(Optional.some(6)), Optional.some(6)); * * assert.deepStrictEqual(filterEven(Optional.some(5)), Optional.none); * ``` * * @template O The input `UnknownOptional` type. * @param optional The `Optional` to filter. * @param predicate The predicate function. * @returns The filtered `Optional`. */ export declare function filter<O extends UnknownOptional>(optional: O, predicate: (value: Unwrap<O>) => boolean): Optional<Unwrap<O>>; export declare function filter<S>(predicate: (value: S) => boolean): (optional: Optional<S>) => Optional<S>; //# sourceMappingURL=optional-filter.d.mts.map