UNPKG

@dancrumb/fpish

Version:

FP-friendly classes for Typescript

59 lines (58 loc) 1.66 kB
import { Optional } from "./Optional.js"; /** * This is the identity function - it returns whatever you pass in * * @category Utilities */ export declare const identity: <T>(t: T) => T; /** * A synonym for {@link identity} * * @category Utilities */ export declare const asIs: <T>(t: T) => T; /** * This function returns undefined, whatever you pass in * * @category Utilities */ export declare const drop: (t: unknown) => void; /** * This does the same as {@link drop}, but is typed to return undefined (rather than void) * * @category Utilities */ export declare const asUndefined: (t: unknown) => undefined; /** * Logs an error and moves on * * @category Utilities */ export declare const logError: (e: Error) => void; /** * This is a handy utility function that just throws an error * that exists in an Either. Useful for Either.apply * * @category Utilities */ export declare const throwError: (e: Error) => never; /** * Sometimes, all you're looking to do is extract a single property from and object. * That's what this function does * * @category Utilities */ export declare const extractProperty: <O extends object>(key: keyof O) => (o: O) => O[keyof O]; /** * Sometimes, you want a subset of an object, with just a few properties * That's what this function does * * @category Utilities */ export declare const pickProperties: <O extends object>(keys: (keyof O)[]) => (o: O) => Partial<O>; /** * Take function that returns a value and make that return an Optional * * @category Utilities */ export declare const asOptional: <A extends any[], R>(f: (...args: A) => R) => (...args: A) => Optional<NonNullable<R>>;