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.

23 lines 1.27 kB
/** * Applies a function to a value if the value is not `null` or `undefined`. If * the value is `null` or `undefined`, it returns `undefined`. * * This function provides a safe way to transform nullable values without * explicit null checks. It's similar to Optional.map() but works directly with * TypeScript's nullable types. Supports both regular and curried usage for * functional composition. * * @template A - The type of the input value (excluding null/undefined) * @template B - The type of the value returned by the mapping function * @param value - The value to potentially transform (can be `A`, `null`, or * `undefined`) * @param mapFn - A function that transforms a non-nullable value of type `A` to * type `B` * @returns The result of applying `mapFn` to `value` if value is not * null/undefined; otherwise `undefined` * @see Optional - For more complex optional value handling * @see Result - For error handling with detailed error information */ export declare function mapNullable<const A, const B>(value: A | null | undefined, mapFn: (v: A) => B): B | undefined; export declare function mapNullable<const A, const B>(mapFn: (v: A) => B): (value: A | null | undefined) => B | undefined; //# sourceMappingURL=map-nullable.d.mts.map