Add settings page for managing forecasting API key and URL via UI

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-20 14:37:36 +00:00
parent cae411eae7
commit 1c411e402e
19809 changed files with 1962608 additions and 97 deletions

View file

@ -0,0 +1,32 @@
//#region src/function/after.d.ts
/**
* Creates a function that only executes starting from the `n`-th call.
* The provided function will be invoked starting from the `n`-th call.
*
* This is particularly useful for scenarios involving events or asynchronous operations
* where an action should occur only after a certain number of invocations.
*
* @template F - The type of the function to be invoked.
* @param n - The number of calls required for `func` to execute.
* @param func - The function to be invoked.
* @returns A new function that:
* - Tracks the number of calls.
* - Invokes `func` starting from the `n`-th call.
* - Returns `undefined` if fewer than `n` calls have been made.
* @throws {Error} - Throws an error if `n` is negative.
* @example
*
* const afterFn = after(3, () => {
* console.log("called")
* });
*
* // Will not log anything.
* afterFn()
* // Will not log anything.
* afterFn()
* // Will log 'called'.
* afterFn()
*/
declare function after<F extends (...args: any[]) => any>(n: number, func: F): (...args: Parameters<F>) => ReturnType<F> | undefined;
//#endregion
export { after };

View file

@ -0,0 +1,32 @@
//#region src/function/after.d.ts
/**
* Creates a function that only executes starting from the `n`-th call.
* The provided function will be invoked starting from the `n`-th call.
*
* This is particularly useful for scenarios involving events or asynchronous operations
* where an action should occur only after a certain number of invocations.
*
* @template F - The type of the function to be invoked.
* @param n - The number of calls required for `func` to execute.
* @param func - The function to be invoked.
* @returns A new function that:
* - Tracks the number of calls.
* - Invokes `func` starting from the `n`-th call.
* - Returns `undefined` if fewer than `n` calls have been made.
* @throws {Error} - Throws an error if `n` is negative.
* @example
*
* const afterFn = after(3, () => {
* console.log("called")
* });
*
* // Will not log anything.
* afterFn()
* // Will not log anything.
* afterFn()
* // Will log 'called'.
* afterFn()
*/
declare function after<F extends (...args: any[]) => any>(n: number, func: F): (...args: Parameters<F>) => ReturnType<F> | undefined;
//#endregion
export { after };

View file

@ -0,0 +1,38 @@
//#region src/function/after.ts
/**
* Creates a function that only executes starting from the `n`-th call.
* The provided function will be invoked starting from the `n`-th call.
*
* This is particularly useful for scenarios involving events or asynchronous operations
* where an action should occur only after a certain number of invocations.
*
* @template F - The type of the function to be invoked.
* @param n - The number of calls required for `func` to execute.
* @param func - The function to be invoked.
* @returns A new function that:
* - Tracks the number of calls.
* - Invokes `func` starting from the `n`-th call.
* - Returns `undefined` if fewer than `n` calls have been made.
* @throws {Error} - Throws an error if `n` is negative.
* @example
*
* const afterFn = after(3, () => {
* console.log("called")
* });
*
* // Will not log anything.
* afterFn()
* // Will not log anything.
* afterFn()
* // Will log 'called'.
* afterFn()
*/
function after(n, func) {
if (!Number.isInteger(n) || n < 0) throw new Error(`n must be a non-negative integer.`);
let counter = 0;
return (...args) => {
if (++counter >= n) return func(...args);
};
}
//#endregion
exports.after = after;

View file

@ -0,0 +1,38 @@
//#region src/function/after.ts
/**
* Creates a function that only executes starting from the `n`-th call.
* The provided function will be invoked starting from the `n`-th call.
*
* This is particularly useful for scenarios involving events or asynchronous operations
* where an action should occur only after a certain number of invocations.
*
* @template F - The type of the function to be invoked.
* @param n - The number of calls required for `func` to execute.
* @param func - The function to be invoked.
* @returns A new function that:
* - Tracks the number of calls.
* - Invokes `func` starting from the `n`-th call.
* - Returns `undefined` if fewer than `n` calls have been made.
* @throws {Error} - Throws an error if `n` is negative.
* @example
*
* const afterFn = after(3, () => {
* console.log("called")
* });
*
* // Will not log anything.
* afterFn()
* // Will not log anything.
* afterFn()
* // Will log 'called'.
* afterFn()
*/
function after(n, func) {
if (!Number.isInteger(n) || n < 0) throw new Error(`n must be a non-negative integer.`);
let counter = 0;
return (...args) => {
if (++counter >= n) return func(...args);
};
}
//#endregion
export { after };

View file

@ -0,0 +1,22 @@
//#region src/function/ary.d.ts
/**
* Creates a function that invokes func, with up to n arguments, ignoring any additional arguments.
*
* @template F - The type of the function.
* @param func - The function to cap arguments for.
* @param n - The arity cap.
* @returns Returns the new capped function.
*
* @example
* function fn(a: number, b: number, c: number) {
* return Array.from(arguments);
* }
*
* ary(fn, 0)(1, 2, 3) // []
* ary(fn, 1)(1, 2, 3) // [1]
* ary(fn, 2)(1, 2, 3) // [1, 2]
* ary(fn, 3)(1, 2, 3) // [1, 2, 3]
*/
declare function ary<F extends (...args: any[]) => any>(func: F, n: number): (...args: any[]) => ReturnType<F>;
//#endregion
export { ary };

View file

@ -0,0 +1,22 @@
//#region src/function/ary.d.ts
/**
* Creates a function that invokes func, with up to n arguments, ignoring any additional arguments.
*
* @template F - The type of the function.
* @param func - The function to cap arguments for.
* @param n - The arity cap.
* @returns Returns the new capped function.
*
* @example
* function fn(a: number, b: number, c: number) {
* return Array.from(arguments);
* }
*
* ary(fn, 0)(1, 2, 3) // []
* ary(fn, 1)(1, 2, 3) // [1]
* ary(fn, 2)(1, 2, 3) // [1, 2]
* ary(fn, 3)(1, 2, 3) // [1, 2, 3]
*/
declare function ary<F extends (...args: any[]) => any>(func: F, n: number): (...args: any[]) => ReturnType<F>;
//#endregion
export { ary };

26
frontend/node_modules/es-toolkit/dist/function/ary.js generated vendored Normal file
View file

@ -0,0 +1,26 @@
//#region src/function/ary.ts
/**
* Creates a function that invokes func, with up to n arguments, ignoring any additional arguments.
*
* @template F - The type of the function.
* @param func - The function to cap arguments for.
* @param n - The arity cap.
* @returns Returns the new capped function.
*
* @example
* function fn(a: number, b: number, c: number) {
* return Array.from(arguments);
* }
*
* ary(fn, 0)(1, 2, 3) // []
* ary(fn, 1)(1, 2, 3) // [1]
* ary(fn, 2)(1, 2, 3) // [1, 2]
* ary(fn, 3)(1, 2, 3) // [1, 2, 3]
*/
function ary(func, n) {
return function(...args) {
return func.apply(this, args.slice(0, n));
};
}
//#endregion
exports.ary = ary;

26
frontend/node_modules/es-toolkit/dist/function/ary.mjs generated vendored Normal file
View file

@ -0,0 +1,26 @@
//#region src/function/ary.ts
/**
* Creates a function that invokes func, with up to n arguments, ignoring any additional arguments.
*
* @template F - The type of the function.
* @param func - The function to cap arguments for.
* @param n - The arity cap.
* @returns Returns the new capped function.
*
* @example
* function fn(a: number, b: number, c: number) {
* return Array.from(arguments);
* }
*
* ary(fn, 0)(1, 2, 3) // []
* ary(fn, 1)(1, 2, 3) // [1]
* ary(fn, 2)(1, 2, 3) // [1, 2]
* ary(fn, 3)(1, 2, 3) // [1, 2, 3]
*/
function ary(func, n) {
return function(...args) {
return func.apply(this, args.slice(0, n));
};
}
//#endregion
export { ary };

View file

@ -0,0 +1,13 @@
//#region src/function/asyncNoop.d.ts
/**
* An asynchronous no-operation function that does nothing.
* This can be used as a placeholder or default function.
*
* @example
* asyncNoop(); // Does nothing
*
* @returns This function returns a Promise that resolves to undefined.
*/
declare function asyncNoop(): Promise<void>;
//#endregion
export { asyncNoop };

View file

@ -0,0 +1,13 @@
//#region src/function/asyncNoop.d.ts
/**
* An asynchronous no-operation function that does nothing.
* This can be used as a placeholder or default function.
*
* @example
* asyncNoop(); // Does nothing
*
* @returns This function returns a Promise that resolves to undefined.
*/
declare function asyncNoop(): Promise<void>;
//#endregion
export { asyncNoop };

View file

@ -0,0 +1,13 @@
//#region src/function/asyncNoop.ts
/**
* An asynchronous no-operation function that does nothing.
* This can be used as a placeholder or default function.
*
* @example
* asyncNoop(); // Does nothing
*
* @returns This function returns a Promise that resolves to undefined.
*/
async function asyncNoop() {}
//#endregion
exports.asyncNoop = asyncNoop;

View file

@ -0,0 +1,13 @@
//#region src/function/asyncNoop.ts
/**
* An asynchronous no-operation function that does nothing.
* This can be used as a placeholder or default function.
*
* @example
* asyncNoop(); // Does nothing
*
* @returns This function returns a Promise that resolves to undefined.
*/
async function asyncNoop() {}
//#endregion
export { asyncNoop };

View file

@ -0,0 +1,32 @@
//#region src/function/before.d.ts
/**
* Creates a function that limits the number of times the given function (`func`) can be called.
*
* @template F - The type of the function to be invoked.
* @param n - The number of times the returned function is allowed to call `func` before stopping.
* - If `n` is 0, `func` will never be called.
* - If `n` is a positive integer, `func` will be called up to `n-1` times.
* @param func - The function to be called with the limit applied.
* @returns A new function that:
* - Tracks the number of calls.
* - Invokes `func` until the `n-1`-th call.
* - Returns `undefined` if the number of calls reaches or exceeds `n`, stopping further calls.
* @throws {Error} - Throw an error if `n` is negative.
* @example
*
* const beforeFn = before(3, () => {
* console.log("called");
* })
*
* // Will log 'called'.
* beforeFn();
*
* // Will log 'called'.
* beforeFn();
*
* // Will not log anything.
* beforeFn();
*/
declare function before<F extends (...args: any[]) => any>(n: number, func: F): (...args: Parameters<F>) => ReturnType<F> | undefined;
//#endregion
export { before };

View file

@ -0,0 +1,32 @@
//#region src/function/before.d.ts
/**
* Creates a function that limits the number of times the given function (`func`) can be called.
*
* @template F - The type of the function to be invoked.
* @param n - The number of times the returned function is allowed to call `func` before stopping.
* - If `n` is 0, `func` will never be called.
* - If `n` is a positive integer, `func` will be called up to `n-1` times.
* @param func - The function to be called with the limit applied.
* @returns A new function that:
* - Tracks the number of calls.
* - Invokes `func` until the `n-1`-th call.
* - Returns `undefined` if the number of calls reaches or exceeds `n`, stopping further calls.
* @throws {Error} - Throw an error if `n` is negative.
* @example
*
* const beforeFn = before(3, () => {
* console.log("called");
* })
*
* // Will log 'called'.
* beforeFn();
*
* // Will log 'called'.
* beforeFn();
*
* // Will not log anything.
* beforeFn();
*/
declare function before<F extends (...args: any[]) => any>(n: number, func: F): (...args: Parameters<F>) => ReturnType<F> | undefined;
//#endregion
export { before };

View file

@ -0,0 +1,38 @@
//#region src/function/before.ts
/**
* Creates a function that limits the number of times the given function (`func`) can be called.
*
* @template F - The type of the function to be invoked.
* @param n - The number of times the returned function is allowed to call `func` before stopping.
* - If `n` is 0, `func` will never be called.
* - If `n` is a positive integer, `func` will be called up to `n-1` times.
* @param func - The function to be called with the limit applied.
* @returns A new function that:
* - Tracks the number of calls.
* - Invokes `func` until the `n-1`-th call.
* - Returns `undefined` if the number of calls reaches or exceeds `n`, stopping further calls.
* @throws {Error} - Throw an error if `n` is negative.
* @example
*
* const beforeFn = before(3, () => {
* console.log("called");
* })
*
* // Will log 'called'.
* beforeFn();
*
* // Will log 'called'.
* beforeFn();
*
* // Will not log anything.
* beforeFn();
*/
function before(n, func) {
if (!Number.isInteger(n) || n < 0) throw new Error("n must be a non-negative integer.");
let counter = 0;
return (...args) => {
if (++counter < n) return func(...args);
};
}
//#endregion
exports.before = before;

View file

@ -0,0 +1,38 @@
//#region src/function/before.ts
/**
* Creates a function that limits the number of times the given function (`func`) can be called.
*
* @template F - The type of the function to be invoked.
* @param n - The number of times the returned function is allowed to call `func` before stopping.
* - If `n` is 0, `func` will never be called.
* - If `n` is a positive integer, `func` will be called up to `n-1` times.
* @param func - The function to be called with the limit applied.
* @returns A new function that:
* - Tracks the number of calls.
* - Invokes `func` until the `n-1`-th call.
* - Returns `undefined` if the number of calls reaches or exceeds `n`, stopping further calls.
* @throws {Error} - Throw an error if `n` is negative.
* @example
*
* const beforeFn = before(3, () => {
* console.log("called");
* })
*
* // Will log 'called'.
* beforeFn();
*
* // Will log 'called'.
* beforeFn();
*
* // Will not log anything.
* beforeFn();
*/
function before(n, func) {
if (!Number.isInteger(n) || n < 0) throw new Error("n must be a non-negative integer.");
let counter = 0;
return (...args) => {
if (++counter < n) return func(...args);
};
}
//#endregion
export { before };

View file

@ -0,0 +1,127 @@
//#region src/function/curry.d.ts
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function noArgFunc() {
* return 42;
* }
* const curriedNoArgFunc = curry(noArgFunc);
* console.log(curriedNoArgFunc()); // 42
*/
declare function curry<R>(func: () => R): () => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function oneArgFunc(a: number) {
* return a * 2;
* }
* const curriedOneArgFunc = curry(oneArgFunc);
* console.log(curriedOneArgFunc(5)); // 10
*/
declare function curry<P, R>(func: (p: P) => R): (p: P) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function twoArgFunc(a: number, b: number) {
* return a + b;
* }
* const curriedTwoArgFunc = curry(twoArgFunc);
* const add5 = curriedTwoArgFunc(5);
* console.log(add5(10)); // 15
*/
declare function curry<P1, P2, R>(func: (p1: P1, p2: P2) => R): (p1: P1) => (p2: P2) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function threeArgFunc(a: number, b: number, c: number) {
* return a + b + c;
* }
* const curriedThreeArgFunc = curry(threeArgFunc);
* const add1 = curriedThreeArgFunc(1);
* const add3 = add1(2);
* console.log(add3(3)); // 6
*/
declare function curry<P1, P2, P3, R>(func: (p1: P1, p2: P2, p3: P3) => R): (p1: P1) => (p2: P2) => (p3: P3) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function fourArgFunc(a: number, b: number, c: number, d: number) {
* return a + b + c + d;
* }
* const curriedFourArgFunc = curry(fourArgFunc);
* const add1 = curriedFourArgFunc(1);
* const add3 = add1(2);
* const add6 = add3(3);
* console.log(add6(4)); // 10
*/
declare function curry<P1, P2, P3, P4, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function fiveArgFunc(a: number, b: number, c: number, d: number, e: number) {
* return a + b + c + d + e;
* }
* const curriedFiveArgFunc = curry(fiveArgFunc);
* const add1 = curriedFiveArgFunc(1);
* const add3 = add1(2);
* const add6 = add3(3);
* const add10 = add6(4);
* console.log(add10(5)); // 15
*/
declare function curry<P1, P2, P3, P4, P5, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => (p5: P5) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function that can be called with a single argument at a time.
*
* @example
* function sum(a: number, b: number, c: number) {
* return a + b + c;
* }
*
* const curriedSum = curry(sum);
*
* // The parameter `a` should be given the value `10`.
* const add10 = curriedSum(10);
*
* // The parameter `b` should be given the value `15`.
* const add25 = add10(15);
*
* // The parameter `c` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
* const result = add25(5);
*/
declare function curry(func: (...args: any[]) => any): (...args: any[]) => any;
//#endregion
export { curry };

View file

@ -0,0 +1,127 @@
//#region src/function/curry.d.ts
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function noArgFunc() {
* return 42;
* }
* const curriedNoArgFunc = curry(noArgFunc);
* console.log(curriedNoArgFunc()); // 42
*/
declare function curry<R>(func: () => R): () => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function oneArgFunc(a: number) {
* return a * 2;
* }
* const curriedOneArgFunc = curry(oneArgFunc);
* console.log(curriedOneArgFunc(5)); // 10
*/
declare function curry<P, R>(func: (p: P) => R): (p: P) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function twoArgFunc(a: number, b: number) {
* return a + b;
* }
* const curriedTwoArgFunc = curry(twoArgFunc);
* const add5 = curriedTwoArgFunc(5);
* console.log(add5(10)); // 15
*/
declare function curry<P1, P2, R>(func: (p1: P1, p2: P2) => R): (p1: P1) => (p2: P2) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function threeArgFunc(a: number, b: number, c: number) {
* return a + b + c;
* }
* const curriedThreeArgFunc = curry(threeArgFunc);
* const add1 = curriedThreeArgFunc(1);
* const add3 = add1(2);
* console.log(add3(3)); // 6
*/
declare function curry<P1, P2, P3, R>(func: (p1: P1, p2: P2, p3: P3) => R): (p1: P1) => (p2: P2) => (p3: P3) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function fourArgFunc(a: number, b: number, c: number, d: number) {
* return a + b + c + d;
* }
* const curriedFourArgFunc = curry(fourArgFunc);
* const add1 = curriedFourArgFunc(1);
* const add3 = add1(2);
* const add6 = add3(3);
* console.log(add6(4)); // 10
*/
declare function curry<P1, P2, P3, P4, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function fiveArgFunc(a: number, b: number, c: number, d: number, e: number) {
* return a + b + c + d + e;
* }
* const curriedFiveArgFunc = curry(fiveArgFunc);
* const add1 = curriedFiveArgFunc(1);
* const add3 = add1(2);
* const add6 = add3(3);
* const add10 = add6(4);
* console.log(add10(5)); // 15
*/
declare function curry<P1, P2, P3, P4, P5, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => (p5: P5) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function that can be called with a single argument at a time.
*
* @example
* function sum(a: number, b: number, c: number) {
* return a + b + c;
* }
*
* const curriedSum = curry(sum);
*
* // The parameter `a` should be given the value `10`.
* const add10 = curriedSum(10);
*
* // The parameter `b` should be given the value `15`.
* const add25 = add10(15);
*
* // The parameter `c` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
* const result = add25(5);
*/
declare function curry(func: (...args: any[]) => any): (...args: any[]) => any;
//#endregion
export { curry };

View file

@ -0,0 +1,41 @@
//#region src/function/curry.ts
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function that can be called with a single argument at a time.
*
* @example
* function sum(a: number, b: number, c: number) {
* return a + b + c;
* }
*
* const curriedSum = curry(sum);
*
* // The parameter `a` should be given the value `10`.
* const add10 = curriedSum(10);
*
* // The parameter `b` should be given the value `15`.
* const add25 = add10(15);
*
* // The parameter `c` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
* const result = add25(5);
*/
function curry(func) {
if (func.length === 0 || func.length === 1) return func;
return function(arg) {
return makeCurry(func, func.length, [arg]);
};
}
function makeCurry(origin, argsLength, args) {
if (args.length === argsLength) return origin(...args);
else {
const next = function(arg) {
return makeCurry(origin, argsLength, [...args, arg]);
};
return next;
}
}
//#endregion
exports.curry = curry;

View file

@ -0,0 +1,41 @@
//#region src/function/curry.ts
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* @param func - The function to curry.
* @returns A curried function that can be called with a single argument at a time.
*
* @example
* function sum(a: number, b: number, c: number) {
* return a + b + c;
* }
*
* const curriedSum = curry(sum);
*
* // The parameter `a` should be given the value `10`.
* const add10 = curriedSum(10);
*
* // The parameter `b` should be given the value `15`.
* const add25 = add10(15);
*
* // The parameter `c` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
* const result = add25(5);
*/
function curry(func) {
if (func.length === 0 || func.length === 1) return func;
return function(arg) {
return makeCurry(func, func.length, [arg]);
};
}
function makeCurry(origin, argsLength, args) {
if (args.length === argsLength) return origin(...args);
else {
const next = function(arg) {
return makeCurry(origin, argsLength, [...args, arg]);
};
return next;
}
}
//#endregion
export { curry };

View file

@ -0,0 +1,141 @@
//#region src/function/curryRight.d.ts
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function noArgFunc() {
* return 42;
* }
* const curriedNoArgFunc = curryRight(noArgFunc);
* console.log(curriedNoArgFunc()); // 42
*/
declare function curryRight<R>(func: () => R): () => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function oneArgFunc(a: number) {
* return a * 2;
* }
* const curriedOneArgFunc = curryRight(oneArgFunc);
* console.log(curriedOneArgFunc(5)); // 10
*/
declare function curryRight<P, R>(func: (p: P) => R): (p: P) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function twoArgFunc(a: number, b: number) {
* return [a, b];
* }
* const curriedTwoArgFunc = curryRight(twoArgFunc);
* const func = curriedTwoArgFunc(1);
* console.log(func(2)); // [2, 1]
*/
declare function curryRight<P1, P2, R>(func: (p1: P1, p2: P2) => R): (p2: P2) => (p1: P1) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function threeArgFunc(a: number, b: number, c: number) {
* return [a, b, c];
* }
* const curriedThreeArgFunc = curryRight(threeArgFunc);
* const func = curriedThreeArgFunc(1);
* const func2 = func(2);
* console.log(func2(3)); // [3, 2, 1]
*/
declare function curryRight<P1, P2, P3, R>(func: (p1: P1, p2: P2, p3: P3) => R): (p3: P3) => (p2: P2) => (p1: P1) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function fourArgFunc(a: number, b: number, c: number, d: number) {
* return [a, b, c, d];
* }
* const curriedFourArgFunc = curryRight(fourArgFunc);
* const func = curriedFourArgFunc(1);
* const func2 = func(2);
* const func3 = func2(3);
* console.log(func3(4)); // [4, 3, 2, 1]
*/
declare function curryRight<P1, P2, P3, P4, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4) => R): (p4: P4) => (p3: P3) => (p2: P2) => (p1: P1) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function fiveArgFunc(a: number, b: number, c: number, d: number, e: number) {
* return [a, b, c, d, e];
* }
* const curriedFiveArgFunc = curryRight(fiveArgFunc);
* const func = curriedFiveArgFunc(1);
* const func2 = func(2);
* const func3 = func2(3);
* const func4 = func3(4);
* console.log(func4(5)); // [5, 4, 3, 2, 1]
*/
declare function curryRight<P1, P2, P3, P4, P5, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R): (p5: P5) => (p4: P4) => (p3: P3) => (p2: P2) => (p1: P1) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function sum(a: number, b: number, c: number) {
* return a + b + c;
* }
*
* const curriedSum = curryRight(sum);
*
* // The parameter `c` should be given the value `10`.
* const add10 = curriedSum(10);
*
* // The parameter `b` should be given the value `15`.
* const add25 = add10(15);
*
* // The parameter `a` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
* const result = add25(5); // 30
*/
declare function curryRight(func: (...args: any[]) => any): (...args: any[]) => any;
//#endregion
export { curryRight };

View file

@ -0,0 +1,141 @@
//#region src/function/curryRight.d.ts
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function noArgFunc() {
* return 42;
* }
* const curriedNoArgFunc = curryRight(noArgFunc);
* console.log(curriedNoArgFunc()); // 42
*/
declare function curryRight<R>(func: () => R): () => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function oneArgFunc(a: number) {
* return a * 2;
* }
* const curriedOneArgFunc = curryRight(oneArgFunc);
* console.log(curriedOneArgFunc(5)); // 10
*/
declare function curryRight<P, R>(func: (p: P) => R): (p: P) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function twoArgFunc(a: number, b: number) {
* return [a, b];
* }
* const curriedTwoArgFunc = curryRight(twoArgFunc);
* const func = curriedTwoArgFunc(1);
* console.log(func(2)); // [2, 1]
*/
declare function curryRight<P1, P2, R>(func: (p1: P1, p2: P2) => R): (p2: P2) => (p1: P1) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function threeArgFunc(a: number, b: number, c: number) {
* return [a, b, c];
* }
* const curriedThreeArgFunc = curryRight(threeArgFunc);
* const func = curriedThreeArgFunc(1);
* const func2 = func(2);
* console.log(func2(3)); // [3, 2, 1]
*/
declare function curryRight<P1, P2, P3, R>(func: (p1: P1, p2: P2, p3: P3) => R): (p3: P3) => (p2: P2) => (p1: P1) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function fourArgFunc(a: number, b: number, c: number, d: number) {
* return [a, b, c, d];
* }
* const curriedFourArgFunc = curryRight(fourArgFunc);
* const func = curriedFourArgFunc(1);
* const func2 = func(2);
* const func3 = func2(3);
* console.log(func3(4)); // [4, 3, 2, 1]
*/
declare function curryRight<P1, P2, P3, P4, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4) => R): (p4: P4) => (p3: P3) => (p2: P2) => (p1: P1) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function fiveArgFunc(a: number, b: number, c: number, d: number, e: number) {
* return [a, b, c, d, e];
* }
* const curriedFiveArgFunc = curryRight(fiveArgFunc);
* const func = curriedFiveArgFunc(1);
* const func2 = func(2);
* const func3 = func2(3);
* const func4 = func3(4);
* console.log(func4(5)); // [5, 4, 3, 2, 1]
*/
declare function curryRight<P1, P2, P3, P4, P5, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R): (p5: P5) => (p4: P4) => (p3: P3) => (p2: P2) => (p1: P1) => R;
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function sum(a: number, b: number, c: number) {
* return a + b + c;
* }
*
* const curriedSum = curryRight(sum);
*
* // The parameter `c` should be given the value `10`.
* const add10 = curriedSum(10);
*
* // The parameter `b` should be given the value `15`.
* const add25 = add10(15);
*
* // The parameter `a` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
* const result = add25(5); // 30
*/
declare function curryRight(func: (...args: any[]) => any): (...args: any[]) => any;
//#endregion
export { curryRight };

View file

@ -0,0 +1,43 @@
//#region src/function/curryRight.ts
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function sum(a: number, b: number, c: number) {
* return a + b + c;
* }
*
* const curriedSum = curryRight(sum);
*
* // The parameter `c` should be given the value `10`.
* const add10 = curriedSum(10);
*
* // The parameter `b` should be given the value `15`.
* const add25 = add10(15);
*
* // The parameter `a` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
* const result = add25(5); // 30
*/
function curryRight(func) {
if (func.length === 0 || func.length === 1) return func;
return function(arg) {
return makeCurryRight(func, func.length, [arg]);
};
}
function makeCurryRight(origin, argsLength, args) {
if (args.length === argsLength) return origin(...args);
else {
const next = function(arg) {
return makeCurryRight(origin, argsLength, [arg, ...args]);
};
return next;
}
}
//#endregion
exports.curryRight = curryRight;

View file

@ -0,0 +1,43 @@
//#region src/function/curryRight.ts
/**
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
*
* Unlike `curry`, this function curries the function from right to left.
*
* @param func - The function to curry.
* @returns A curried function.
*
* @example
* function sum(a: number, b: number, c: number) {
* return a + b + c;
* }
*
* const curriedSum = curryRight(sum);
*
* // The parameter `c` should be given the value `10`.
* const add10 = curriedSum(10);
*
* // The parameter `b` should be given the value `15`.
* const add25 = add10(15);
*
* // The parameter `a` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
* const result = add25(5); // 30
*/
function curryRight(func) {
if (func.length === 0 || func.length === 1) return func;
return function(arg) {
return makeCurryRight(func, func.length, [arg]);
};
}
function makeCurryRight(origin, argsLength, args) {
if (args.length === argsLength) return origin(...args);
else {
const next = function(arg) {
return makeCurryRight(origin, argsLength, [arg, ...args]);
};
return next;
}
}
//#endregion
export { curryRight };

View file

@ -0,0 +1,77 @@
//#region src/function/debounce.d.ts
interface DebounceOptions {
/**
* An optional AbortSignal to cancel the debounced function.
*/
signal?: AbortSignal;
/**
* An optional array specifying whether the function should be invoked on the leading edge, trailing edge, or both.
* If `edges` includes "leading", the function will be invoked at the start of the delay period.
* If `edges` includes "trailing", the function will be invoked at the end of the delay period.
* If both "leading" and "trailing" are included, the function will be invoked at both the start and end of the delay period.
* @default ["trailing"]
*/
edges?: Array<'leading' | 'trailing'>;
}
interface DebouncedFunction<F extends (...args: any[]) => void> {
(...args: Parameters<F>): void;
/**
* Schedules the execution of the debounced function after the specified debounce delay.
* This method resets any existing timer, ensuring that the function is only invoked
* after the delay has elapsed since the last call to the debounced function.
* It is typically called internally whenever the debounced function is invoked.
*/
schedule: () => void;
/**
* Cancels any pending execution of the debounced function.
* This method clears the active timer and resets any stored context or arguments.
*/
cancel: () => void;
/**
* Immediately invokes the debounced function if there is a pending execution.
* This method executes the function right away if there is a pending execution.
*/
flush: () => void;
}
/**
* Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
* have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`
* method to cancel any pending execution.
*
* @template F - The type of function.
* @param func - The function to debounce.
* @param debounceMs - The number of milliseconds to delay.
* @param options - The options object
* @param options.signal - An optional AbortSignal to cancel the debounced function.
* @param options.edges - An optional array specifying whether the function should be invoked on the leading edge, trailing edge, or both.
* @returns A new debounced function with a `cancel` method.
*
* @example
* const debouncedFunction = debounce(() => {
* console.log('Function executed');
* }, 1000);
*
* // Will log 'Function executed' after 1 second if not called again in that time
* debouncedFunction();
*
* // Will not log anything as the previous call is canceled
* debouncedFunction.cancel();
*
* // With AbortSignal
* const controller = new AbortController();
* const signal = controller.signal;
* const debouncedWithSignal = debounce(() => {
* console.log('Function executed');
* }, 1000, { signal });
*
* debouncedWithSignal();
*
* // Will cancel the debounced function call
* controller.abort();
*/
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, {
signal,
edges
}?: DebounceOptions): DebouncedFunction<F>;
//#endregion
export { DebounceOptions, DebouncedFunction, debounce };

View file

@ -0,0 +1,77 @@
//#region src/function/debounce.d.ts
interface DebounceOptions {
/**
* An optional AbortSignal to cancel the debounced function.
*/
signal?: AbortSignal;
/**
* An optional array specifying whether the function should be invoked on the leading edge, trailing edge, or both.
* If `edges` includes "leading", the function will be invoked at the start of the delay period.
* If `edges` includes "trailing", the function will be invoked at the end of the delay period.
* If both "leading" and "trailing" are included, the function will be invoked at both the start and end of the delay period.
* @default ["trailing"]
*/
edges?: Array<'leading' | 'trailing'>;
}
interface DebouncedFunction<F extends (...args: any[]) => void> {
(...args: Parameters<F>): void;
/**
* Schedules the execution of the debounced function after the specified debounce delay.
* This method resets any existing timer, ensuring that the function is only invoked
* after the delay has elapsed since the last call to the debounced function.
* It is typically called internally whenever the debounced function is invoked.
*/
schedule: () => void;
/**
* Cancels any pending execution of the debounced function.
* This method clears the active timer and resets any stored context or arguments.
*/
cancel: () => void;
/**
* Immediately invokes the debounced function if there is a pending execution.
* This method executes the function right away if there is a pending execution.
*/
flush: () => void;
}
/**
* Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
* have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`
* method to cancel any pending execution.
*
* @template F - The type of function.
* @param func - The function to debounce.
* @param debounceMs - The number of milliseconds to delay.
* @param options - The options object
* @param options.signal - An optional AbortSignal to cancel the debounced function.
* @param options.edges - An optional array specifying whether the function should be invoked on the leading edge, trailing edge, or both.
* @returns A new debounced function with a `cancel` method.
*
* @example
* const debouncedFunction = debounce(() => {
* console.log('Function executed');
* }, 1000);
*
* // Will log 'Function executed' after 1 second if not called again in that time
* debouncedFunction();
*
* // Will not log anything as the previous call is canceled
* debouncedFunction.cancel();
*
* // With AbortSignal
* const controller = new AbortController();
* const signal = controller.signal;
* const debouncedWithSignal = debounce(() => {
* console.log('Function executed');
* }, 1000, { signal });
*
* debouncedWithSignal();
*
* // Will cancel the debounced function call
* controller.abort();
*/
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, {
signal,
edges
}?: DebounceOptions): DebouncedFunction<F>;
//#endregion
export { DebounceOptions, DebouncedFunction, debounce };

View file

@ -0,0 +1,91 @@
//#region src/function/debounce.ts
/**
* Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
* have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`
* method to cancel any pending execution.
*
* @template F - The type of function.
* @param func - The function to debounce.
* @param debounceMs - The number of milliseconds to delay.
* @param options - The options object
* @param options.signal - An optional AbortSignal to cancel the debounced function.
* @param options.edges - An optional array specifying whether the function should be invoked on the leading edge, trailing edge, or both.
* @returns A new debounced function with a `cancel` method.
*
* @example
* const debouncedFunction = debounce(() => {
* console.log('Function executed');
* }, 1000);
*
* // Will log 'Function executed' after 1 second if not called again in that time
* debouncedFunction();
*
* // Will not log anything as the previous call is canceled
* debouncedFunction.cancel();
*
* // With AbortSignal
* const controller = new AbortController();
* const signal = controller.signal;
* const debouncedWithSignal = debounce(() => {
* console.log('Function executed');
* }, 1000, { signal });
*
* debouncedWithSignal();
*
* // Will cancel the debounced function call
* controller.abort();
*/
function debounce(func, debounceMs, { signal, edges } = {}) {
let pendingThis = void 0;
let pendingArgs = null;
const leading = edges != null && edges.includes("leading");
const trailing = edges == null || edges.includes("trailing");
const invoke = () => {
if (pendingArgs !== null) {
func.apply(pendingThis, pendingArgs);
pendingThis = void 0;
pendingArgs = null;
}
};
const onTimerEnd = () => {
if (trailing) invoke();
cancel();
};
let timeoutId = null;
const schedule = () => {
if (timeoutId != null) clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
timeoutId = null;
onTimerEnd();
}, debounceMs);
};
const cancelTimer = () => {
if (timeoutId !== null) {
clearTimeout(timeoutId);
timeoutId = null;
}
};
const cancel = () => {
cancelTimer();
pendingThis = void 0;
pendingArgs = null;
};
const flush = () => {
invoke();
};
const debounced = function(...args) {
if (signal?.aborted) return;
pendingThis = this;
pendingArgs = args;
const isFirstCall = timeoutId == null;
schedule();
if (leading && isFirstCall) invoke();
};
debounced.schedule = schedule;
debounced.cancel = cancel;
debounced.flush = flush;
signal?.addEventListener("abort", cancel, { once: true });
return debounced;
}
//#endregion
exports.debounce = debounce;

View file

@ -0,0 +1,91 @@
//#region src/function/debounce.ts
/**
* Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
* have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`
* method to cancel any pending execution.
*
* @template F - The type of function.
* @param func - The function to debounce.
* @param debounceMs - The number of milliseconds to delay.
* @param options - The options object
* @param options.signal - An optional AbortSignal to cancel the debounced function.
* @param options.edges - An optional array specifying whether the function should be invoked on the leading edge, trailing edge, or both.
* @returns A new debounced function with a `cancel` method.
*
* @example
* const debouncedFunction = debounce(() => {
* console.log('Function executed');
* }, 1000);
*
* // Will log 'Function executed' after 1 second if not called again in that time
* debouncedFunction();
*
* // Will not log anything as the previous call is canceled
* debouncedFunction.cancel();
*
* // With AbortSignal
* const controller = new AbortController();
* const signal = controller.signal;
* const debouncedWithSignal = debounce(() => {
* console.log('Function executed');
* }, 1000, { signal });
*
* debouncedWithSignal();
*
* // Will cancel the debounced function call
* controller.abort();
*/
function debounce(func, debounceMs, { signal, edges } = {}) {
let pendingThis = void 0;
let pendingArgs = null;
const leading = edges != null && edges.includes("leading");
const trailing = edges == null || edges.includes("trailing");
const invoke = () => {
if (pendingArgs !== null) {
func.apply(pendingThis, pendingArgs);
pendingThis = void 0;
pendingArgs = null;
}
};
const onTimerEnd = () => {
if (trailing) invoke();
cancel();
};
let timeoutId = null;
const schedule = () => {
if (timeoutId != null) clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
timeoutId = null;
onTimerEnd();
}, debounceMs);
};
const cancelTimer = () => {
if (timeoutId !== null) {
clearTimeout(timeoutId);
timeoutId = null;
}
};
const cancel = () => {
cancelTimer();
pendingThis = void 0;
pendingArgs = null;
};
const flush = () => {
invoke();
};
const debounced = function(...args) {
if (signal?.aborted) return;
pendingThis = this;
pendingArgs = args;
const isFirstCall = timeoutId == null;
schedule();
if (leading && isFirstCall) invoke();
};
debounced.schedule = schedule;
debounced.cancel = cancel;
debounced.flush = flush;
signal?.addEventListener("abort", cancel, { once: true });
return debounced;
}
//#endregion
export { debounce };

View file

@ -0,0 +1,133 @@
//#region src/function/flow.d.ts
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param f The function to invoke.
* @returns Returns the new composite function.
*
* @example
* function noArgFunc() {
* return 42;
* }
*
* const combined = flow(noArgFunc);
* console.log(combined()); // 42
*/
declare function flow<R>(f: () => R): () => R;
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param f1 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* function oneArgFunc(a: number) {
* return a * 2;
* }
*
* const combined = flow(oneArgFunc);
* console.log(combined(5)); // 10
*/
declare function flow<A extends any[], R>(f1: (...args: A) => R): (...args: A) => R;
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param f1 The function to invoke.
* @param f2 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
*
* const combined = flow(add, square);
* console.log(combined(1, 2)); // 9
*/
declare function flow<A extends any[], R1, R2>(f1: (...args: A) => R1, f2: (a: R1) => R2): (...args: A) => R2;
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param f1 The function to invoke.
* @param f2 The function to invoke.
* @param f3 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
*
* const combined = flow(add, square, double);
* console.log(combined(1, 2)); // 18
*/
declare function flow<A extends any[], R1, R2, R3>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3): (...args: A) => R3;
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param f1 The function to invoke.
* @param f2 The function to invoke.
* @param f3 The function to invoke.
* @param f4 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toStr = (n: number) => n.toString();
*
* const combined = flow(add, square, double, toStr);
* console.log(combined(1, 2)); // '18'
*/
declare function flow<A extends any[], R1, R2, R3, R4>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4): (...args: A) => R4;
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param f1 The function to invoke.
* @param f2 The function to invoke.
* @param f3 The function to invoke.
* @param f4 The function to invoke.
* @param f5 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toStr = (n: number) => n.toString();
* const split = (s: string) => s.split('');
*
* const combined = flow(add, square, double, toStr, split);
* console.log(combined(1, 2)); // ['1', '8']
*/
declare function flow<A extends any[], R1, R2, R3, R4, R5>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5): (...args: A) => R5;
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param funcs The functions to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
*
* const combined = flow(add, square);
* console.log(combined(1, 2)); // 9
*/
declare function flow(...funcs: Array<(...args: any[]) => any>): (...args: any[]) => any;
//#endregion
export { flow };

View file

@ -0,0 +1,133 @@
//#region src/function/flow.d.ts
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param f The function to invoke.
* @returns Returns the new composite function.
*
* @example
* function noArgFunc() {
* return 42;
* }
*
* const combined = flow(noArgFunc);
* console.log(combined()); // 42
*/
declare function flow<R>(f: () => R): () => R;
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param f1 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* function oneArgFunc(a: number) {
* return a * 2;
* }
*
* const combined = flow(oneArgFunc);
* console.log(combined(5)); // 10
*/
declare function flow<A extends any[], R>(f1: (...args: A) => R): (...args: A) => R;
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param f1 The function to invoke.
* @param f2 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
*
* const combined = flow(add, square);
* console.log(combined(1, 2)); // 9
*/
declare function flow<A extends any[], R1, R2>(f1: (...args: A) => R1, f2: (a: R1) => R2): (...args: A) => R2;
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param f1 The function to invoke.
* @param f2 The function to invoke.
* @param f3 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
*
* const combined = flow(add, square, double);
* console.log(combined(1, 2)); // 18
*/
declare function flow<A extends any[], R1, R2, R3>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3): (...args: A) => R3;
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param f1 The function to invoke.
* @param f2 The function to invoke.
* @param f3 The function to invoke.
* @param f4 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toStr = (n: number) => n.toString();
*
* const combined = flow(add, square, double, toStr);
* console.log(combined(1, 2)); // '18'
*/
declare function flow<A extends any[], R1, R2, R3, R4>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4): (...args: A) => R4;
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param f1 The function to invoke.
* @param f2 The function to invoke.
* @param f3 The function to invoke.
* @param f4 The function to invoke.
* @param f5 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toStr = (n: number) => n.toString();
* const split = (s: string) => s.split('');
*
* const combined = flow(add, square, double, toStr, split);
* console.log(combined(1, 2)); // ['1', '8']
*/
declare function flow<A extends any[], R1, R2, R3, R4, R5>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5): (...args: A) => R5;
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param funcs The functions to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
*
* const combined = flow(add, square);
* console.log(combined(1, 2)); // 9
*/
declare function flow(...funcs: Array<(...args: any[]) => any>): (...args: any[]) => any;
//#endregion
export { flow };

25
frontend/node_modules/es-toolkit/dist/function/flow.js generated vendored Normal file
View file

@ -0,0 +1,25 @@
//#region src/function/flow.ts
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param funcs The functions to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
*
* const combined = flow(add, square);
* console.log(combined(1, 2)); // 9
*/
function flow(...funcs) {
return function(...args) {
let result = funcs.length ? funcs[0].apply(this, args) : args[0];
for (let i = 1; i < funcs.length; i++) result = funcs[i].call(this, result);
return result;
};
}
//#endregion
exports.flow = flow;

View file

@ -0,0 +1,25 @@
//#region src/function/flow.ts
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param funcs The functions to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
*
* const combined = flow(add, square);
* console.log(combined(1, 2)); // 9
*/
function flow(...funcs) {
return function(...args) {
let result = funcs.length ? funcs[0].apply(this, args) : args[0];
for (let i = 1; i < funcs.length; i++) result = funcs[i].call(this, result);
return result;
};
}
//#endregion
export { flow };

View file

@ -0,0 +1,145 @@
//#region src/function/flowRight.d.ts
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param f The function to invoke.
* @returns Returns the new composite function.
*
* @example
* function noArgFunc() {
* return 42;
* }
* const combined = flowRight(noArgFunc);
* console.log(combined()); // 42
*/
declare function flowRight<R>(f: () => R): () => R;
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param f1 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* function oneArgFunc(a: number) {
* return a * 2;
* }
* const combined = flowRight(oneArgFunc);
* console.log(combined(5)); // 10
*/
declare function flowRight<A extends any[], R>(f1: (...args: A) => R): (...args: A) => R;
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param f2 The function to invoke.
* @param f1 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
*
* const combined = flowRight(square, add);
* console.log(combined(1, 2)); // 9
*/
declare function flowRight<A extends any[], R1, R2>(f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R2;
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param f3 The function to invoke.
* @param f2 The function to invoke.
* @param f1 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
*
* const combined = flowRight(double, square, add);
* console.log(combined(1, 2)); // 18
*/
declare function flowRight<A extends any[], R1, R2, R3>(f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R3;
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param f4 The function to invoke.
* @param f3 The function to invoke.
* @param f2 The function to invoke.
* @param f1 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toStr = (n: number) => n.toString();
*
* const combined = flowRight(toStr, double, square, add);
* console.log(combined(1, 2)); // '18'
*/
declare function flowRight<A extends any[], R1, R2, R3, R4>(f4: (a: R3) => R4, f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R4;
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param f5 The function to invoke.
* @param f4 The function to invoke.
* @param f3 The function to invoke.
* @param f2 The function to invoke.
* @param f1 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toStr = (n: number) => n.toString();
* const split = (s: string) => s.split('');
*
* const combined = flowRight(split, toStr, double, square, add);
* console.log(combined(1, 2)); // ['1', '8']
*/
declare function flowRight<A extends any[], R1, R2, R3, R4, R5>(f5: (a: R4) => R5, f4: (a: R3) => R4, f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R5;
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param funcs The functions to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
*
* const combined = flowRight(square, add);
* console.log(combined(1, 2)); // 9
*/
declare function flowRight(...funcs: Array<(...args: any[]) => any>): (...args: any[]) => any;
//#endregion
export { flowRight };

View file

@ -0,0 +1,145 @@
//#region src/function/flowRight.d.ts
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param f The function to invoke.
* @returns Returns the new composite function.
*
* @example
* function noArgFunc() {
* return 42;
* }
* const combined = flowRight(noArgFunc);
* console.log(combined()); // 42
*/
declare function flowRight<R>(f: () => R): () => R;
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param f1 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* function oneArgFunc(a: number) {
* return a * 2;
* }
* const combined = flowRight(oneArgFunc);
* console.log(combined(5)); // 10
*/
declare function flowRight<A extends any[], R>(f1: (...args: A) => R): (...args: A) => R;
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param f2 The function to invoke.
* @param f1 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
*
* const combined = flowRight(square, add);
* console.log(combined(1, 2)); // 9
*/
declare function flowRight<A extends any[], R1, R2>(f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R2;
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param f3 The function to invoke.
* @param f2 The function to invoke.
* @param f1 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
*
* const combined = flowRight(double, square, add);
* console.log(combined(1, 2)); // 18
*/
declare function flowRight<A extends any[], R1, R2, R3>(f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R3;
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param f4 The function to invoke.
* @param f3 The function to invoke.
* @param f2 The function to invoke.
* @param f1 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toStr = (n: number) => n.toString();
*
* const combined = flowRight(toStr, double, square, add);
* console.log(combined(1, 2)); // '18'
*/
declare function flowRight<A extends any[], R1, R2, R3, R4>(f4: (a: R3) => R4, f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R4;
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param f5 The function to invoke.
* @param f4 The function to invoke.
* @param f3 The function to invoke.
* @param f2 The function to invoke.
* @param f1 The function to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toStr = (n: number) => n.toString();
* const split = (s: string) => s.split('');
*
* const combined = flowRight(split, toStr, double, square, add);
* console.log(combined(1, 2)); // ['1', '8']
*/
declare function flowRight<A extends any[], R1, R2, R3, R4, R5>(f5: (a: R4) => R5, f4: (a: R3) => R4, f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R5;
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param funcs The functions to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
*
* const combined = flowRight(square, add);
* console.log(combined(1, 2)); // 9
*/
declare function flowRight(...funcs: Array<(...args: any[]) => any>): (...args: any[]) => any;
//#endregion
export { flowRight };

View file

@ -0,0 +1,24 @@
const require_flow = require("./flow.js");
//#region src/function/flowRight.ts
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param funcs The functions to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
*
* const combined = flowRight(square, add);
* console.log(combined(1, 2)); // 9
*/
function flowRight(...funcs) {
return require_flow.flow(...funcs.reverse());
}
//#endregion
exports.flowRight = flowRight;

View file

@ -0,0 +1,24 @@
import { flow } from "./flow.mjs";
//#region src/function/flowRight.ts
/**
* Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
*
* @param funcs The functions to invoke.
* @returns Returns the new composite function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
*
* const combined = flowRight(square, add);
* console.log(combined(1, 2)); // 9
*/
function flowRight(...funcs) {
return flow(...funcs.reverse());
}
//#endregion
export { flowRight };

View file

@ -0,0 +1,23 @@
//#region src/function/identity.d.ts
/**
* Returns the input value unchanged.
*
* @template T - The type of the input value.
* @param x - The value to be returned.
* @returns The input value.
*
* @example
* // Returns 5
* identity(5);
*
* @example
* // Returns 'hello'
* identity('hello');
*
* @example
* // Returns { key: 'value' }
* identity({ key: 'value' });
*/
declare function identity<T>(x: T): T;
//#endregion
export { identity };

View file

@ -0,0 +1,23 @@
//#region src/function/identity.d.ts
/**
* Returns the input value unchanged.
*
* @template T - The type of the input value.
* @param x - The value to be returned.
* @returns The input value.
*
* @example
* // Returns 5
* identity(5);
*
* @example
* // Returns 'hello'
* identity('hello');
*
* @example
* // Returns { key: 'value' }
* identity({ key: 'value' });
*/
declare function identity<T>(x: T): T;
//#endregion
export { identity };

View file

@ -0,0 +1,25 @@
//#region src/function/identity.ts
/**
* Returns the input value unchanged.
*
* @template T - The type of the input value.
* @param x - The value to be returned.
* @returns The input value.
*
* @example
* // Returns 5
* identity(5);
*
* @example
* // Returns 'hello'
* identity('hello');
*
* @example
* // Returns { key: 'value' }
* identity({ key: 'value' });
*/
function identity(x) {
return x;
}
//#endregion
exports.identity = identity;

View file

@ -0,0 +1,25 @@
//#region src/function/identity.ts
/**
* Returns the input value unchanged.
*
* @template T - The type of the input value.
* @param x - The value to be returned.
* @returns The input value.
*
* @example
* // Returns 5
* identity(5);
*
* @example
* // Returns 'hello'
* identity('hello');
*
* @example
* // Returns { key: 'value' }
* identity({ key: 'value' });
*/
function identity(x) {
return x;
}
//#endregion
export { identity };

View file

@ -0,0 +1,22 @@
import { after } from "./after.mjs";
import { ary } from "./ary.mjs";
import { asyncNoop } from "./asyncNoop.mjs";
import { before } from "./before.mjs";
import { curry } from "./curry.mjs";
import { curryRight } from "./curryRight.mjs";
import { DebounceOptions, DebouncedFunction, debounce } from "./debounce.mjs";
import { flow } from "./flow.mjs";
import { flowRight } from "./flowRight.mjs";
import { identity } from "./identity.mjs";
import { MemoizeCache, memoize } from "./memoize.mjs";
import { negate } from "./negate.mjs";
import { noop } from "./noop.mjs";
import { once } from "./once.mjs";
import { partial } from "./partial.mjs";
import { partialRight } from "./partialRight.mjs";
import { rest } from "./rest.mjs";
import { retry } from "./retry.mjs";
import { spread } from "./spread.mjs";
import { ThrottleOptions, ThrottledFunction, throttle } from "./throttle.mjs";
import { unary } from "./unary.mjs";
export { type DebounceOptions, type DebouncedFunction, type MemoizeCache, type ThrottleOptions, type ThrottledFunction, after, ary, asyncNoop, before, curry, curryRight, debounce, flow, flowRight, identity, memoize, negate, noop, once, partial, partialRight, rest, retry, spread, throttle, unary };

View file

@ -0,0 +1,22 @@
import { after } from "./after.js";
import { ary } from "./ary.js";
import { asyncNoop } from "./asyncNoop.js";
import { before } from "./before.js";
import { curry } from "./curry.js";
import { curryRight } from "./curryRight.js";
import { DebounceOptions, DebouncedFunction, debounce } from "./debounce.js";
import { flow } from "./flow.js";
import { flowRight } from "./flowRight.js";
import { identity } from "./identity.js";
import { MemoizeCache, memoize } from "./memoize.js";
import { negate } from "./negate.js";
import { noop } from "./noop.js";
import { once } from "./once.js";
import { partial } from "./partial.js";
import { partialRight } from "./partialRight.js";
import { rest } from "./rest.js";
import { retry } from "./retry.js";
import { spread } from "./spread.js";
import { ThrottleOptions, ThrottledFunction, throttle } from "./throttle.js";
import { unary } from "./unary.js";
export { type DebounceOptions, type DebouncedFunction, type MemoizeCache, type ThrottleOptions, type ThrottledFunction, after, ary, asyncNoop, before, curry, curryRight, debounce, flow, flowRight, identity, memoize, negate, noop, once, partial, partialRight, rest, retry, spread, throttle, unary };

View file

@ -0,0 +1,43 @@
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require_after = require("./after.js");
const require_ary = require("./ary.js");
const require_asyncNoop = require("./asyncNoop.js");
const require_before = require("./before.js");
const require_curry = require("./curry.js");
const require_curryRight = require("./curryRight.js");
const require_debounce = require("./debounce.js");
const require_flow = require("./flow.js");
const require_flowRight = require("./flowRight.js");
const require_identity = require("./identity.js");
const require_memoize = require("./memoize.js");
const require_negate = require("./negate.js");
const require_noop = require("./noop.js");
const require_once = require("./once.js");
const require_partial = require("./partial.js");
const require_partialRight = require("./partialRight.js");
const require_rest = require("./rest.js");
const require_retry = require("./retry.js");
const require_spread = require("./spread.js");
const require_throttle = require("./throttle.js");
const require_unary = require("./unary.js");
exports.after = require_after.after;
exports.ary = require_ary.ary;
exports.asyncNoop = require_asyncNoop.asyncNoop;
exports.before = require_before.before;
exports.curry = require_curry.curry;
exports.curryRight = require_curryRight.curryRight;
exports.debounce = require_debounce.debounce;
exports.flow = require_flow.flow;
exports.flowRight = require_flowRight.flowRight;
exports.identity = require_identity.identity;
exports.memoize = require_memoize.memoize;
exports.negate = require_negate.negate;
exports.noop = require_noop.noop;
exports.once = require_once.once;
exports.partial = require_partial.partial;
exports.partialRight = require_partialRight.partialRight;
exports.rest = require_rest.rest;
exports.retry = require_retry.retry;
exports.spread = require_spread.spread;
exports.throttle = require_throttle.throttle;
exports.unary = require_unary.unary;

View file

@ -0,0 +1,22 @@
import { after } from "./after.mjs";
import { ary } from "./ary.mjs";
import { asyncNoop } from "./asyncNoop.mjs";
import { before } from "./before.mjs";
import { curry } from "./curry.mjs";
import { curryRight } from "./curryRight.mjs";
import { debounce } from "./debounce.mjs";
import { flow } from "./flow.mjs";
import { flowRight } from "./flowRight.mjs";
import { identity } from "./identity.mjs";
import { memoize } from "./memoize.mjs";
import { negate } from "./negate.mjs";
import { noop } from "./noop.mjs";
import { once } from "./once.mjs";
import { partial } from "./partial.mjs";
import { partialRight } from "./partialRight.mjs";
import { rest } from "./rest.mjs";
import { retry } from "./retry.mjs";
import { spread } from "./spread.mjs";
import { throttle } from "./throttle.mjs";
import { unary } from "./unary.mjs";
export { after, ary, asyncNoop, before, curry, curryRight, debounce, flow, flowRight, identity, memoize, negate, noop, once, partial, partialRight, rest, retry, spread, throttle, unary };

View file

@ -0,0 +1,125 @@
//#region src/function/memoize.d.ts
/**
* Creates a memoized version of the provided function. The memoized function caches
* results based on the argument it receives, so if the same argument is passed again,
* it returns the cached result instead of recomputing it.
*
* This function works with functions that take zero or just one argument. If your function
* originally takes multiple arguments, you should refactor it to take a single object or array
* that combines those arguments.
*
* If the argument is not primitive (e.g., arrays or objects), provide a
* `getCacheKey` function to generate a unique cache key for proper caching.
*
* @template F - The type of the function to be memoized.
* @param fn - The function to be memoized. It should accept a single argument and return a value.
* @param [options={}] - Optional configuration for the memoization.
* @param [options.cache] - The cache object used to store results. Defaults to a new `Map`.
* @param [options.getCacheKey] - An optional function to generate a unique cache key for each argument.
*
* @returns The memoized function with an additional `cache` property that exposes the internal cache.
*
* @example
* // Example using the default cache
* const add = (x: number) => x + 10;
* const memoizedAdd = memoize(add);
*
* console.log(memoizedAdd(5)); // 15
* console.log(memoizedAdd(5)); // 15 (cached result)
* console.log(memoizedAdd.cache.size); // 1
*
* @example
* // Example using a custom resolver
* const sum = (arr: number[]) => arr.reduce((x, y) => x + y, 0);
* const memoizedSum = memoize(sum, { getCacheKey: (arr: number[]) => arr.join(',') });
* console.log(memoizedSum([1, 2])); // 3
* console.log(memoizedSum([1, 2])); // 3 (cached result)
* console.log(memoizedSum.cache.size); // 1
*
* @example
* // Example using a custom cache implementation
* class CustomCache<K, T> implements MemoizeCache<K, T> {
* private cache = new Map<K, T>();
*
* set(key: K, value: T): void {
* this.cache.set(key, value);
* }
*
* get(key: K): T | undefined {
* return this.cache.get(key);
* }
*
* has(key: K): boolean {
* return this.cache.has(key);
* }
*
* delete(key: K): boolean {
* return this.cache.delete(key);
* }
*
* clear(): void {
* this.cache.clear();
* }
*
* get size(): number {
* return this.cache.size;
* }
* }
* const customCache = new CustomCache<string, number>();
* const memoizedSumWithCustomCache = memoize(sum, { cache: customCache });
* console.log(memoizedSumWithCustomCache([1, 2])); // 3
* console.log(memoizedSumWithCustomCache([1, 2])); // 3 (cached result)
* console.log(memoizedSumWithCustomCache.cache.size); // 1
*/
declare function memoize<F extends (...args: any) => any>(fn: F, options?: {
cache?: MemoizeCache<any, ReturnType<F>>;
getCacheKey?: (args: Parameters<F>[0]) => unknown;
}): F & {
cache: MemoizeCache<any, ReturnType<F>>;
};
/**
* Represents a cache for memoization, allowing storage and retrieval of computed values.
*
* @template K - The type of keys used to store values in the cache.
* @template V - The type of values stored in the cache.
*/
interface MemoizeCache<K, V> {
/**
* Stores a value in the cache with the specified key.
*
* @param key - The key to associate with the value.
* @param value - The value to store in the cache.
*/
set(key: K, value: V): void;
/**
* Retrieves a value from the cache by its key.
*
* @param key - The key of the value to retrieve.
* @returns The value associated with the key, or undefined if the key does not exist.
*/
get(key: K): V | undefined;
/**
* Checks if a value exists in the cache for the specified key.
*
* @param key - The key to check for existence in the cache.
* @returns True if the cache contains the key, false otherwise.
*/
has(key: K): boolean;
/**
* Deletes a value from the cache by its key.
*
* @param key - The key of the value to delete.
* @returns True if the value was successfully deleted, false otherwise.
*/
delete(key: K): boolean | void;
/**
* Clears all values from the cache.
*/
clear(): void;
/**
* The number of entries in the cache.
*/
size: number;
}
//#endregion
export { MemoizeCache, memoize };

View file

@ -0,0 +1,125 @@
//#region src/function/memoize.d.ts
/**
* Creates a memoized version of the provided function. The memoized function caches
* results based on the argument it receives, so if the same argument is passed again,
* it returns the cached result instead of recomputing it.
*
* This function works with functions that take zero or just one argument. If your function
* originally takes multiple arguments, you should refactor it to take a single object or array
* that combines those arguments.
*
* If the argument is not primitive (e.g., arrays or objects), provide a
* `getCacheKey` function to generate a unique cache key for proper caching.
*
* @template F - The type of the function to be memoized.
* @param fn - The function to be memoized. It should accept a single argument and return a value.
* @param [options={}] - Optional configuration for the memoization.
* @param [options.cache] - The cache object used to store results. Defaults to a new `Map`.
* @param [options.getCacheKey] - An optional function to generate a unique cache key for each argument.
*
* @returns The memoized function with an additional `cache` property that exposes the internal cache.
*
* @example
* // Example using the default cache
* const add = (x: number) => x + 10;
* const memoizedAdd = memoize(add);
*
* console.log(memoizedAdd(5)); // 15
* console.log(memoizedAdd(5)); // 15 (cached result)
* console.log(memoizedAdd.cache.size); // 1
*
* @example
* // Example using a custom resolver
* const sum = (arr: number[]) => arr.reduce((x, y) => x + y, 0);
* const memoizedSum = memoize(sum, { getCacheKey: (arr: number[]) => arr.join(',') });
* console.log(memoizedSum([1, 2])); // 3
* console.log(memoizedSum([1, 2])); // 3 (cached result)
* console.log(memoizedSum.cache.size); // 1
*
* @example
* // Example using a custom cache implementation
* class CustomCache<K, T> implements MemoizeCache<K, T> {
* private cache = new Map<K, T>();
*
* set(key: K, value: T): void {
* this.cache.set(key, value);
* }
*
* get(key: K): T | undefined {
* return this.cache.get(key);
* }
*
* has(key: K): boolean {
* return this.cache.has(key);
* }
*
* delete(key: K): boolean {
* return this.cache.delete(key);
* }
*
* clear(): void {
* this.cache.clear();
* }
*
* get size(): number {
* return this.cache.size;
* }
* }
* const customCache = new CustomCache<string, number>();
* const memoizedSumWithCustomCache = memoize(sum, { cache: customCache });
* console.log(memoizedSumWithCustomCache([1, 2])); // 3
* console.log(memoizedSumWithCustomCache([1, 2])); // 3 (cached result)
* console.log(memoizedSumWithCustomCache.cache.size); // 1
*/
declare function memoize<F extends (...args: any) => any>(fn: F, options?: {
cache?: MemoizeCache<any, ReturnType<F>>;
getCacheKey?: (args: Parameters<F>[0]) => unknown;
}): F & {
cache: MemoizeCache<any, ReturnType<F>>;
};
/**
* Represents a cache for memoization, allowing storage and retrieval of computed values.
*
* @template K - The type of keys used to store values in the cache.
* @template V - The type of values stored in the cache.
*/
interface MemoizeCache<K, V> {
/**
* Stores a value in the cache with the specified key.
*
* @param key - The key to associate with the value.
* @param value - The value to store in the cache.
*/
set(key: K, value: V): void;
/**
* Retrieves a value from the cache by its key.
*
* @param key - The key of the value to retrieve.
* @returns The value associated with the key, or undefined if the key does not exist.
*/
get(key: K): V | undefined;
/**
* Checks if a value exists in the cache for the specified key.
*
* @param key - The key to check for existence in the cache.
* @returns True if the cache contains the key, false otherwise.
*/
has(key: K): boolean;
/**
* Deletes a value from the cache by its key.
*
* @param key - The key of the value to delete.
* @returns True if the value was successfully deleted, false otherwise.
*/
delete(key: K): boolean | void;
/**
* Clears all values from the cache.
*/
clear(): void;
/**
* The number of entries in the cache.
*/
size: number;
}
//#endregion
export { MemoizeCache, memoize };

View file

@ -0,0 +1,87 @@
//#region src/function/memoize.ts
/**
* Creates a memoized version of the provided function. The memoized function caches
* results based on the argument it receives, so if the same argument is passed again,
* it returns the cached result instead of recomputing it.
*
* This function works with functions that take zero or just one argument. If your function
* originally takes multiple arguments, you should refactor it to take a single object or array
* that combines those arguments.
*
* If the argument is not primitive (e.g., arrays or objects), provide a
* `getCacheKey` function to generate a unique cache key for proper caching.
*
* @template F - The type of the function to be memoized.
* @param fn - The function to be memoized. It should accept a single argument and return a value.
* @param [options={}] - Optional configuration for the memoization.
* @param [options.cache] - The cache object used to store results. Defaults to a new `Map`.
* @param [options.getCacheKey] - An optional function to generate a unique cache key for each argument.
*
* @returns The memoized function with an additional `cache` property that exposes the internal cache.
*
* @example
* // Example using the default cache
* const add = (x: number) => x + 10;
* const memoizedAdd = memoize(add);
*
* console.log(memoizedAdd(5)); // 15
* console.log(memoizedAdd(5)); // 15 (cached result)
* console.log(memoizedAdd.cache.size); // 1
*
* @example
* // Example using a custom resolver
* const sum = (arr: number[]) => arr.reduce((x, y) => x + y, 0);
* const memoizedSum = memoize(sum, { getCacheKey: (arr: number[]) => arr.join(',') });
* console.log(memoizedSum([1, 2])); // 3
* console.log(memoizedSum([1, 2])); // 3 (cached result)
* console.log(memoizedSum.cache.size); // 1
*
* @example
* // Example using a custom cache implementation
* class CustomCache<K, T> implements MemoizeCache<K, T> {
* private cache = new Map<K, T>();
*
* set(key: K, value: T): void {
* this.cache.set(key, value);
* }
*
* get(key: K): T | undefined {
* return this.cache.get(key);
* }
*
* has(key: K): boolean {
* return this.cache.has(key);
* }
*
* delete(key: K): boolean {
* return this.cache.delete(key);
* }
*
* clear(): void {
* this.cache.clear();
* }
*
* get size(): number {
* return this.cache.size;
* }
* }
* const customCache = new CustomCache<string, number>();
* const memoizedSumWithCustomCache = memoize(sum, { cache: customCache });
* console.log(memoizedSumWithCustomCache([1, 2])); // 3
* console.log(memoizedSumWithCustomCache([1, 2])); // 3 (cached result)
* console.log(memoizedSumWithCustomCache.cache.size); // 1
*/
function memoize(fn, options = {}) {
const { cache = /* @__PURE__ */ new Map(), getCacheKey } = options;
const memoizedFn = function(arg) {
const key = getCacheKey ? getCacheKey(arg) : arg;
if (cache.has(key)) return cache.get(key);
const result = fn.call(this, arg);
cache.set(key, result);
return result;
};
memoizedFn.cache = cache;
return memoizedFn;
}
//#endregion
exports.memoize = memoize;

View file

@ -0,0 +1,87 @@
//#region src/function/memoize.ts
/**
* Creates a memoized version of the provided function. The memoized function caches
* results based on the argument it receives, so if the same argument is passed again,
* it returns the cached result instead of recomputing it.
*
* This function works with functions that take zero or just one argument. If your function
* originally takes multiple arguments, you should refactor it to take a single object or array
* that combines those arguments.
*
* If the argument is not primitive (e.g., arrays or objects), provide a
* `getCacheKey` function to generate a unique cache key for proper caching.
*
* @template F - The type of the function to be memoized.
* @param fn - The function to be memoized. It should accept a single argument and return a value.
* @param [options={}] - Optional configuration for the memoization.
* @param [options.cache] - The cache object used to store results. Defaults to a new `Map`.
* @param [options.getCacheKey] - An optional function to generate a unique cache key for each argument.
*
* @returns The memoized function with an additional `cache` property that exposes the internal cache.
*
* @example
* // Example using the default cache
* const add = (x: number) => x + 10;
* const memoizedAdd = memoize(add);
*
* console.log(memoizedAdd(5)); // 15
* console.log(memoizedAdd(5)); // 15 (cached result)
* console.log(memoizedAdd.cache.size); // 1
*
* @example
* // Example using a custom resolver
* const sum = (arr: number[]) => arr.reduce((x, y) => x + y, 0);
* const memoizedSum = memoize(sum, { getCacheKey: (arr: number[]) => arr.join(',') });
* console.log(memoizedSum([1, 2])); // 3
* console.log(memoizedSum([1, 2])); // 3 (cached result)
* console.log(memoizedSum.cache.size); // 1
*
* @example
* // Example using a custom cache implementation
* class CustomCache<K, T> implements MemoizeCache<K, T> {
* private cache = new Map<K, T>();
*
* set(key: K, value: T): void {
* this.cache.set(key, value);
* }
*
* get(key: K): T | undefined {
* return this.cache.get(key);
* }
*
* has(key: K): boolean {
* return this.cache.has(key);
* }
*
* delete(key: K): boolean {
* return this.cache.delete(key);
* }
*
* clear(): void {
* this.cache.clear();
* }
*
* get size(): number {
* return this.cache.size;
* }
* }
* const customCache = new CustomCache<string, number>();
* const memoizedSumWithCustomCache = memoize(sum, { cache: customCache });
* console.log(memoizedSumWithCustomCache([1, 2])); // 3
* console.log(memoizedSumWithCustomCache([1, 2])); // 3 (cached result)
* console.log(memoizedSumWithCustomCache.cache.size); // 1
*/
function memoize(fn, options = {}) {
const { cache = /* @__PURE__ */ new Map(), getCacheKey } = options;
const memoizedFn = function(arg) {
const key = getCacheKey ? getCacheKey(arg) : arg;
if (cache.has(key)) return cache.get(key);
const result = fn.call(this, arg);
cache.set(key, result);
return result;
};
memoizedFn.cache = cache;
return memoizedFn;
}
//#endregion
export { memoize };

View file

@ -0,0 +1,17 @@
//#region src/function/negate.d.ts
/**
* Creates a function that negates the result of the predicate function.
*
* @template F - The type of the function to negate.
* @param func - The function to negate.
* @returns The new negated function, which negates the boolean result of `func`.
*
* @example
* const array = [1, 2, 3, 4, 5, 6];
* const isEven = (n: number) => n % 2 === 0;
* const result = array.filter(negate(isEven));
* // result will be [1, 3, 5]
*/
declare function negate<F extends (...args: any[]) => boolean>(func: F): F;
//#endregion
export { negate };

View file

@ -0,0 +1,17 @@
//#region src/function/negate.d.ts
/**
* Creates a function that negates the result of the predicate function.
*
* @template F - The type of the function to negate.
* @param func - The function to negate.
* @returns The new negated function, which negates the boolean result of `func`.
*
* @example
* const array = [1, 2, 3, 4, 5, 6];
* const isEven = (n: number) => n % 2 === 0;
* const result = array.filter(negate(isEven));
* // result will be [1, 3, 5]
*/
declare function negate<F extends (...args: any[]) => boolean>(func: F): F;
//#endregion
export { negate };

View file

@ -0,0 +1,19 @@
//#region src/function/negate.ts
/**
* Creates a function that negates the result of the predicate function.
*
* @template F - The type of the function to negate.
* @param func - The function to negate.
* @returns The new negated function, which negates the boolean result of `func`.
*
* @example
* const array = [1, 2, 3, 4, 5, 6];
* const isEven = (n: number) => n % 2 === 0;
* const result = array.filter(negate(isEven));
* // result will be [1, 3, 5]
*/
function negate(func) {
return ((...args) => !func(...args));
}
//#endregion
exports.negate = negate;

View file

@ -0,0 +1,19 @@
//#region src/function/negate.ts
/**
* Creates a function that negates the result of the predicate function.
*
* @template F - The type of the function to negate.
* @param func - The function to negate.
* @returns The new negated function, which negates the boolean result of `func`.
*
* @example
* const array = [1, 2, 3, 4, 5, 6];
* const isEven = (n: number) => n % 2 === 0;
* const result = array.filter(negate(isEven));
* // result will be [1, 3, 5]
*/
function negate(func) {
return ((...args) => !func(...args));
}
//#endregion
export { negate };

View file

@ -0,0 +1,13 @@
//#region src/function/noop.d.ts
/**
* A no-operation function that does nothing.
* This can be used as a placeholder or default function.
*
* @example
* noop(); // Does nothing
*
* @returns This function does not return anything.
*/
declare function noop(): void;
//#endregion
export { noop };

View file

@ -0,0 +1,13 @@
//#region src/function/noop.d.ts
/**
* A no-operation function that does nothing.
* This can be used as a placeholder or default function.
*
* @example
* noop(); // Does nothing
*
* @returns This function does not return anything.
*/
declare function noop(): void;
//#endregion
export { noop };

13
frontend/node_modules/es-toolkit/dist/function/noop.js generated vendored Normal file
View file

@ -0,0 +1,13 @@
//#region src/function/noop.ts
/**
* A no-operation function that does nothing.
* This can be used as a placeholder or default function.
*
* @example
* noop(); // Does nothing
*
* @returns This function does not return anything.
*/
function noop() {}
//#endregion
exports.noop = noop;

View file

@ -0,0 +1,13 @@
//#region src/function/noop.ts
/**
* A no-operation function that does nothing.
* This can be used as a placeholder or default function.
*
* @example
* noop(); // Does nothing
*
* @returns This function does not return anything.
*/
function noop() {}
//#endregion
export { noop };

View file

@ -0,0 +1,18 @@
//#region src/function/once.d.ts
/**
* Creates a function that is restricted to invoking func once. Repeat calls to the function return the value of the first invocation.
*
* @template F - The type of the function.
* @param func - The function to restrict.
* @returns Returns the new restricted function.
*
* @example
* const initialize = once(createApplication);
*
* initialize();
* initialize();
* // => `createApplication` is invoked once
*/
declare function once<F extends (...args: any[]) => any>(func: F): F;
//#endregion
export { once };

View file

@ -0,0 +1,18 @@
//#region src/function/once.d.ts
/**
* Creates a function that is restricted to invoking func once. Repeat calls to the function return the value of the first invocation.
*
* @template F - The type of the function.
* @param func - The function to restrict.
* @returns Returns the new restricted function.
*
* @example
* const initialize = once(createApplication);
*
* initialize();
* initialize();
* // => `createApplication` is invoked once
*/
declare function once<F extends (...args: any[]) => any>(func: F): F;
//#endregion
export { once };

31
frontend/node_modules/es-toolkit/dist/function/once.js generated vendored Normal file
View file

@ -0,0 +1,31 @@
//#region src/function/once.ts
/**
* Creates a function that is restricted to invoking the provided function `func` once.
* Repeated calls to the function will return the value from the first invocation.
*
* @template F - The type of function.
* @param func - The function to restrict.
* @returns A new function that invokes `func` once and caches the result.
*
* @example
* const initialize = once(() => {
* console.log('Initialized!');
* return true;
* });
*
* initialize(); // Logs: 'Initialized!' and returns true
* initialize(); // Returns true without logging
*/
function once(func) {
let called = false;
let cache;
return function(...args) {
if (!called) {
called = true;
cache = func(...args);
}
return cache;
};
}
//#endregion
exports.once = once;

View file

@ -0,0 +1,31 @@
//#region src/function/once.ts
/**
* Creates a function that is restricted to invoking the provided function `func` once.
* Repeated calls to the function will return the value from the first invocation.
*
* @template F - The type of function.
* @param func - The function to restrict.
* @returns A new function that invokes `func` once and caches the result.
*
* @example
* const initialize = once(() => {
* console.log('Initialized!');
* return true;
* });
*
* initialize(); // Logs: 'Initialized!' and returns true
* initialize(); // Returns true without logging
*/
function once(func) {
let called = false;
let cache;
return function(...args) {
if (!called) {
called = true;
cache = func(...args);
}
return cache;
};
}
//#endregion
export { once };

View file

@ -0,0 +1,622 @@
//#region src/function/partial.d.ts
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @returns A new function that takes no arguments and returns the result of the original function.
*
* @example
* const addOne = (x: number) => x + 1;
* const addOneToFive = partial(addOne, 5);
* console.log(addOneToFive()); // => 6
*/
declare function partial<T1, R>(func: (arg1: T1) => R, arg1: T1): () => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @returns A new function that takes the second argument and returns the result of the original function.
*
* @example
* const multiply = (x: number, y: number) => x * y;
* const double = partial(multiply, 2);
* console.log(double(5)); // => 10
*/
declare function partial<T1, T2, R>(func: (arg1: T1, arg2: T2) => R, arg1: T1): (arg2: T2) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param placeholder The placeholder for the first argument.
* @param arg2 The second argument to apply.
* @returns A new function that takes the first argument and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
* const greetWithHello = partial(greet, partial.placeholder, 'John');
* console.log(greetWithHello('Hello')); // => 'Hello, John!'
*/
declare function partial<T1, T2, R>(func: (arg1: T1, arg2: T2) => R, placeholder: Placeholder, arg2: T2): (arg1: T1) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The second argument to apply.
* @returns A new function that takes no arguments and returns the result of the original function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const addThree = partial(add, 1, 2);
* console.log(addThree()); // => 3
*/
declare function partial<T1, T2, R>(func: (arg1: T1, arg2: T2) => R, arg1: T1, arg2: T2): () => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @returns A new function that takes the second and third arguments and returns the result of the original function.
*
* @example
* const sumThree = (a: number, b: number, c: number) => a + b + c;
* const addFive = partial(sumThree, 5);
* console.log(addFive(3, 2)); // => 10
*/
declare function partial<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1): (arg2: T2, arg3: T3) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The placeholder for the first argument.
* @param arg2 The second argument to apply.
* @returns A new function that takes the first and third arguments and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
* const greetWithPlaceholder = partial(greet, partial.placeholder, 'John');
* console.log(greetWithPlaceholder('Hello')); // => 'Hello, John!'
*/
declare function partial<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: Placeholder, arg2: T2): (arg1: T1, arg3: T3) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The placeholder for the first argument.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to apply.
* @returns A new function that takes the first and second arguments and returns the result of the original function.
*
* @example
* const multiply = (x: number, y: number, z: number) => x * y * z;
* const multiplyWithPlaceholders = partial(multiply, partial.placeholder, partial.placeholder, 2);
* console.log(multiplyWithPlaceholders(3, 4)); // => 24
*/
declare function partial<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: Placeholder, arg2: Placeholder, arg3: T3): (arg1: T1, arg2: T2) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to apply.
* @returns A new function that takes the second argument and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
* const greetWithPlaceholder = partial(greet, 'Hello', partial.placeholder);
* console.log(greetWithPlaceholder('John')); // => 'Hello, John!'
*/
declare function partial<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: Placeholder, arg3: T3): (arg2: T2) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to apply.
* @returns A new function that takes the second argument and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
* const greetWithPlaceholder = partial(greet, 'Hello', partial.placeholder);
* console.log(greetWithPlaceholder('John')); // => 'Hello, John!'
*/
declare function partial<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, plc1: Placeholder, arg2: T2, arg3: T3): (arg1: T1) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The second argument to apply.
* @param arg3 The third argument to apply.
* @returns A new function that takes no arguments and returns the result of the original function.
*
* @example
* const sum = (a: number, b: number, c: number) => a + b + c;
* const sumAll = partial(sum, 1, 2, 3);
* console.log(sumAll()); // => 6
*/
declare function partial<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: T2, arg3: T3): () => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @returns A new function that takes the second argument and returns the result of the original function.
*
* @example
* const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w;
* const double = partial(multiply, 2);
* console.log(double(5, 4, 3)); // => 120
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1): (arg2: T2, arg3: T3, arg4: T4) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The placeholder for the first argument.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the first and second arguments and returns the result of the original function.
*
* @example
* const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w;
* const multiplyWithPlaceholders = partial(multiply, partial.placeholder, partial.placeholder, 2, 3);
* console.log(multiplyWithPlaceholders(4, 5)); // => 120
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: Placeholder, arg2: Placeholder, arg3: T3, arg4: T4): (arg1: T1, arg2: T2) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The second argument to apply.
* @returns A new function that takes the third and fourth arguments and returns the result of the original function.
*
* @example
* const sumFour = (a: number, b: number, c: number, d: number) => a + b + c + d;
* const addOneAndTwo = partial(sumFour, 1, 2);
* console.log(addOneAndTwo(3, 4)); // => 10
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2): (arg3: T3, arg4: T4) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the second and fourth arguments and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`;
* const greetWithPlaceholder = partial(greet, 'Hello', partial.placeholder, '!');
* console.log(greetWithPlaceholder('John')); // => 'Hello, John!'
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: Placeholder, arg3: T3): (arg2: T2, arg4: T4) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The placeholder for the first argument.
* @param arg2 The second argument to apply.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the first and third arguments and returns the result of the original function.
*
* @example
* const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w;
* const multiplyWithPlaceholder = partial(multiply, partial.placeholder, 2, 3);
* console.log(multiplyWithPlaceholder(4)); // => 24
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: Placeholder, arg2: T2, arg3: T3): (arg1: T1, arg4: T4) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The placeholder for the first argument.
* @param arg2 The second argument to apply.
* @param arg3 The placeholder for the third argument.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the first and third arguments and returns the result of the original function.
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: Placeholder, arg2: T2, arg3: Placeholder, arg4: T4): (arg1: T1, arg3: T3) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The placeholder for the first argument.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the first and second arguments and returns the result of the original function.
*
* @example
* const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w;
* const multiplyWithPlaceholders = partial(multiply, partial.placeholder, partial.placeholder, 2, 3);
* console.log(multiplyWithPlaceholders(4, 5)); // => 120
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: Placeholder, arg2: Placeholder, arg3: T3, arg4: T4): (arg1: T1, arg2: T2) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The second argument to apply.
* @param arg3 The third argument to apply.
* @returns A new function that takes the fourth argument and returns the result of the original function.
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2, arg3: T3): (arg4: T4) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The second argument to apply.
* @param arg3 The placeholder for the third argument.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the third argument and returns the result of the original function.
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2, arg3: Placeholder, arg4: T4): (arg3: T3) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the second argument and returns the result of the original function.
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: Placeholder, arg3: T3, arg4: T4): (arg2: T2) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The placeholder for the first argument.
* @param arg2 The second argument to apply.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the first argument and returns the result of the original function.
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: Placeholder, arg2: T2, arg3: T3, arg4: T4): (arg1: T1) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The second argument to apply.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes no arguments and returns the result of the original function.
*
* @example
* const sumFour = (a: number, b: number, c: number, d: number) => a + b + c + d;
* const sumAll = partial(sumFour, 1, 2, 3, 4);
* console.log(sumAll()); // => 10
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2, arg3: T3, arg4: T4): () => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template TS The types of the arguments.
* @template R The return type of the function.
* @param func The function to partially apply.
* @returns A new function that takes the same arguments as the original function.
*
* @example
* const add = (...numbers: number[]) => numbers.reduce((sum, n) => sum + n, 0);
* const addFive = partial(add, 5);
* console.log(addFive(1, 2, 3)); // => 11
*/
declare function partial<TS extends any[], R>(func: (...args: TS) => R): (...args: TS) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template TS The types of the arguments.
* @template T1 The type of the first argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @returns A new function that takes the remaining arguments and returns the result of the original function.
*
* @example
* const greet = (greeting: string, ...names: string[]) => `${greeting}, ${names.join(', ')}!`;
* const greetHello = partial(greet, 'Hello');
* console.log(greetHello('Alice', 'Bob')); // => 'Hello, Alice, Bob!'
*/
declare function partial<TS extends any[], T1, R>(func: (arg1: T1, ...args: TS) => R, arg1: T1): (...args: TS) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template TS The types of the arguments.
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The second argument to apply.
* @returns A new function that takes the remaining arguments and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`;
* const greetWithHello = partial(greet, 'Hello', '!');
* console.log(greetWithHello('John')); // => 'Hello, John!'
*/
declare function partial<TS extends any[], T1, T2, R>(func: (arg1: T1, arg2: T2, ...args: TS) => R, t1: T1, arg2: T2): (...args: TS) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template TS The types of the arguments.
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param t1 The first argument to apply.
* @param arg2 The second argument to apply.
* @param arg3 The third argument to apply.
* @returns A new function that takes the remaining arguments and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`;
* const greetWithHello = partial(greet, 'Hello', 'John', '!');
* console.log(greetWithHello()); // => 'Hello, John!'
*/
declare function partial<TS extends any[], T1, T2, T3, R>(func: (t1: T1, arg2: T2, arg3: T3, ...args: TS) => R, t1: T1, arg2: T2, arg3: T3): (...args: TS) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template TS The types of the arguments.
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param t1 The first argument to apply.
* @param arg2 The second argument to apply.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the remaining arguments and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`;
* const greetWithHello = partial(greet, 'Hello', 'John', '!');
* console.log(greetWithHello()); // => 'Hello, John!'
*/
declare function partial<TS extends any[], T1, T2, T3, T4, R>(func: (t1: T1, arg2: T2, arg3: T3, arg4: T4, ...args: TS) => R, t1: T1, arg2: T2, arg3: T3, arg4: T4): (...args: TS) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template F The type of the function to partially apply.
* @param func The function to partially apply.
* @param partialArgs The arguments to be partially applied.
* @returns A new function that takes the remaining arguments and returns the result of the original function.
*
* @example
* const add = (...numbers: number[]) => numbers.reduce((sum, n) => sum + n, 0);
* const addFive = partial(add, 5);
* console.log(addFive(1, 2, 3)); // => 11
*/
declare function partial<F extends (...args: any[]) => any>(func: F, ...partialArgs: any[]): (...args: any[]) => ReturnType<F>;
declare namespace partial {
var placeholder: typeof placeholderSymbol;
}
declare function partialImpl<F extends (...args: any[]) => any, P>(func: F, placeholder: P, ...partialArgs: any[]): (...args: any[]) => ReturnType<F>;
declare const placeholderSymbol: unique symbol;
type Placeholder = typeof placeholderSymbol;
//#endregion
export { partial };

View file

@ -0,0 +1,622 @@
//#region src/function/partial.d.ts
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @returns A new function that takes no arguments and returns the result of the original function.
*
* @example
* const addOne = (x: number) => x + 1;
* const addOneToFive = partial(addOne, 5);
* console.log(addOneToFive()); // => 6
*/
declare function partial<T1, R>(func: (arg1: T1) => R, arg1: T1): () => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @returns A new function that takes the second argument and returns the result of the original function.
*
* @example
* const multiply = (x: number, y: number) => x * y;
* const double = partial(multiply, 2);
* console.log(double(5)); // => 10
*/
declare function partial<T1, T2, R>(func: (arg1: T1, arg2: T2) => R, arg1: T1): (arg2: T2) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param placeholder The placeholder for the first argument.
* @param arg2 The second argument to apply.
* @returns A new function that takes the first argument and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
* const greetWithHello = partial(greet, partial.placeholder, 'John');
* console.log(greetWithHello('Hello')); // => 'Hello, John!'
*/
declare function partial<T1, T2, R>(func: (arg1: T1, arg2: T2) => R, placeholder: Placeholder, arg2: T2): (arg1: T1) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The second argument to apply.
* @returns A new function that takes no arguments and returns the result of the original function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const addThree = partial(add, 1, 2);
* console.log(addThree()); // => 3
*/
declare function partial<T1, T2, R>(func: (arg1: T1, arg2: T2) => R, arg1: T1, arg2: T2): () => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @returns A new function that takes the second and third arguments and returns the result of the original function.
*
* @example
* const sumThree = (a: number, b: number, c: number) => a + b + c;
* const addFive = partial(sumThree, 5);
* console.log(addFive(3, 2)); // => 10
*/
declare function partial<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1): (arg2: T2, arg3: T3) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The placeholder for the first argument.
* @param arg2 The second argument to apply.
* @returns A new function that takes the first and third arguments and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
* const greetWithPlaceholder = partial(greet, partial.placeholder, 'John');
* console.log(greetWithPlaceholder('Hello')); // => 'Hello, John!'
*/
declare function partial<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: Placeholder, arg2: T2): (arg1: T1, arg3: T3) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The placeholder for the first argument.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to apply.
* @returns A new function that takes the first and second arguments and returns the result of the original function.
*
* @example
* const multiply = (x: number, y: number, z: number) => x * y * z;
* const multiplyWithPlaceholders = partial(multiply, partial.placeholder, partial.placeholder, 2);
* console.log(multiplyWithPlaceholders(3, 4)); // => 24
*/
declare function partial<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: Placeholder, arg2: Placeholder, arg3: T3): (arg1: T1, arg2: T2) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to apply.
* @returns A new function that takes the second argument and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
* const greetWithPlaceholder = partial(greet, 'Hello', partial.placeholder);
* console.log(greetWithPlaceholder('John')); // => 'Hello, John!'
*/
declare function partial<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: Placeholder, arg3: T3): (arg2: T2) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to apply.
* @returns A new function that takes the second argument and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
* const greetWithPlaceholder = partial(greet, 'Hello', partial.placeholder);
* console.log(greetWithPlaceholder('John')); // => 'Hello, John!'
*/
declare function partial<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, plc1: Placeholder, arg2: T2, arg3: T3): (arg1: T1) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The second argument to apply.
* @param arg3 The third argument to apply.
* @returns A new function that takes no arguments and returns the result of the original function.
*
* @example
* const sum = (a: number, b: number, c: number) => a + b + c;
* const sumAll = partial(sum, 1, 2, 3);
* console.log(sumAll()); // => 6
*/
declare function partial<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: T2, arg3: T3): () => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @returns A new function that takes the second argument and returns the result of the original function.
*
* @example
* const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w;
* const double = partial(multiply, 2);
* console.log(double(5, 4, 3)); // => 120
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1): (arg2: T2, arg3: T3, arg4: T4) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The placeholder for the first argument.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the first and second arguments and returns the result of the original function.
*
* @example
* const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w;
* const multiplyWithPlaceholders = partial(multiply, partial.placeholder, partial.placeholder, 2, 3);
* console.log(multiplyWithPlaceholders(4, 5)); // => 120
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: Placeholder, arg2: Placeholder, arg3: T3, arg4: T4): (arg1: T1, arg2: T2) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The second argument to apply.
* @returns A new function that takes the third and fourth arguments and returns the result of the original function.
*
* @example
* const sumFour = (a: number, b: number, c: number, d: number) => a + b + c + d;
* const addOneAndTwo = partial(sumFour, 1, 2);
* console.log(addOneAndTwo(3, 4)); // => 10
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2): (arg3: T3, arg4: T4) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the second and fourth arguments and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`;
* const greetWithPlaceholder = partial(greet, 'Hello', partial.placeholder, '!');
* console.log(greetWithPlaceholder('John')); // => 'Hello, John!'
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: Placeholder, arg3: T3): (arg2: T2, arg4: T4) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The placeholder for the first argument.
* @param arg2 The second argument to apply.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the first and third arguments and returns the result of the original function.
*
* @example
* const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w;
* const multiplyWithPlaceholder = partial(multiply, partial.placeholder, 2, 3);
* console.log(multiplyWithPlaceholder(4)); // => 24
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: Placeholder, arg2: T2, arg3: T3): (arg1: T1, arg4: T4) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The placeholder for the first argument.
* @param arg2 The second argument to apply.
* @param arg3 The placeholder for the third argument.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the first and third arguments and returns the result of the original function.
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: Placeholder, arg2: T2, arg3: Placeholder, arg4: T4): (arg1: T1, arg3: T3) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The placeholder for the first argument.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the first and second arguments and returns the result of the original function.
*
* @example
* const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w;
* const multiplyWithPlaceholders = partial(multiply, partial.placeholder, partial.placeholder, 2, 3);
* console.log(multiplyWithPlaceholders(4, 5)); // => 120
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: Placeholder, arg2: Placeholder, arg3: T3, arg4: T4): (arg1: T1, arg2: T2) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The second argument to apply.
* @param arg3 The third argument to apply.
* @returns A new function that takes the fourth argument and returns the result of the original function.
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2, arg3: T3): (arg4: T4) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The second argument to apply.
* @param arg3 The placeholder for the third argument.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the third argument and returns the result of the original function.
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2, arg3: Placeholder, arg4: T4): (arg3: T3) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the second argument and returns the result of the original function.
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: Placeholder, arg3: T3, arg4: T4): (arg2: T2) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The placeholder for the first argument.
* @param arg2 The second argument to apply.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the first argument and returns the result of the original function.
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: Placeholder, arg2: T2, arg3: T3, arg4: T4): (arg1: T1) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The second argument to apply.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes no arguments and returns the result of the original function.
*
* @example
* const sumFour = (a: number, b: number, c: number, d: number) => a + b + c + d;
* const sumAll = partial(sumFour, 1, 2, 3, 4);
* console.log(sumAll()); // => 10
*/
declare function partial<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2, arg3: T3, arg4: T4): () => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template TS The types of the arguments.
* @template R The return type of the function.
* @param func The function to partially apply.
* @returns A new function that takes the same arguments as the original function.
*
* @example
* const add = (...numbers: number[]) => numbers.reduce((sum, n) => sum + n, 0);
* const addFive = partial(add, 5);
* console.log(addFive(1, 2, 3)); // => 11
*/
declare function partial<TS extends any[], R>(func: (...args: TS) => R): (...args: TS) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template TS The types of the arguments.
* @template T1 The type of the first argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @returns A new function that takes the remaining arguments and returns the result of the original function.
*
* @example
* const greet = (greeting: string, ...names: string[]) => `${greeting}, ${names.join(', ')}!`;
* const greetHello = partial(greet, 'Hello');
* console.log(greetHello('Alice', 'Bob')); // => 'Hello, Alice, Bob!'
*/
declare function partial<TS extends any[], T1, R>(func: (arg1: T1, ...args: TS) => R, arg1: T1): (...args: TS) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template TS The types of the arguments.
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param arg1 The first argument to apply.
* @param arg2 The second argument to apply.
* @returns A new function that takes the remaining arguments and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`;
* const greetWithHello = partial(greet, 'Hello', '!');
* console.log(greetWithHello('John')); // => 'Hello, John!'
*/
declare function partial<TS extends any[], T1, T2, R>(func: (arg1: T1, arg2: T2, ...args: TS) => R, t1: T1, arg2: T2): (...args: TS) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template TS The types of the arguments.
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param t1 The first argument to apply.
* @param arg2 The second argument to apply.
* @param arg3 The third argument to apply.
* @returns A new function that takes the remaining arguments and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`;
* const greetWithHello = partial(greet, 'Hello', 'John', '!');
* console.log(greetWithHello()); // => 'Hello, John!'
*/
declare function partial<TS extends any[], T1, T2, T3, R>(func: (t1: T1, arg2: T2, arg3: T3, ...args: TS) => R, t1: T1, arg2: T2, arg3: T3): (...args: TS) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template TS The types of the arguments.
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply.
* @param t1 The first argument to apply.
* @param arg2 The second argument to apply.
* @param arg3 The third argument to apply.
* @param arg4 The fourth argument to apply.
* @returns A new function that takes the remaining arguments and returns the result of the original function.
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`;
* const greetWithHello = partial(greet, 'Hello', 'John', '!');
* console.log(greetWithHello()); // => 'Hello, John!'
*/
declare function partial<TS extends any[], T1, T2, T3, T4, R>(func: (t1: T1, arg2: T2, arg3: T3, arg4: T4, ...args: TS) => R, t1: T1, arg2: T2, arg3: T3, arg4: T4): (...args: TS) => R;
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template F The type of the function to partially apply.
* @param func The function to partially apply.
* @param partialArgs The arguments to be partially applied.
* @returns A new function that takes the remaining arguments and returns the result of the original function.
*
* @example
* const add = (...numbers: number[]) => numbers.reduce((sum, n) => sum + n, 0);
* const addFive = partial(add, 5);
* console.log(addFive(1, 2, 3)); // => 11
*/
declare function partial<F extends (...args: any[]) => any>(func: F, ...partialArgs: any[]): (...args: any[]) => ReturnType<F>;
declare namespace partial {
var placeholder: typeof placeholderSymbol;
}
declare function partialImpl<F extends (...args: any[]) => any, P>(func: F, placeholder: P, ...partialArgs: any[]): (...args: any[]) => ReturnType<F>;
declare const placeholderSymbol: unique symbol;
type Placeholder = typeof placeholderSymbol;
//#endregion
export { partial };

View file

@ -0,0 +1,45 @@
//#region src/function/partial.ts
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template F The type of the function to partially apply.
* @param func The function to partially apply arguments to.
* @param partialArgs The arguments to be partially applied.
* @returns Returns the new partially applied function.
*
* @example
* function greet(greeting, name) {
* return greeting + ' ' + name;
* }
*
* const sayHelloTo = partial(greet, 'hello');
* sayHelloTo('fred');
* // => 'hello fred'
*
* // Partially applied with placeholders.
* const greetFred = partial(greet, partial.placeholder, 'fred');
* greetFred('hi');
* // => 'hi fred'
*/
function partial(func, ...partialArgs) {
return partialImpl(func, placeholderSymbol, ...partialArgs);
}
function partialImpl(func, placeholder, ...partialArgs) {
const partialed = function(...providedArgs) {
let providedArgsIndex = 0;
const substitutedArgs = partialArgs.slice().map((arg) => arg === placeholder ? providedArgs[providedArgsIndex++] : arg);
const remainingArgs = providedArgs.slice(providedArgsIndex);
return func.apply(this, substitutedArgs.concat(remainingArgs));
};
if (func.prototype) partialed.prototype = Object.create(func.prototype);
return partialed;
}
const placeholderSymbol = Symbol("partial.placeholder");
partial.placeholder = placeholderSymbol;
//#endregion
exports.partial = partial;
exports.partialImpl = partialImpl;

View file

@ -0,0 +1,44 @@
//#region src/function/partial.ts
/**
* Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
*
* The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template F The type of the function to partially apply.
* @param func The function to partially apply arguments to.
* @param partialArgs The arguments to be partially applied.
* @returns Returns the new partially applied function.
*
* @example
* function greet(greeting, name) {
* return greeting + ' ' + name;
* }
*
* const sayHelloTo = partial(greet, 'hello');
* sayHelloTo('fred');
* // => 'hello fred'
*
* // Partially applied with placeholders.
* const greetFred = partial(greet, partial.placeholder, 'fred');
* greetFred('hi');
* // => 'hi fred'
*/
function partial(func, ...partialArgs) {
return partialImpl(func, placeholderSymbol, ...partialArgs);
}
function partialImpl(func, placeholder, ...partialArgs) {
const partialed = function(...providedArgs) {
let providedArgsIndex = 0;
const substitutedArgs = partialArgs.slice().map((arg) => arg === placeholder ? providedArgs[providedArgsIndex++] : arg);
const remainingArgs = providedArgs.slice(providedArgsIndex);
return func.apply(this, substitutedArgs.concat(remainingArgs));
};
if (func.prototype) partialed.prototype = Object.create(func.prototype);
return partialed;
}
const placeholderSymbol = Symbol("partial.placeholder");
partial.placeholder = placeholderSymbol;
//#endregion
export { partial, partialImpl };

View file

@ -0,0 +1,630 @@
//#region src/function/partialRight.d.ts
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template R The return type of the function.
* @param func The function to invoke.
* @returns Returns the new function.
* @example
* const getValue = () => 42;
* const getValueFunc = partialRight(getValue);
* console.log(getValueFunc()); // => 42
*/
declare function partialRight<R>(func: () => R): () => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const addOne = (num: number) => num + 1;
* const addOneFunc = partialRight(addOne, 1);
* console.log(addOneFunc()); // => 2
*/
declare function partialRight<T1, R>(func: (arg1: T1) => R, arg1: T1): () => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @returns Returns the new partially applied function.
* @example
* const multiplyBy = (factor: number) => (num: number) => num * factor;
* const double = partialRight(multiplyBy(2));
* console.log(double(5)); // => 10
*/
declare function partialRight<T1, R>(func: (arg1: T1) => R): (arg1: T1) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const greet = (name: string) => `Hello, ${name}!`;
* const greetJohn = partialRight(greet, 'John');
* console.log(greetJohn()); // => 'Hello, John!'
*/
declare function partialRight<T1, R>(func: (arg1: T1) => R, arg1: T1): () => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @returns Returns the new partially applied function.
* @example
* const subtract = (a: number, b: number) => a - b;
* const subtractFive = partialRight(subtract);
* console.log(subtractFive(10, 5)); // => 5
*/
declare function partialRight<T1, T2, R>(func: (arg1: T1, arg2: T2) => R): (arg1: T1, arg2: T2) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The placeholder for the second argument.
* @returns Returns the new partially applied function.
* @example
* const concat = (a: string, b: string) => a + b;
* const concatWithHello = partialRight(concat, 'Hello', partialRight.placeholder);
* console.log(concatWithHello(' World!')); // => 'Hello World!'
*/
declare function partialRight<T1, T2, R>(func: (arg1: T1, arg2: T2) => R, arg1: T1, arg2: Placeholder): (arg2: T2) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg2 The second argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const divide = (a: number, b: number) => a / b;
* const divideByTwo = partialRight(divide, 2);
* console.log(divideByTwo(10)); // => 5
*/
declare function partialRight<T1, T2, R>(func: (arg1: T1, arg2: T2) => R, arg2: T2): (arg1: T1) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The second argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const multiply = (a: number, b: number) => a * b;
* const multiplyByThreeAndFour = partialRight(multiply, 3, 4);
* console.log(multiplyByThreeAndFour()); // => 12
*/
declare function partialRight<T1, T2, R>(func: (arg1: T1, arg2: T2) => R, arg1: T1, arg2: T2): () => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @returns Returns the new partially applied function.
* @example
* const sumThree = (a: number, b: number, c: number) => a + b + c;
* const sumWithFive = partialRight(sumThree);
* console.log(sumWithFive(1, 2, 5)); // => 8
*/
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R): (arg1: T1, arg2: T2, arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The placeholder for the second argument.
* @param arg3 The placeholder for the third argument.
* @returns Returns the new partially applied function.
* @example
* const formatDate = (day: number, month: number, year: number) => `${day}/${month}/${year}`;
* const formatDateWithDay = partialRight(formatDate, 1, partialRight.placeholder, partialRight.placeholder);
* console.log(formatDateWithDay(12, 2023)); // => '1/12/2023'
*/
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: Placeholder, arg3: Placeholder): (arg2: T2, arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg2 The second argument to be partially applied.
* @param arg3 The placeholder for the third argument.
* @returns Returns the new partially applied function.
* @example
* const createUser = (name: string, age: number, country: string) => `${name}, ${age} years old from ${country}`;
* const createUserFromUSA = partialRight(createUser, 'USA', partialRight.placeholder);
* console.log(createUserFromUSA('John', 30)); // => 'John, 30 years old from USA'
*/
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg2: T2, arg3: Placeholder): (arg1: T1, arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The second argument to be partially applied.
* @param arg3 The placeholder for the third argument.
* @returns Returns the new partially applied function.
* @example
* const logMessage = (level: string, message: string, timestamp: string) => `[${level}] ${message} at ${timestamp}`;
* const logError = partialRight(logMessage, 'ERROR', '2023-10-01');
* console.log(logError('Something went wrong!')); // => '[ERROR] Something went wrong! at 2023-10-01'
*/
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: T2, arg3: Placeholder): (arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg3 The third argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const calculateArea = (length: number, width: number) => length * width;
* const calculateAreaWithWidth = partialRight(calculateArea, 5);
* console.log(calculateAreaWithWidth(10)); // => 50
*/
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg3: T3): (arg1: T1, arg2: T2) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const formatCurrency = (amount: number, currency: string) => `${amount} ${currency}`;
* const formatUSD = partialRight(formatCurrency, 100, partialRight.placeholder);
* console.log(formatUSD('USD')); // => '100 USD'
*/
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: Placeholder, arg3: T3): (arg2: T2) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg2 The second argument to be partially applied.
* @param arg3 The third argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const createProfile = (name: string, age: number, country: string) => `${name}, ${age} from ${country}`;
* const createProfileFromCanada = partialRight(createProfile, 'Canada', 'John');
* console.log(createProfileFromCanada(30)); // => 'John, 30 from Canada'
*/
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg2: T2, arg3: T3): (arg1: T1) => R;
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: T2, arg3: T3): () => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @returns Returns a new function that takes four arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The placeholder for the second argument.
* @param arg3 The placeholder for the third argument.
* @param arg4 The placeholder for the fourth argument.
* @returns Returns a new function that takes the second, third, and fourth arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: Placeholder, arg3: Placeholder, arg4: Placeholder): (arg2: T2, arg3: T3, arg4: T4) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg2 The second argument to be partially applied.
* @param arg3 The placeholder for the third argument.
* @param arg4 The placeholder for the fourth argument.
* @returns Returns a new function that takes the first, third, and fourth arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg2: T2, arg3: Placeholder, arg4: Placeholder): (arg1: T1, arg3: T3, arg4: T4) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The second argument to be partially applied.
* @param arg3 The placeholder for the third argument.
* @param arg4 The placeholder for the fourth argument.
* @returns Returns a new function that takes the third and fourth arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2, arg3: Placeholder, arg4: Placeholder): (arg3: T3, arg4: T4) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg3 The third argument to be partially applied.
* @param arg4 The placeholder for the fourth argument.
* @returns Returns a new function that takes the first, second, and fourth arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg3: T3, arg4: Placeholder): (arg1: T1, arg2: T2, arg4: T4) => R;
/**
* Creates a function that invokes `func` with the first argument, a placeholder for the second argument,
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to be partially applied.
* @param arg4 The placeholder for the fourth argument.
* @returns Returns a new function that takes the second and fourth arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: Placeholder, arg3: T3, arg4: Placeholder): (arg2: T2, arg4: T4) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg2 The second argument to be partially applied.
* @param arg3 The third argument to be partially applied.
* @param arg4 The placeholder for the fourth argument.
* @returns Returns a new function that takes the first and fourth arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg2: T2, arg3: T3, arg4: Placeholder): (arg1: T1, arg4: T4) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The second argument to be partially applied.
* @param arg3 The third argument to be partially applied.
* @param arg4 The placeholder for the fourth argument.
* @returns Returns a new function that takes the fourth argument.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2, arg3: T3, arg4: Placeholder): (arg4: T4) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns a new function that takes the first, second, and third arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg4: T4): (arg1: T1, arg2: T2, arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The placeholder for the second argument.
* @param arg3 The placeholder for the third argument.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns a new function that takes the second and third arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: Placeholder, arg3: Placeholder, arg4: T4): (arg2: T2, arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg2 The second argument to be partially applied.
* @param arg3 The placeholder for the third argument.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns a new function that takes the first and third arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg2: T2, arg3: Placeholder, arg4: T4): (arg1: T1, arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The second argument to be partially applied.
* @param arg3 The placeholder for the third argument.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns a new function that takes the third argument.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2, arg3: Placeholder, arg4: T4): (arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg3 The third argument to be partially applied.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns a new function that takes the first and second arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg3: T3, arg4: T4): (arg1: T1, arg2: T2) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to be partially applied.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns a new function that takes the second argument.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: Placeholder, arg3: T3, arg4: T4): (arg2: T2) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg2 The second argument to be partially applied.
* @param arg3 The third argument to be partially applied.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns a new function that takes the first argument.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg2: T2, arg3: T3, arg4: T4): (arg1: T1) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The second argument to be partially applied.
* @param arg3 The third argument to be partially applied.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const concatenate = (a: string, b: string, c: string, d: string) => a + b + c + d;
* const concatenateHelloWorld = partialRight(concatenate, 'Hello', ' ', 'World', '!');
* console.log(concatenateHelloWorld()); // => 'Hello World!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2, arg3: T3, arg4: T4): () => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template F The type of the function to partially apply.
* @param func The function to partially apply arguments to.
* @param args The arguments to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const log = (...messages: string[]) => console.log(...messages);
* const logError = partialRight(log, 'Error:');
* logError('Something went wrong!'); // => 'Error: Something went wrong!'
*/
declare function partialRight(func: (...args: any[]) => any, ...args: any[]): (...args: any[]) => any;
declare namespace partialRight {
var placeholder: typeof placeholderSymbol;
}
declare function partialRightImpl<F extends (...args: any[]) => any, P>(func: F, placeholder: P, ...partialArgs: any[]): (...args: any[]) => ReturnType<F>;
declare const placeholderSymbol: unique symbol;
type Placeholder = typeof placeholderSymbol;
//#endregion
export { partialRight };

View file

@ -0,0 +1,630 @@
//#region src/function/partialRight.d.ts
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template R The return type of the function.
* @param func The function to invoke.
* @returns Returns the new function.
* @example
* const getValue = () => 42;
* const getValueFunc = partialRight(getValue);
* console.log(getValueFunc()); // => 42
*/
declare function partialRight<R>(func: () => R): () => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const addOne = (num: number) => num + 1;
* const addOneFunc = partialRight(addOne, 1);
* console.log(addOneFunc()); // => 2
*/
declare function partialRight<T1, R>(func: (arg1: T1) => R, arg1: T1): () => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @returns Returns the new partially applied function.
* @example
* const multiplyBy = (factor: number) => (num: number) => num * factor;
* const double = partialRight(multiplyBy(2));
* console.log(double(5)); // => 10
*/
declare function partialRight<T1, R>(func: (arg1: T1) => R): (arg1: T1) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const greet = (name: string) => `Hello, ${name}!`;
* const greetJohn = partialRight(greet, 'John');
* console.log(greetJohn()); // => 'Hello, John!'
*/
declare function partialRight<T1, R>(func: (arg1: T1) => R, arg1: T1): () => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @returns Returns the new partially applied function.
* @example
* const subtract = (a: number, b: number) => a - b;
* const subtractFive = partialRight(subtract);
* console.log(subtractFive(10, 5)); // => 5
*/
declare function partialRight<T1, T2, R>(func: (arg1: T1, arg2: T2) => R): (arg1: T1, arg2: T2) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The placeholder for the second argument.
* @returns Returns the new partially applied function.
* @example
* const concat = (a: string, b: string) => a + b;
* const concatWithHello = partialRight(concat, 'Hello', partialRight.placeholder);
* console.log(concatWithHello(' World!')); // => 'Hello World!'
*/
declare function partialRight<T1, T2, R>(func: (arg1: T1, arg2: T2) => R, arg1: T1, arg2: Placeholder): (arg2: T2) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg2 The second argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const divide = (a: number, b: number) => a / b;
* const divideByTwo = partialRight(divide, 2);
* console.log(divideByTwo(10)); // => 5
*/
declare function partialRight<T1, T2, R>(func: (arg1: T1, arg2: T2) => R, arg2: T2): (arg1: T1) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The second argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const multiply = (a: number, b: number) => a * b;
* const multiplyByThreeAndFour = partialRight(multiply, 3, 4);
* console.log(multiplyByThreeAndFour()); // => 12
*/
declare function partialRight<T1, T2, R>(func: (arg1: T1, arg2: T2) => R, arg1: T1, arg2: T2): () => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @returns Returns the new partially applied function.
* @example
* const sumThree = (a: number, b: number, c: number) => a + b + c;
* const sumWithFive = partialRight(sumThree);
* console.log(sumWithFive(1, 2, 5)); // => 8
*/
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R): (arg1: T1, arg2: T2, arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The placeholder for the second argument.
* @param arg3 The placeholder for the third argument.
* @returns Returns the new partially applied function.
* @example
* const formatDate = (day: number, month: number, year: number) => `${day}/${month}/${year}`;
* const formatDateWithDay = partialRight(formatDate, 1, partialRight.placeholder, partialRight.placeholder);
* console.log(formatDateWithDay(12, 2023)); // => '1/12/2023'
*/
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: Placeholder, arg3: Placeholder): (arg2: T2, arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg2 The second argument to be partially applied.
* @param arg3 The placeholder for the third argument.
* @returns Returns the new partially applied function.
* @example
* const createUser = (name: string, age: number, country: string) => `${name}, ${age} years old from ${country}`;
* const createUserFromUSA = partialRight(createUser, 'USA', partialRight.placeholder);
* console.log(createUserFromUSA('John', 30)); // => 'John, 30 years old from USA'
*/
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg2: T2, arg3: Placeholder): (arg1: T1, arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The second argument to be partially applied.
* @param arg3 The placeholder for the third argument.
* @returns Returns the new partially applied function.
* @example
* const logMessage = (level: string, message: string, timestamp: string) => `[${level}] ${message} at ${timestamp}`;
* const logError = partialRight(logMessage, 'ERROR', '2023-10-01');
* console.log(logError('Something went wrong!')); // => '[ERROR] Something went wrong! at 2023-10-01'
*/
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: T2, arg3: Placeholder): (arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg3 The third argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const calculateArea = (length: number, width: number) => length * width;
* const calculateAreaWithWidth = partialRight(calculateArea, 5);
* console.log(calculateAreaWithWidth(10)); // => 50
*/
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg3: T3): (arg1: T1, arg2: T2) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const formatCurrency = (amount: number, currency: string) => `${amount} ${currency}`;
* const formatUSD = partialRight(formatCurrency, 100, partialRight.placeholder);
* console.log(formatUSD('USD')); // => '100 USD'
*/
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: Placeholder, arg3: T3): (arg2: T2) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg2 The second argument to be partially applied.
* @param arg3 The third argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const createProfile = (name: string, age: number, country: string) => `${name}, ${age} from ${country}`;
* const createProfileFromCanada = partialRight(createProfile, 'Canada', 'John');
* console.log(createProfileFromCanada(30)); // => 'John, 30 from Canada'
*/
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg2: T2, arg3: T3): (arg1: T1) => R;
declare function partialRight<T1, T2, T3, R>(func: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: T2, arg3: T3): () => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @returns Returns a new function that takes four arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The placeholder for the second argument.
* @param arg3 The placeholder for the third argument.
* @param arg4 The placeholder for the fourth argument.
* @returns Returns a new function that takes the second, third, and fourth arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: Placeholder, arg3: Placeholder, arg4: Placeholder): (arg2: T2, arg3: T3, arg4: T4) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg2 The second argument to be partially applied.
* @param arg3 The placeholder for the third argument.
* @param arg4 The placeholder for the fourth argument.
* @returns Returns a new function that takes the first, third, and fourth arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg2: T2, arg3: Placeholder, arg4: Placeholder): (arg1: T1, arg3: T3, arg4: T4) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The second argument to be partially applied.
* @param arg3 The placeholder for the third argument.
* @param arg4 The placeholder for the fourth argument.
* @returns Returns a new function that takes the third and fourth arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2, arg3: Placeholder, arg4: Placeholder): (arg3: T3, arg4: T4) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg3 The third argument to be partially applied.
* @param arg4 The placeholder for the fourth argument.
* @returns Returns a new function that takes the first, second, and fourth arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg3: T3, arg4: Placeholder): (arg1: T1, arg2: T2, arg4: T4) => R;
/**
* Creates a function that invokes `func` with the first argument, a placeholder for the second argument,
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to be partially applied.
* @param arg4 The placeholder for the fourth argument.
* @returns Returns a new function that takes the second and fourth arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: Placeholder, arg3: T3, arg4: Placeholder): (arg2: T2, arg4: T4) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg2 The second argument to be partially applied.
* @param arg3 The third argument to be partially applied.
* @param arg4 The placeholder for the fourth argument.
* @returns Returns a new function that takes the first and fourth arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg2: T2, arg3: T3, arg4: Placeholder): (arg1: T1, arg4: T4) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The second argument to be partially applied.
* @param arg3 The third argument to be partially applied.
* @param arg4 The placeholder for the fourth argument.
* @returns Returns a new function that takes the fourth argument.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2, arg3: T3, arg4: Placeholder): (arg4: T4) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns a new function that takes the first, second, and third arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg4: T4): (arg1: T1, arg2: T2, arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The placeholder for the second argument.
* @param arg3 The placeholder for the third argument.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns a new function that takes the second and third arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: Placeholder, arg3: Placeholder, arg4: T4): (arg2: T2, arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg2 The second argument to be partially applied.
* @param arg3 The placeholder for the third argument.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns a new function that takes the first and third arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg2: T2, arg3: Placeholder, arg4: T4): (arg1: T1, arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The second argument to be partially applied.
* @param arg3 The placeholder for the third argument.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns a new function that takes the third argument.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2, arg3: Placeholder, arg4: T4): (arg3: T3) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg3 The third argument to be partially applied.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns a new function that takes the first and second arguments.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg3: T3, arg4: T4): (arg1: T1, arg2: T2) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The placeholder for the second argument.
* @param arg3 The third argument to be partially applied.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns a new function that takes the second argument.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: Placeholder, arg3: T3, arg4: T4): (arg2: T2) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg2 The second argument to be partially applied.
* @param arg3 The third argument to be partially applied.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns a new function that takes the first argument.
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg2: T2, arg3: T3, arg4: T4): (arg1: T1) => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template T1 The type of the first argument.
* @template T2 The type of the second argument.
* @template T3 The type of the third argument.
* @template T4 The type of the fourth argument.
* @template R The return type of the function.
* @param func The function to partially apply arguments to.
* @param arg1 The first argument to be partially applied.
* @param arg2 The second argument to be partially applied.
* @param arg3 The third argument to be partially applied.
* @param arg4 The fourth argument to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const concatenate = (a: string, b: string, c: string, d: string) => a + b + c + d;
* const concatenateHelloWorld = partialRight(concatenate, 'Hello', ' ', 'World', '!');
* console.log(concatenateHelloWorld()); // => 'Hello World!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R, arg1: T1, arg2: T2, arg3: T3, arg4: T4): () => R;
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template F The type of the function to partially apply.
* @param func The function to partially apply arguments to.
* @param args The arguments to be partially applied.
* @returns Returns the new partially applied function.
* @example
* const log = (...messages: string[]) => console.log(...messages);
* const logError = partialRight(log, 'Error:');
* logError('Something went wrong!'); // => 'Error: Something went wrong!'
*/
declare function partialRight(func: (...args: any[]) => any, ...args: any[]): (...args: any[]) => any;
declare namespace partialRight {
var placeholder: typeof placeholderSymbol;
}
declare function partialRightImpl<F extends (...args: any[]) => any, P>(func: F, placeholder: P, ...partialArgs: any[]): (...args: any[]) => ReturnType<F>;
declare const placeholderSymbol: unique symbol;
type Placeholder = typeof placeholderSymbol;
//#endregion
export { partialRight };

View file

@ -0,0 +1,47 @@
//#region src/function/partialRight.ts
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template F The type of the function to partially apply.
* @param func The function to partially apply arguments to.
* @param partialArgs The arguments to be partially applied.
* @returns Returns the new partially applied function.
*
* @example
* function greet(greeting, name) {
* return greeting + ' ' + name;
* }
*
* const greetFred = partialRight(greet, 'fred');
* greetFred('hi');
* // => 'hi fred'
*
* // Partially applied with placeholders.
* const sayHelloTo = partialRight(greet, 'hello', partialRight.placeholder);
* sayHelloTo('fred');
* // => 'hello fred'
*/
function partialRight(func, ...partialArgs) {
return partialRightImpl(func, placeholderSymbol, ...partialArgs);
}
function partialRightImpl(func, placeholder, ...partialArgs) {
const partialedRight = function(...providedArgs) {
const placeholderLength = partialArgs.filter((arg) => arg === placeholder).length;
const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
const remainingArgs = providedArgs.slice(0, rangeLength);
let providedArgsIndex = rangeLength;
const substitutedArgs = partialArgs.slice().map((arg) => arg === placeholder ? providedArgs[providedArgsIndex++] : arg);
return func.apply(this, remainingArgs.concat(substitutedArgs));
};
if (func.prototype) partialedRight.prototype = Object.create(func.prototype);
return partialedRight;
}
const placeholderSymbol = Symbol("partialRight.placeholder");
partialRight.placeholder = placeholderSymbol;
//#endregion
exports.partialRight = partialRight;
exports.partialRightImpl = partialRightImpl;

View file

@ -0,0 +1,46 @@
//#region src/function/partialRight.ts
/**
* This method is like `partial` except that partially applied arguments are appended to the arguments it receives.
*
* The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: This method doesn't set the `length` property of partially applied functions.
*
* @template F The type of the function to partially apply.
* @param func The function to partially apply arguments to.
* @param partialArgs The arguments to be partially applied.
* @returns Returns the new partially applied function.
*
* @example
* function greet(greeting, name) {
* return greeting + ' ' + name;
* }
*
* const greetFred = partialRight(greet, 'fred');
* greetFred('hi');
* // => 'hi fred'
*
* // Partially applied with placeholders.
* const sayHelloTo = partialRight(greet, 'hello', partialRight.placeholder);
* sayHelloTo('fred');
* // => 'hello fred'
*/
function partialRight(func, ...partialArgs) {
return partialRightImpl(func, placeholderSymbol, ...partialArgs);
}
function partialRightImpl(func, placeholder, ...partialArgs) {
const partialedRight = function(...providedArgs) {
const placeholderLength = partialArgs.filter((arg) => arg === placeholder).length;
const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
const remainingArgs = providedArgs.slice(0, rangeLength);
let providedArgsIndex = rangeLength;
const substitutedArgs = partialArgs.slice().map((arg) => arg === placeholder ? providedArgs[providedArgsIndex++] : arg);
return func.apply(this, remainingArgs.concat(substitutedArgs));
};
if (func.prototype) partialedRight.prototype = Object.create(func.prototype);
return partialedRight;
}
const placeholderSymbol = Symbol("partialRight.placeholder");
partialRight.placeholder = placeholderSymbol;
//#endregion
export { partialRight, partialRightImpl };

View file

@ -0,0 +1,34 @@
//#region src/function/rest.d.ts
/**
* Creates a function that transforms the arguments of the provided function `func`.
* The transformed arguments are passed to `func` such that the arguments starting from a specified index
* are grouped into an array, while the previous arguments are passed as individual elements.
*
* @template F - The type of the function being transformed.
* @param func - The function whose arguments are to be transformed.
* @param [startIndex=func.length - 1] - The index from which to start grouping the remaining arguments into an array.
* Defaults to `func.length - 1`, grouping all arguments after the last parameter.
* @returns A new function that, when called, returns the result of calling `func` with the transformed arguments.
*
* The transformed arguments are:
* - The first `start` arguments as individual elements.
* - The remaining arguments from index `start` onward grouped into an array.
* @example
* function fn(a, b, c) {
* return [a, b, c];
* }
*
* // Using default start index (func.length - 1, which is 2 in this case)
* const transformedFn = rest(fn);
* console.log(transformedFn(1, 2, 3, 4)); // [1, 2, [3, 4]]
*
* // Using start index 1
* const transformedFnWithStart = rest(fn, 1);
* console.log(transformedFnWithStart(1, 2, 3, 4)); // [1, [2, 3, 4]]
*
* // With fewer arguments than the start index
* console.log(transformedFn(1)); // [1, undefined, []]
*/
declare function rest<F extends (...args: any[]) => any>(func: F, startIndex?: number): (...args: any[]) => ReturnType<F>;
//#endregion
export { rest };

View file

@ -0,0 +1,34 @@
//#region src/function/rest.d.ts
/**
* Creates a function that transforms the arguments of the provided function `func`.
* The transformed arguments are passed to `func` such that the arguments starting from a specified index
* are grouped into an array, while the previous arguments are passed as individual elements.
*
* @template F - The type of the function being transformed.
* @param func - The function whose arguments are to be transformed.
* @param [startIndex=func.length - 1] - The index from which to start grouping the remaining arguments into an array.
* Defaults to `func.length - 1`, grouping all arguments after the last parameter.
* @returns A new function that, when called, returns the result of calling `func` with the transformed arguments.
*
* The transformed arguments are:
* - The first `start` arguments as individual elements.
* - The remaining arguments from index `start` onward grouped into an array.
* @example
* function fn(a, b, c) {
* return [a, b, c];
* }
*
* // Using default start index (func.length - 1, which is 2 in this case)
* const transformedFn = rest(fn);
* console.log(transformedFn(1, 2, 3, 4)); // [1, 2, [3, 4]]
*
* // Using start index 1
* const transformedFnWithStart = rest(fn, 1);
* console.log(transformedFnWithStart(1, 2, 3, 4)); // [1, [2, 3, 4]]
*
* // With fewer arguments than the start index
* console.log(transformedFn(1)); // [1, undefined, []]
*/
declare function rest<F extends (...args: any[]) => any>(func: F, startIndex?: number): (...args: any[]) => ReturnType<F>;
//#endregion
export { rest };

41
frontend/node_modules/es-toolkit/dist/function/rest.js generated vendored Normal file
View file

@ -0,0 +1,41 @@
//#region src/function/rest.ts
/**
* Creates a function that transforms the arguments of the provided function `func`.
* The transformed arguments are passed to `func` such that the arguments starting from a specified index
* are grouped into an array, while the previous arguments are passed as individual elements.
*
* @template F - The type of the function being transformed.
* @param func - The function whose arguments are to be transformed.
* @param [startIndex=func.length - 1] - The index from which to start grouping the remaining arguments into an array.
* Defaults to `func.length - 1`, grouping all arguments after the last parameter.
* @returns A new function that, when called, returns the result of calling `func` with the transformed arguments.
*
* The transformed arguments are:
* - The first `start` arguments as individual elements.
* - The remaining arguments from index `start` onward grouped into an array.
* @example
* function fn(a, b, c) {
* return [a, b, c];
* }
*
* // Using default start index (func.length - 1, which is 2 in this case)
* const transformedFn = rest(fn);
* console.log(transformedFn(1, 2, 3, 4)); // [1, 2, [3, 4]]
*
* // Using start index 1
* const transformedFnWithStart = rest(fn, 1);
* console.log(transformedFnWithStart(1, 2, 3, 4)); // [1, [2, 3, 4]]
*
* // With fewer arguments than the start index
* console.log(transformedFn(1)); // [1, undefined, []]
*/
function rest(func, startIndex = func.length - 1) {
return function(...args) {
const rest = args.slice(startIndex);
const params = args.slice(0, startIndex);
while (params.length < startIndex) params.push(void 0);
return func.apply(this, [...params, rest]);
};
}
//#endregion
exports.rest = rest;

View file

@ -0,0 +1,41 @@
//#region src/function/rest.ts
/**
* Creates a function that transforms the arguments of the provided function `func`.
* The transformed arguments are passed to `func` such that the arguments starting from a specified index
* are grouped into an array, while the previous arguments are passed as individual elements.
*
* @template F - The type of the function being transformed.
* @param func - The function whose arguments are to be transformed.
* @param [startIndex=func.length - 1] - The index from which to start grouping the remaining arguments into an array.
* Defaults to `func.length - 1`, grouping all arguments after the last parameter.
* @returns A new function that, when called, returns the result of calling `func` with the transformed arguments.
*
* The transformed arguments are:
* - The first `start` arguments as individual elements.
* - The remaining arguments from index `start` onward grouped into an array.
* @example
* function fn(a, b, c) {
* return [a, b, c];
* }
*
* // Using default start index (func.length - 1, which is 2 in this case)
* const transformedFn = rest(fn);
* console.log(transformedFn(1, 2, 3, 4)); // [1, 2, [3, 4]]
*
* // Using start index 1
* const transformedFnWithStart = rest(fn, 1);
* console.log(transformedFnWithStart(1, 2, 3, 4)); // [1, [2, 3, 4]]
*
* // With fewer arguments than the start index
* console.log(transformedFn(1)); // [1, undefined, []]
*/
function rest(func, startIndex = func.length - 1) {
return function(...args) {
const rest = args.slice(startIndex);
const params = args.slice(0, startIndex);
while (params.length < startIndex) params.push(void 0);
return func.apply(this, [...params, rest]);
};
}
//#endregion
export { rest };

View file

@ -0,0 +1,91 @@
//#region src/function/retry.d.ts
interface RetryOptions {
/**
* Delay between retries. Can be a static number (milliseconds) or a function
* that computes delay dynamically based on the current attempt.
*
* @default 0
* @example
* delay: (attempts) => attempt * 50
*/
delay?: number | ((attempts: number) => number);
/**
* The number of retries to attempt.
* @default Number.POSITIVE_INFINITY
*/
retries?: number;
/**
* An AbortSignal to cancel the retry operation.
*/
signal?: AbortSignal;
/**
* A function that determines whether to retry based on the error and attempt number.
* If not provided, all errors will trigger a retry.
*
* @param error - The error that occurred.
* @param attempt - The current attempt number (0-indexed).
* @returns Whether to retry.
*
* @example
* shouldRetry: (error, attempt) => error.status >= 500
*/
shouldRetry?: (error: unknown, attempt: number) => boolean;
}
/**
* Retries a function that returns a promise until it resolves successfully.
*
* @template T
* @param func - The function to retry.
* @returns A promise that resolves with the value of the successful function call.
*
* @example
* // Basic usage with default retry options
* retry(() => fetchData()).then(data => console.log(data));
*/
declare function retry<T>(func: () => Promise<T>): Promise<T>;
/**
* Retries a function that returns a promise a specified number of times.
*
* @template T
* @param func - The function to retry. It should return a promise.
* @param retries - The number of retries to attempt. Default is Infinity.
* @returns A promise that resolves with the value of the successful function call.
*
* @example
* // Retry a function up to 3 times
* retry(() => fetchData(), 3).then(data => console.log(data));
*/
declare function retry<T>(func: () => Promise<T>, retries: number): Promise<T>;
/**
* Retries a function that returns a promise with specified options.
*
* @template T
* @param func - The function to retry. It should return a promise.
* @param options - Options to configure the retry behavior.
* @param [options.delay=0] - Delay(milliseconds) between retries.
* @param [options.retries=Infinity] - The number of retries to attempt.
* @param [options.signal] - An AbortSignal to cancel the retry operation.
* @param [options.shouldRetry] - A function that determines whether to retry.
* @returns A promise that resolves with the value of the successful function call.
*
* @example
* // Retry a function with a delay of 1000ms between attempts
* retry(() => fetchData(), { delay: 1000, times: 5 }).then(data => console.log(data));
*
* @example
* // Retry a function with a fixed delay
* retry(() => fetchData(), { delay: 1000, retries: 5 });
*
* // Retry a function with a delay increasing linearly by 50ms per attempt
* retry(() => fetchData(), { delay: (attempts) => attempt * 50, retries: 5 });
*
* @example
* // Retry a function with exponential backoff + jitter (max delay 10 seconds)
* retry(() => fetchData(), {
* delay: (attempts) => Math.min(Math.random() * 100 * 2 ** attempts, 10000),
* retries: 5
* });
*/
declare function retry<T>(func: () => Promise<T>, options: RetryOptions): Promise<T>;
//#endregion
export { retry };

View file

@ -0,0 +1,91 @@
//#region src/function/retry.d.ts
interface RetryOptions {
/**
* Delay between retries. Can be a static number (milliseconds) or a function
* that computes delay dynamically based on the current attempt.
*
* @default 0
* @example
* delay: (attempts) => attempt * 50
*/
delay?: number | ((attempts: number) => number);
/**
* The number of retries to attempt.
* @default Number.POSITIVE_INFINITY
*/
retries?: number;
/**
* An AbortSignal to cancel the retry operation.
*/
signal?: AbortSignal;
/**
* A function that determines whether to retry based on the error and attempt number.
* If not provided, all errors will trigger a retry.
*
* @param error - The error that occurred.
* @param attempt - The current attempt number (0-indexed).
* @returns Whether to retry.
*
* @example
* shouldRetry: (error, attempt) => error.status >= 500
*/
shouldRetry?: (error: unknown, attempt: number) => boolean;
}
/**
* Retries a function that returns a promise until it resolves successfully.
*
* @template T
* @param func - The function to retry.
* @returns A promise that resolves with the value of the successful function call.
*
* @example
* // Basic usage with default retry options
* retry(() => fetchData()).then(data => console.log(data));
*/
declare function retry<T>(func: () => Promise<T>): Promise<T>;
/**
* Retries a function that returns a promise a specified number of times.
*
* @template T
* @param func - The function to retry. It should return a promise.
* @param retries - The number of retries to attempt. Default is Infinity.
* @returns A promise that resolves with the value of the successful function call.
*
* @example
* // Retry a function up to 3 times
* retry(() => fetchData(), 3).then(data => console.log(data));
*/
declare function retry<T>(func: () => Promise<T>, retries: number): Promise<T>;
/**
* Retries a function that returns a promise with specified options.
*
* @template T
* @param func - The function to retry. It should return a promise.
* @param options - Options to configure the retry behavior.
* @param [options.delay=0] - Delay(milliseconds) between retries.
* @param [options.retries=Infinity] - The number of retries to attempt.
* @param [options.signal] - An AbortSignal to cancel the retry operation.
* @param [options.shouldRetry] - A function that determines whether to retry.
* @returns A promise that resolves with the value of the successful function call.
*
* @example
* // Retry a function with a delay of 1000ms between attempts
* retry(() => fetchData(), { delay: 1000, times: 5 }).then(data => console.log(data));
*
* @example
* // Retry a function with a fixed delay
* retry(() => fetchData(), { delay: 1000, retries: 5 });
*
* // Retry a function with a delay increasing linearly by 50ms per attempt
* retry(() => fetchData(), { delay: (attempts) => attempt * 50, retries: 5 });
*
* @example
* // Retry a function with exponential backoff + jitter (max delay 10 seconds)
* retry(() => fetchData(), {
* delay: (attempts) => Math.min(Math.random() * 100 * 2 ** attempts, 10000),
* retries: 5
* });
*/
declare function retry<T>(func: () => Promise<T>, options: RetryOptions): Promise<T>;
//#endregion
export { retry };

View file

@ -0,0 +1,45 @@
const require_delay = require("../promise/delay.js");
//#region src/function/retry.ts
const DEFAULT_DELAY = 0;
const DEFAULT_RETRIES = Number.POSITIVE_INFINITY;
const DEFAULT_SHOULD_RETRY = () => true;
/**
* Retries a function that returns a promise with specified options.
*
* @template T
* @param func - The function to retry. It should return a promise.
* @param [_options] - Either the number of retries or an options object.
* @returns A promise that resolves with the value of the successful function call.
*/
async function retry(func, _options) {
let delay$1;
let retries;
let signal;
let shouldRetry;
if (typeof _options === "number") {
delay$1 = DEFAULT_DELAY;
retries = _options;
signal = void 0;
shouldRetry = DEFAULT_SHOULD_RETRY;
} else {
delay$1 = _options?.delay ?? DEFAULT_DELAY;
retries = _options?.retries ?? DEFAULT_RETRIES;
signal = _options?.signal;
shouldRetry = _options?.shouldRetry ?? DEFAULT_SHOULD_RETRY;
}
let error;
for (let attempts = 0; attempts <= retries; attempts++) {
if (signal?.aborted) throw error ?? /* @__PURE__ */ new Error(`The retry operation was aborted due to an abort signal.`);
try {
return await func();
} catch (err) {
error = err;
if (!shouldRetry(err, attempts)) throw err;
const currentDelay = typeof delay$1 === "function" ? delay$1(attempts) : delay$1;
await require_delay.delay(currentDelay);
}
}
throw error;
}
//#endregion
exports.retry = retry;

View file

@ -0,0 +1,44 @@
import { delay } from "../promise/delay.mjs";
//#region src/function/retry.ts
const DEFAULT_DELAY = 0;
const DEFAULT_RETRIES = Number.POSITIVE_INFINITY;
const DEFAULT_SHOULD_RETRY = () => true;
/**
* Retries a function that returns a promise with specified options.
*
* @template T
* @param func - The function to retry. It should return a promise.
* @param [_options] - Either the number of retries or an options object.
* @returns A promise that resolves with the value of the successful function call.
*/
async function retry(func, _options) {
let delay$1;
let retries;
let signal;
let shouldRetry;
if (typeof _options === "number") {
delay$1 = DEFAULT_DELAY;
retries = _options;
signal = void 0;
shouldRetry = DEFAULT_SHOULD_RETRY;
} else {
delay$1 = _options?.delay ?? DEFAULT_DELAY;
retries = _options?.retries ?? DEFAULT_RETRIES;
signal = _options?.signal;
shouldRetry = _options?.shouldRetry ?? DEFAULT_SHOULD_RETRY;
}
let error;
for (let attempts = 0; attempts <= retries; attempts++) {
if (signal?.aborted) throw error ?? /* @__PURE__ */ new Error(`The retry operation was aborted due to an abort signal.`);
try {
return await func();
} catch (err) {
error = err;
if (!shouldRetry(err, attempts)) throw err;
await delay(typeof delay$1 === "function" ? delay$1(attempts) : delay$1);
}
}
throw error;
}
//#endregion
export { retry };

View file

@ -0,0 +1,20 @@
//#region src/function/spread.d.ts
/**
* Creates a new function that spreads elements of an array argument into individual arguments
* for the original function.
*
* @template F - A function type with any number of parameters and any return type.
* @param func - The function to be transformed. It can be any function with any number of arguments.
* @returns A new function that takes an array of arguments and returns the result of calling the original function with those arguments.
*
* @example
* function add(a, b) {
* return a + b;
* }
*
* const spreadAdd = spread(add);
* console.log(spreadAdd([1, 2])); // Output: 3
*/
declare function spread<F extends (...args: any[]) => any>(func: F): (argsArr: Parameters<F>) => ReturnType<F>;
//#endregion
export { spread };

View file

@ -0,0 +1,20 @@
//#region src/function/spread.d.ts
/**
* Creates a new function that spreads elements of an array argument into individual arguments
* for the original function.
*
* @template F - A function type with any number of parameters and any return type.
* @param func - The function to be transformed. It can be any function with any number of arguments.
* @returns A new function that takes an array of arguments and returns the result of calling the original function with those arguments.
*
* @example
* function add(a, b) {
* return a + b;
* }
*
* const spreadAdd = spread(add);
* console.log(spreadAdd([1, 2])); // Output: 3
*/
declare function spread<F extends (...args: any[]) => any>(func: F): (argsArr: Parameters<F>) => ReturnType<F>;
//#endregion
export { spread };

View file

@ -0,0 +1,24 @@
//#region src/function/spread.ts
/**
* Creates a new function that spreads elements of an array argument into individual arguments
* for the original function.
*
* @template F - A function type with any number of parameters and any return type.
* @param func - The function to be transformed. It can be any function with any number of arguments.
* @returns A new function that takes an array of arguments and returns the result of calling the original function with those arguments.
*
* @example
* function add(a, b) {
* return a + b;
* }
*
* const spreadAdd = spread(add);
* console.log(spreadAdd([1, 2])); // Output: 3
*/
function spread(func) {
return function(argsArr) {
return func.apply(this, argsArr);
};
}
//#endregion
exports.spread = spread;

View file

@ -0,0 +1,24 @@
//#region src/function/spread.ts
/**
* Creates a new function that spreads elements of an array argument into individual arguments
* for the original function.
*
* @template F - A function type with any number of parameters and any return type.
* @param func - The function to be transformed. It can be any function with any number of arguments.
* @returns A new function that takes an array of arguments and returns the result of calling the original function with those arguments.
*
* @example
* function add(a, b) {
* return a + b;
* }
*
* const spreadAdd = spread(add);
* console.log(spreadAdd([1, 2])); // Output: 3
*/
function spread(func) {
return function(argsArr) {
return func.apply(this, argsArr);
};
}
//#endregion
export { spread };

View file

@ -0,0 +1,52 @@
//#region src/function/throttle.d.ts
interface ThrottleOptions {
/**
* An optional AbortSignal to cancel the throttled function.
*/
signal?: AbortSignal;
/**
* An optional array specifying whether the function should be invoked on the leading edge, trailing edge, or both.
* If `edges` includes "leading", the function will be invoked at the start of the delay period.
* If `edges` includes "trailing", the function will be invoked at the end of the delay period.
* If both "leading" and "trailing" are included, the function will be invoked at both the start and end of the delay period.
* @default ["leading", "trailing"]
*/
edges?: Array<'leading' | 'trailing'>;
}
interface ThrottledFunction<F extends (...args: any[]) => void> {
(...args: Parameters<F>): void;
cancel: () => void;
flush: () => void;
}
/**
* Creates a throttled function that only invokes the provided function at most once
* per every `throttleMs` milliseconds. Subsequent calls to the throttled function
* within the wait time will not trigger the execution of the original function.
*
* @template F - The type of function.
* @param func - The function to throttle.
* @param throttleMs - The number of milliseconds to throttle executions to.
* @returns A new throttled function that accepts the same parameters as the original function.
*
* @example
* const throttledFunction = throttle(() => {
* console.log('Function executed');
* }, 1000);
*
* // Will log 'Function executed' immediately
* throttledFunction();
*
* // Will not log anything as it is within the throttle time
* throttledFunction();
*
* // After 1 second
* setTimeout(() => {
* throttledFunction(); // Will log 'Function executed'
* }, 1000);
*/
declare function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number, {
signal,
edges
}?: ThrottleOptions): ThrottledFunction<F>;
//#endregion
export { ThrottleOptions, ThrottledFunction, throttle };

View file

@ -0,0 +1,52 @@
//#region src/function/throttle.d.ts
interface ThrottleOptions {
/**
* An optional AbortSignal to cancel the throttled function.
*/
signal?: AbortSignal;
/**
* An optional array specifying whether the function should be invoked on the leading edge, trailing edge, or both.
* If `edges` includes "leading", the function will be invoked at the start of the delay period.
* If `edges` includes "trailing", the function will be invoked at the end of the delay period.
* If both "leading" and "trailing" are included, the function will be invoked at both the start and end of the delay period.
* @default ["leading", "trailing"]
*/
edges?: Array<'leading' | 'trailing'>;
}
interface ThrottledFunction<F extends (...args: any[]) => void> {
(...args: Parameters<F>): void;
cancel: () => void;
flush: () => void;
}
/**
* Creates a throttled function that only invokes the provided function at most once
* per every `throttleMs` milliseconds. Subsequent calls to the throttled function
* within the wait time will not trigger the execution of the original function.
*
* @template F - The type of function.
* @param func - The function to throttle.
* @param throttleMs - The number of milliseconds to throttle executions to.
* @returns A new throttled function that accepts the same parameters as the original function.
*
* @example
* const throttledFunction = throttle(() => {
* console.log('Function executed');
* }, 1000);
*
* // Will log 'Function executed' immediately
* throttledFunction();
*
* // Will not log anything as it is within the throttle time
* throttledFunction();
*
* // After 1 second
* setTimeout(() => {
* throttledFunction(); // Will log 'Function executed'
* }, 1000);
*/
declare function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number, {
signal,
edges
}?: ThrottleOptions): ThrottledFunction<F>;
//#endregion
export { ThrottleOptions, ThrottledFunction, throttle };

View file

@ -0,0 +1,54 @@
const require_debounce = require("./debounce.js");
//#region src/function/throttle.ts
/**
* Creates a throttled function that only invokes the provided function at most once
* per every `throttleMs` milliseconds. Subsequent calls to the throttled function
* within the wait time will not trigger the execution of the original function.
*
* @template F - The type of function.
* @param func - The function to throttle.
* @param throttleMs - The number of milliseconds to throttle executions to.
* @returns A new throttled function that accepts the same parameters as the original function.
*
* @example
* const throttledFunction = throttle(() => {
* console.log('Function executed');
* }, 1000);
*
* // Will log 'Function executed' immediately
* throttledFunction();
*
* // Will not log anything as it is within the throttle time
* throttledFunction();
*
* // After 1 second
* setTimeout(() => {
* throttledFunction(); // Will log 'Function executed'
* }, 1000);
*/
function throttle(func, throttleMs, { signal, edges = ["leading", "trailing"] } = {}) {
let pendingAt = null;
const debounced = require_debounce.debounce(function(...args) {
pendingAt = Date.now();
func.apply(this, args);
}, throttleMs, {
signal,
edges
});
const throttled = function(...args) {
if (pendingAt == null) pendingAt = Date.now();
if (Date.now() - pendingAt >= throttleMs) {
pendingAt = Date.now();
func.apply(this, args);
debounced.cancel();
debounced.schedule();
return;
}
debounced.apply(this, args);
};
throttled.cancel = debounced.cancel;
throttled.flush = debounced.flush;
return throttled;
}
//#endregion
exports.throttle = throttle;

View file

@ -0,0 +1,54 @@
import { debounce } from "./debounce.mjs";
//#region src/function/throttle.ts
/**
* Creates a throttled function that only invokes the provided function at most once
* per every `throttleMs` milliseconds. Subsequent calls to the throttled function
* within the wait time will not trigger the execution of the original function.
*
* @template F - The type of function.
* @param func - The function to throttle.
* @param throttleMs - The number of milliseconds to throttle executions to.
* @returns A new throttled function that accepts the same parameters as the original function.
*
* @example
* const throttledFunction = throttle(() => {
* console.log('Function executed');
* }, 1000);
*
* // Will log 'Function executed' immediately
* throttledFunction();
*
* // Will not log anything as it is within the throttle time
* throttledFunction();
*
* // After 1 second
* setTimeout(() => {
* throttledFunction(); // Will log 'Function executed'
* }, 1000);
*/
function throttle(func, throttleMs, { signal, edges = ["leading", "trailing"] } = {}) {
let pendingAt = null;
const debounced = debounce(function(...args) {
pendingAt = Date.now();
func.apply(this, args);
}, throttleMs, {
signal,
edges
});
const throttled = function(...args) {
if (pendingAt == null) pendingAt = Date.now();
if (Date.now() - pendingAt >= throttleMs) {
pendingAt = Date.now();
func.apply(this, args);
debounced.cancel();
debounced.schedule();
return;
}
debounced.apply(this, args);
};
throttled.cancel = debounced.cancel;
throttled.flush = debounced.flush;
return throttled;
}
//#endregion
export { throttle };

View file

@ -0,0 +1,18 @@
//#region src/function/unary.d.ts
/**
* Creates a function that accepts up to one argument, ignoring any additional arguments.
*
* @template F - The type of the function.
* @param func - The function to cap arguments for.
* @returns Returns the new capped function.
*
* @example
* function fn(a, b, c) {
* console.log(arguments);
* }
*
* unary(fn)(1, 2, 3); // [Arguments] { '0': 1 }
*/
declare function unary<F extends (...args: any[]) => any>(func: F): (...args: any[]) => ReturnType<F>;
//#endregion
export { unary };

View file

@ -0,0 +1,18 @@
//#region src/function/unary.d.ts
/**
* Creates a function that accepts up to one argument, ignoring any additional arguments.
*
* @template F - The type of the function.
* @param func - The function to cap arguments for.
* @returns Returns the new capped function.
*
* @example
* function fn(a, b, c) {
* console.log(arguments);
* }
*
* unary(fn)(1, 2, 3); // [Arguments] { '0': 1 }
*/
declare function unary<F extends (...args: any[]) => any>(func: F): (...args: any[]) => ReturnType<F>;
//#endregion
export { unary };

View file

@ -0,0 +1,21 @@
const require_ary = require("./ary.js");
//#region src/function/unary.ts
/**
* Creates a function that accepts up to one argument, ignoring any additional arguments.
*
* @template F - The type of the function.
* @param func - The function to cap arguments for.
* @returns Returns the new capped function.
*
* @example
* function fn(a, b, c) {
* console.log(arguments);
* }
*
* unary(fn)(1, 2, 3); // [Arguments] { '0': 1 }
*/
function unary(func) {
return require_ary.ary(func, 1);
}
//#endregion
exports.unary = unary;

View file

@ -0,0 +1,21 @@
import { ary } from "./ary.mjs";
//#region src/function/unary.ts
/**
* Creates a function that accepts up to one argument, ignoring any additional arguments.
*
* @template F - The type of the function.
* @param func - The function to cap arguments for.
* @returns Returns the new capped function.
*
* @example
* function fn(a, b, c) {
* console.log(arguments);
* }
*
* unary(fn)(1, 2, 3); // [Arguments] { '0': 1 }
*/
function unary(func) {
return ary(func, 1);
}
//#endregion
export { unary };