Like partial but for unary functions that accept a single object argument
const add = ({ a = 0, b = 0, c = 0 }: { a?: number; b?: number; c?: number }) => a + b + c; const addPartial = partob(add, { a: 1 });addPartial({ b: 2 }); // 3addPartial({ b: 1, c: 5 }); // 7
npx atmx add helper partob
Copy and paste the following method into @/utils/helpers/undefined.ts:
@/utils/helpers/undefined.ts
/*** Like partial but for unary functions that accept a single object* argument** @example* const add = (* {a = 0, b = 0, c = 0}: {* a?: number,* b?: number,* c?: number* }* ) => a + b + c** const addPartial = partob(add, { a: 1 })* addPartial({ b: 2 }) // 3* addPartial({ b: 1, c: 5 }) // 7*/export function partob<T, K, PartialArgs extends Partial<T>>(fn: (args: T) => K,argobj: PartialArgs,): (restobj: Omit<T, keyof PartialArgs>) => K {return (restobj) => fn({ ...argobj, ...restobj } as T);}