UNPKG

remeda

Version:

A utility library for JavaScript and Typescript.

43 lines (40 loc) 2.2 kB
import { I as IterableContainer } from './IterableContainer-CtfinwiH.cjs'; import { R as RemedaTypeError } from './RemedaTypeError-BIoNlKC-.cjs'; import { T as TupleSplits } from './TupleSplits-35Ht8LCA.cjs'; import 'type-fest'; import './CoercedArray-DRz3tqda.cjs'; import './PartialArray-DqgYiDUP.cjs'; import './TupleParts-Ci1vY__a.cjs'; type PartialBindError<Message extends string, Metadata = never> = RemedaTypeError<"partialBind", Message, { metadata: Metadata; }>; type TuplePrefix<T extends IterableContainer> = TupleSplits<T>["left"]; type RemovePrefix<T extends IterableContainer, Prefix extends TuplePrefix<T>> = Prefix extends readonly [] ? T : T extends readonly [infer THead, ...infer TRest] ? Prefix extends readonly [infer _PrefixHead, ...infer PrefixRest] ? RemovePrefix<TRest, PrefixRest> : [ THead?, ...RemovePrefix<TRest, Prefix> ] : T extends readonly [(infer _THead)?, ...infer TRest] ? Prefix extends readonly [infer _PrefixHead, ...infer PrefixRest] ? RemovePrefix<TRest, PrefixRest> : TRest : PartialBindError<"Function parameter list has unexpected shape", T>; /** * Creates a function that calls `func` with `partial` put before the arguments * it receives. * * Can be thought of as "freezing" some portion of a function's arguments, * resulting in a new function with a simplified signature. * * @param func - The function to wrap. * @param partial - The arguments to put before. * @returns A partially bound function. * @signature * R.partialBind(func, ...partial); * @example * const fn = (x: number, y: number, z: number) => x * 100 + y * 10 + z; * const partialFn = R.partialBind(fn, 1, 2); * partialFn(3); //=> 123 * * const logWithPrefix = R.partialBind(console.log, "[prefix]"); * logWithPrefix("hello"); //=> "[prefix] hello" * @dataFirst * @category Function * @see partialLastBind */ declare function partialBind<F extends (...args: any) => any, PrefixArgs extends TuplePrefix<Parameters<F>>, RemovedPrefix extends RemovePrefix<Parameters<F>, PrefixArgs>>(func: F, ...partial: PrefixArgs): (...rest: RemovedPrefix extends IterableContainer ? RemovedPrefix : never) => ReturnType<F>; export { partialBind };