UNPKG

typescript-monads

Version:
34 lines 1.34 kB
import type { IMaybe } from './maybe.interface'; export declare function maybe<T>(value?: T | null): IMaybe<T>; export declare function none<T>(): IMaybe<T>; export declare function some<T>(value: T): IMaybe<T>; /** * Creates a function that returns a Maybe for the given property path. * * This is a powerful utility for safely navigating nested object structures. * It creates a type-safe property accessor function that returns a Maybe * containing the value at the specified path if it exists, or None if any * part of the path is missing. * * @param path A dot-separated string path to the desired property * @returns A function that takes an object and returns a Maybe of the property value * * @example * const getEmail = maybeProps<User>('profile.contact.email'); * * // Later in code * const emailMaybe = getEmail(user); * // Returns Some(email) if user.profile.contact.email exists * // Returns None if any part of the path is undefined/null * * // Use with filter * const validEmail = getEmail(user).filter(email => email.includes('@')); * * // Use with match * getEmail(user).match({ * some: email => sendVerification(email), * none: () => showEmailPrompt() * }); */ export declare function maybeProps<T, R = unknown>(path: string): (obj: T) => IMaybe<R>; //# sourceMappingURL=maybe.factory.d.ts.map