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,25 @@
//#region src/compat/function/after.d.ts
/**
* The opposite of `_.before`; this method creates a function that invokes
* `func` once it's called `n` or more times.
*
* @template TFunc - The type of the function to be invoked.
* @param n - The number of calls before `func` is invoked.
* @param func - The function to restrict.
* @returns Returns the new restricted function.
* @throws {TypeError} - If `func` is not a function.
*
* @example
* const saves = ['profile', 'settings'];
* const done = after(saves.length, () => {
* console.log('done saving!');
* });
*
* saves.forEach(type => {
* asyncSave({ 'type': type, 'complete': done });
* });
* // => Logs 'done saving!' after the two async saves have completed.
*/
declare function after<TFunc extends (...args: any[]) => any>(n: number, func: TFunc): TFunc;
//#endregion
export { after };

View file

@ -0,0 +1,25 @@
//#region src/compat/function/after.d.ts
/**
* The opposite of `_.before`; this method creates a function that invokes
* `func` once it's called `n` or more times.
*
* @template TFunc - The type of the function to be invoked.
* @param n - The number of calls before `func` is invoked.
* @param func - The function to restrict.
* @returns Returns the new restricted function.
* @throws {TypeError} - If `func` is not a function.
*
* @example
* const saves = ['profile', 'settings'];
* const done = after(saves.length, () => {
* console.log('done saving!');
* });
*
* saves.forEach(type => {
* asyncSave({ 'type': type, 'complete': done });
* });
* // => Logs 'done saving!' after the two async saves have completed.
*/
declare function after<TFunc extends (...args: any[]) => any>(n: number, func: TFunc): TFunc;
//#endregion
export { after };

View file

@ -0,0 +1,32 @@
const require_toInteger = require("../util/toInteger.js");
//#region src/compat/function/after.ts
/**
* The opposite of `_.before`; this method creates a function that invokes
* `func` once it's called `n` or more times.
*
* @template TFunc - The type of the function to be invoked.
* @param n - The number of calls before `func` is invoked.
* @param func - The function to restrict.
* @returns Returns the new restricted function.
* @throws {TypeError} - If `func` is not a function.
*
* @example
* const saves = ['profile', 'settings'];
* const done = after(saves.length, () => {
* console.log('done saving!');
* });
*
* saves.forEach(type => {
* asyncSave({ 'type': type, 'complete': done });
* });
* // => Logs 'done saving!' after the two async saves have completed.
*/
function after(n, func) {
if (typeof func !== "function") throw new TypeError("Expected a function");
n = require_toInteger.toInteger(n);
return function(...args) {
if (--n < 1) return func.apply(this, args);
};
}
//#endregion
exports.after = after;

View file

@ -0,0 +1,32 @@
import { toInteger } from "../util/toInteger.mjs";
//#region src/compat/function/after.ts
/**
* The opposite of `_.before`; this method creates a function that invokes
* `func` once it's called `n` or more times.
*
* @template TFunc - The type of the function to be invoked.
* @param n - The number of calls before `func` is invoked.
* @param func - The function to restrict.
* @returns Returns the new restricted function.
* @throws {TypeError} - If `func` is not a function.
*
* @example
* const saves = ['profile', 'settings'];
* const done = after(saves.length, () => {
* console.log('done saving!');
* });
*
* saves.forEach(type => {
* asyncSave({ 'type': type, 'complete': done });
* });
* // => Logs 'done saving!' after the two async saves have completed.
*/
function after(n, func) {
if (typeof func !== "function") throw new TypeError("Expected a function");
n = toInteger(n);
return function(...args) {
if (--n < 1) return func.apply(this, args);
};
}
//#endregion
export { after };

View file

@ -0,0 +1,25 @@
//#region src/compat/function/ary.d.ts
/**
* Creates a function that invokes func, with up to `n` arguments, ignoring any additional arguments.
* If `n` is not provided, it defaults to the function's length.
*
* @param func - The function to cap arguments for.
* @param [n] - The arity cap. Defaults to func.length.
* @returns Returns the new capped function.
*
* @example
* function fn(a: number, b: number, c: number) {
* return Array.from(arguments);
* }
*
* // Cap at 2 arguments
* const capped = ary(fn, 2);
* capped(1, 2, 3); // [1, 2]
*
* // Default to function length
* const defaultCap = ary(fn);
* defaultCap(1, 2, 3); // [1, 2, 3]
*/
declare function ary(func: (...args: any[]) => any, n?: number): (...args: any[]) => any;
//#endregion
export { ary };

View file

@ -0,0 +1,25 @@
//#region src/compat/function/ary.d.ts
/**
* Creates a function that invokes func, with up to `n` arguments, ignoring any additional arguments.
* If `n` is not provided, it defaults to the function's length.
*
* @param func - The function to cap arguments for.
* @param [n] - The arity cap. Defaults to func.length.
* @returns Returns the new capped function.
*
* @example
* function fn(a: number, b: number, c: number) {
* return Array.from(arguments);
* }
*
* // Cap at 2 arguments
* const capped = ary(fn, 2);
* capped(1, 2, 3); // [1, 2]
*
* // Default to function length
* const defaultCap = ary(fn);
* defaultCap(1, 2, 3); // [1, 2, 3]
*/
declare function ary(func: (...args: any[]) => any, n?: number): (...args: any[]) => any;
//#endregion
export { ary };

View file

@ -0,0 +1,28 @@
const require_ary = require("../../function/ary.js");
//#region src/compat/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.
* @param guard - The value to guard 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 = func.length, guard) {
if (guard) n = func.length;
if (Number.isNaN(n) || n < 0) n = 0;
return require_ary.ary(func, n);
}
//#endregion
exports.ary = ary;

View file

@ -0,0 +1,28 @@
import { ary as ary$1 } from "../../function/ary.mjs";
//#region src/compat/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.
* @param guard - The value to guard 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 = func.length, guard) {
if (guard) n = func.length;
if (Number.isNaN(n) || n < 0) n = 0;
return ary$1(func, n);
}
//#endregion
export { ary };

View file

@ -0,0 +1,34 @@
//#region src/compat/function/attempt.d.ts
/**
* Attempts to execute a function with the provided arguments.
* If the function throws an error, it catches the error and returns it.
* If the caught error is not an instance of Error, it wraps it in a new Error.
*
* @param func - The function to be executed.
* @param args - The arguments to pass to the function.
* @returns The return value of the function if successful, or an Error if an exception is thrown.
*
* @template R - The type of the function return value.
*
* @example
* // Example 1: Successful execution
* const result = attempt((x, y) => x + y, 2, 3);
* console.log(result); // Output: 5
*
* @example
* // Example 2: Function throws an error
* const errorResult = attempt(() => {
* throw new Error("Something went wrong");
* });
* console.log(errorResult); // Output: Error: Something went wrong
*
* @example
* // Example 3: Non-Error thrown
* const nonErrorResult = attempt(() => {
* throw "This is a string error";
* });
* console.log(nonErrorResult); // Output: Error: This is a string error
*/
declare function attempt<R>(func: (...args: any[]) => R, ...args: any[]): R | Error;
//#endregion
export { attempt };

View file

@ -0,0 +1,34 @@
//#region src/compat/function/attempt.d.ts
/**
* Attempts to execute a function with the provided arguments.
* If the function throws an error, it catches the error and returns it.
* If the caught error is not an instance of Error, it wraps it in a new Error.
*
* @param func - The function to be executed.
* @param args - The arguments to pass to the function.
* @returns The return value of the function if successful, or an Error if an exception is thrown.
*
* @template R - The type of the function return value.
*
* @example
* // Example 1: Successful execution
* const result = attempt((x, y) => x + y, 2, 3);
* console.log(result); // Output: 5
*
* @example
* // Example 2: Function throws an error
* const errorResult = attempt(() => {
* throw new Error("Something went wrong");
* });
* console.log(errorResult); // Output: Error: Something went wrong
*
* @example
* // Example 3: Non-Error thrown
* const nonErrorResult = attempt(() => {
* throw "This is a string error";
* });
* console.log(nonErrorResult); // Output: Error: This is a string error
*/
declare function attempt<R>(func: (...args: any[]) => R, ...args: any[]): R | Error;
//#endregion
export { attempt };

View file

@ -0,0 +1,40 @@
//#region src/compat/function/attempt.ts
/**
* Attempts to execute a function with the provided arguments.
* If the function throws an error, it catches the error and returns it.
* If the caught error is not an instance of Error, it wraps it in a new Error.
*
* @param func - The function to be executed.
* @param args - The arguments to pass to the function.
* @returns The return value of the function if successful, or an Error if an exception is thrown.
*
* @template R - The type of the function return value.
*
* @example
* // Example 1: Successful execution
* const result = attempt((x, y) => x + y, 2, 3);
* console.log(result); // Output: 5
*
* @example
* // Example 2: Function throws an error
* const errorResult = attempt(() => {
* throw new Error("Something went wrong");
* });
* console.log(errorResult); // Output: Error: Something went wrong
*
* @example
* // Example 3: Non-Error thrown
* const nonErrorResult = attempt(() => {
* throw "This is a string error";
* });
* console.log(nonErrorResult); // Output: Error: This is a string error
*/
function attempt(func, ...args) {
try {
return func(...args);
} catch (e) {
return e instanceof Error ? e : new Error(e);
}
}
//#endregion
exports.attempt = attempt;

View file

@ -0,0 +1,40 @@
//#region src/compat/function/attempt.ts
/**
* Attempts to execute a function with the provided arguments.
* If the function throws an error, it catches the error and returns it.
* If the caught error is not an instance of Error, it wraps it in a new Error.
*
* @param func - The function to be executed.
* @param args - The arguments to pass to the function.
* @returns The return value of the function if successful, or an Error if an exception is thrown.
*
* @template R - The type of the function return value.
*
* @example
* // Example 1: Successful execution
* const result = attempt((x, y) => x + y, 2, 3);
* console.log(result); // Output: 5
*
* @example
* // Example 2: Function throws an error
* const errorResult = attempt(() => {
* throw new Error("Something went wrong");
* });
* console.log(errorResult); // Output: Error: Something went wrong
*
* @example
* // Example 3: Non-Error thrown
* const nonErrorResult = attempt(() => {
* throw "This is a string error";
* });
* console.log(nonErrorResult); // Output: Error: This is a string error
*/
function attempt(func, ...args) {
try {
return func(...args);
} catch (e) {
return e instanceof Error ? e : new Error(e);
}
}
//#endregion
export { attempt };

View file

@ -0,0 +1,27 @@
//#region src/compat/function/before.d.ts
/**
* Creates a function that invokes `func`, with the `this` binding and arguments
* of the created function, while it's called less than `n` times. Subsequent
* calls to the created function return the result of the last `func` invocation.
*
* @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 last result of `func`, if `n` is reached.
* @throws {TypeError} - If `func` is not a function.
* @example
* let count = 0;
* const before3 = before(3, () => ++count);
*
* before3(); // => 1
* before3(); // => 2
* before3(); // => 2
*/
declare function before<F extends (...args: any[]) => any>(n: number, func: F): F;
//#endregion
export { before };

View file

@ -0,0 +1,27 @@
//#region src/compat/function/before.d.ts
/**
* Creates a function that invokes `func`, with the `this` binding and arguments
* of the created function, while it's called less than `n` times. Subsequent
* calls to the created function return the result of the last `func` invocation.
*
* @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 last result of `func`, if `n` is reached.
* @throws {TypeError} - If `func` is not a function.
* @example
* let count = 0;
* const before3 = before(3, () => ++count);
*
* before3(); // => 1
* before3(); // => 2
* before3(); // => 2
*/
declare function before<F extends (...args: any[]) => any>(n: number, func: F): F;
//#endregion
export { before };

View file

@ -0,0 +1,37 @@
const require_toInteger = require("../util/toInteger.js");
//#region src/compat/function/before.ts
/**
* Creates a function that invokes `func`, with the `this` binding and arguments
* of the created function, while it's called less than `n` times. Subsequent
* calls to the created function return the result of the last `func` invocation.
*
* @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 last result of `func`, if `n` is reached.
* @throws {TypeError} - If `func` is not a function.
* @example
* let count = 0;
* const before3 = before(3, () => ++count);
*
* before3(); // => 1
* before3(); // => 2
* before3(); // => 2
*/
function before(n, func) {
if (typeof func !== "function") throw new TypeError("Expected a function");
let result;
n = require_toInteger.toInteger(n);
return function(...args) {
if (--n > 0) result = func.apply(this, args);
if (n <= 1 && func) func = void 0;
return result;
};
}
//#endregion
exports.before = before;

View file

@ -0,0 +1,37 @@
import { toInteger } from "../util/toInteger.mjs";
//#region src/compat/function/before.ts
/**
* Creates a function that invokes `func`, with the `this` binding and arguments
* of the created function, while it's called less than `n` times. Subsequent
* calls to the created function return the result of the last `func` invocation.
*
* @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 last result of `func`, if `n` is reached.
* @throws {TypeError} - If `func` is not a function.
* @example
* let count = 0;
* const before3 = before(3, () => ++count);
*
* before3(); // => 1
* before3(); // => 2
* before3(); // => 2
*/
function before(n, func) {
if (typeof func !== "function") throw new TypeError("Expected a function");
let result;
n = toInteger(n);
return function(...args) {
if (--n > 0) result = func.apply(this, args);
if (n <= 1 && func) func = void 0;
return result;
};
}
//#endregion
export { before };

View file

@ -0,0 +1,33 @@
//#region src/compat/function/bind.d.ts
/**
* Creates a function that invokes `func` with the `this` binding of `thisArg` and `partials` prepended to the arguments it receives.
*
* The `bind.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: Unlike native `Function#bind`, this method doesn't set the `length` property of bound functions.
*
* @param func - The function to bind.
* @param thisObj - The `this` binding of `func`.
* @param partialArgs - The arguments to be partially applied.
* @returns Returns the new bound function.
*
* @example
* function greet(greeting, punctuation) {
* return greeting + ' ' + this.user + punctuation;
* }
* const object = { user: 'fred' };
* let bound = bind(greet, object, 'hi');
* bound('!');
* // => 'hi fred!'
*
* bound = bind(greet, object, bind.placeholder, '!');
* bound('hi');
* // => 'hi fred!'
*/
declare function bind(func: (...args: any[]) => any, thisObj: any, ...partialArgs: any[]): (...args: any[]) => any;
declare namespace bind {
var placeholder: typeof bindPlaceholder;
}
declare const bindPlaceholder: unique symbol;
//#endregion
export { bind };

View file

@ -0,0 +1,33 @@
//#region src/compat/function/bind.d.ts
/**
* Creates a function that invokes `func` with the `this` binding of `thisArg` and `partials` prepended to the arguments it receives.
*
* The `bind.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: Unlike native `Function#bind`, this method doesn't set the `length` property of bound functions.
*
* @param func - The function to bind.
* @param thisObj - The `this` binding of `func`.
* @param partialArgs - The arguments to be partially applied.
* @returns Returns the new bound function.
*
* @example
* function greet(greeting, punctuation) {
* return greeting + ' ' + this.user + punctuation;
* }
* const object = { user: 'fred' };
* let bound = bind(greet, object, 'hi');
* bound('!');
* // => 'hi fred!'
*
* bound = bind(greet, object, bind.placeholder, '!');
* bound('hi');
* // => 'hi fred!'
*/
declare function bind(func: (...args: any[]) => any, thisObj: any, ...partialArgs: any[]): (...args: any[]) => any;
declare namespace bind {
var placeholder: typeof bindPlaceholder;
}
declare const bindPlaceholder: unique symbol;
//#endregion
export { bind };

View file

@ -0,0 +1,44 @@
//#region src/compat/function/bind.ts
/**
* Creates a function that invokes `func` with the `this` binding of `thisArg` and `partials` prepended to the arguments it receives.
*
* The `bind.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: Unlike native `Function#bind`, this method doesn't set the `length` property of bound functions.
*
* @param func - The function to bind.
* @param thisObj - The `this` binding of `func`.
* @param partialArgs - The arguments to be partially applied.
* @returns Returns the new bound function.
*
* @example
* function greet(greeting, punctuation) {
* return greeting + ' ' + this.user + punctuation;
* }
* const object = { user: 'fred' };
* let bound = bind(greet, object, 'hi');
* bound('!');
* // => 'hi fred!'
*
* bound = bind(greet, object, bind.placeholder, '!');
* bound('hi');
* // => 'hi fred!'
*/
function bind(func, thisObj, ...partialArgs) {
const bound = function(...providedArgs) {
const args = [];
let startIndex = 0;
for (let i = 0; i < partialArgs.length; i++) {
const arg = partialArgs[i];
if (arg === bind.placeholder) args.push(providedArgs[startIndex++]);
else args.push(arg);
}
for (let i = startIndex; i < providedArgs.length; i++) args.push(providedArgs[i]);
if (this instanceof bound) return new func(...args);
return func.apply(thisObj, args);
};
return bound;
}
bind.placeholder = Symbol("bind.placeholder");
//#endregion
exports.bind = bind;

View file

@ -0,0 +1,44 @@
//#region src/compat/function/bind.ts
/**
* Creates a function that invokes `func` with the `this` binding of `thisArg` and `partials` prepended to the arguments it receives.
*
* The `bind.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* Note: Unlike native `Function#bind`, this method doesn't set the `length` property of bound functions.
*
* @param func - The function to bind.
* @param thisObj - The `this` binding of `func`.
* @param partialArgs - The arguments to be partially applied.
* @returns Returns the new bound function.
*
* @example
* function greet(greeting, punctuation) {
* return greeting + ' ' + this.user + punctuation;
* }
* const object = { user: 'fred' };
* let bound = bind(greet, object, 'hi');
* bound('!');
* // => 'hi fred!'
*
* bound = bind(greet, object, bind.placeholder, '!');
* bound('hi');
* // => 'hi fred!'
*/
function bind(func, thisObj, ...partialArgs) {
const bound = function(...providedArgs) {
const args = [];
let startIndex = 0;
for (let i = 0; i < partialArgs.length; i++) {
const arg = partialArgs[i];
if (arg === bind.placeholder) args.push(providedArgs[startIndex++]);
else args.push(arg);
}
for (let i = startIndex; i < providedArgs.length; i++) args.push(providedArgs[i]);
if (this instanceof bound) return new func(...args);
return func.apply(thisObj, args);
};
return bound;
}
bind.placeholder = Symbol("bind.placeholder");
//#endregion
export { bind };

View file

@ -0,0 +1,46 @@
//#region src/compat/function/bindKey.d.ts
/**
* Creates a function that invokes the method at `object[key]` with `partialArgs` prepended to the arguments it receives.
*
* This method differs from `bind` by allowing bound functions to reference methods that may be redefined or don't yet exist.
*
* The `bindKey.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* @template T - The type of the object to bind.
* @template K - The type of the key to bind.
* @param object - The object to invoke the method on.
* @param key - The key of the method.
* @param partialArgs - The arguments to be partially applied.
* @returns Returns the new bound function.
*
* @example
* const object = {
* user: 'fred',
* greet: function (greeting, punctuation) {
* return greeting + ' ' + this.user + punctuation;
* },
* };
*
* let bound = bindKey(object, 'greet', 'hi');
* bound('!');
* // => 'hi fred!'
*
* object.greet = function (greeting, punctuation) {
* return greeting + 'ya ' + this.user + punctuation;
* };
*
* bound('!');
* // => 'hiya fred!'
*
* // Bound with placeholders.
* bound = bindKey(object, 'greet', bindKey.placeholder, '!');
* bound('hi');
* // => 'hiya fred!'
*/
declare function bindKey(object: object, key: string, ...partialArgs: any[]): (...args: any[]) => any;
declare namespace bindKey {
var placeholder: typeof bindKeyPlaceholder;
}
declare const bindKeyPlaceholder: unique symbol;
//#endregion
export { bindKey };

View file

@ -0,0 +1,46 @@
//#region src/compat/function/bindKey.d.ts
/**
* Creates a function that invokes the method at `object[key]` with `partialArgs` prepended to the arguments it receives.
*
* This method differs from `bind` by allowing bound functions to reference methods that may be redefined or don't yet exist.
*
* The `bindKey.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* @template T - The type of the object to bind.
* @template K - The type of the key to bind.
* @param object - The object to invoke the method on.
* @param key - The key of the method.
* @param partialArgs - The arguments to be partially applied.
* @returns Returns the new bound function.
*
* @example
* const object = {
* user: 'fred',
* greet: function (greeting, punctuation) {
* return greeting + ' ' + this.user + punctuation;
* },
* };
*
* let bound = bindKey(object, 'greet', 'hi');
* bound('!');
* // => 'hi fred!'
*
* object.greet = function (greeting, punctuation) {
* return greeting + 'ya ' + this.user + punctuation;
* };
*
* bound('!');
* // => 'hiya fred!'
*
* // Bound with placeholders.
* bound = bindKey(object, 'greet', bindKey.placeholder, '!');
* bound('hi');
* // => 'hiya fred!'
*/
declare function bindKey(object: object, key: string, ...partialArgs: any[]): (...args: any[]) => any;
declare namespace bindKey {
var placeholder: typeof bindKeyPlaceholder;
}
declare const bindKeyPlaceholder: unique symbol;
//#endregion
export { bindKey };

View file

@ -0,0 +1,57 @@
//#region src/compat/function/bindKey.ts
/**
* Creates a function that invokes the method at `object[key]` with `partialArgs` prepended to the arguments it receives.
*
* This method differs from `bind` by allowing bound functions to reference methods that may be redefined or don't yet exist.
*
* The `bindKey.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* @template T - The type of the object to bind.
* @template K - The type of the key to bind.
* @param object - The object to invoke the method on.
* @param key - The key of the method.
* @param partialArgs - The arguments to be partially applied.
* @returns Returns the new bound function.
*
* @example
* const object = {
* user: 'fred',
* greet: function (greeting, punctuation) {
* return greeting + ' ' + this.user + punctuation;
* },
* };
*
* let bound = bindKey(object, 'greet', 'hi');
* bound('!');
* // => 'hi fred!'
*
* object.greet = function (greeting, punctuation) {
* return greeting + 'ya ' + this.user + punctuation;
* };
*
* bound('!');
* // => 'hiya fred!'
*
* // Bound with placeholders.
* bound = bindKey(object, 'greet', bindKey.placeholder, '!');
* bound('hi');
* // => 'hiya fred!'
*/
function bindKey(object, key, ...partialArgs) {
const bound = function(...providedArgs) {
const args = [];
let startIndex = 0;
for (let i = 0; i < partialArgs.length; i++) {
const arg = partialArgs[i];
if (arg === bindKey.placeholder) args.push(providedArgs[startIndex++]);
else args.push(arg);
}
for (let i = startIndex; i < providedArgs.length; i++) args.push(providedArgs[i]);
if (this instanceof bound) return new object[key](...args);
return object[key].apply(object, args);
};
return bound;
}
bindKey.placeholder = Symbol("bindKey.placeholder");
//#endregion
exports.bindKey = bindKey;

View file

@ -0,0 +1,57 @@
//#region src/compat/function/bindKey.ts
/**
* Creates a function that invokes the method at `object[key]` with `partialArgs` prepended to the arguments it receives.
*
* This method differs from `bind` by allowing bound functions to reference methods that may be redefined or don't yet exist.
*
* The `bindKey.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
*
* @template T - The type of the object to bind.
* @template K - The type of the key to bind.
* @param object - The object to invoke the method on.
* @param key - The key of the method.
* @param partialArgs - The arguments to be partially applied.
* @returns Returns the new bound function.
*
* @example
* const object = {
* user: 'fred',
* greet: function (greeting, punctuation) {
* return greeting + ' ' + this.user + punctuation;
* },
* };
*
* let bound = bindKey(object, 'greet', 'hi');
* bound('!');
* // => 'hi fred!'
*
* object.greet = function (greeting, punctuation) {
* return greeting + 'ya ' + this.user + punctuation;
* };
*
* bound('!');
* // => 'hiya fred!'
*
* // Bound with placeholders.
* bound = bindKey(object, 'greet', bindKey.placeholder, '!');
* bound('hi');
* // => 'hiya fred!'
*/
function bindKey(object, key, ...partialArgs) {
const bound = function(...providedArgs) {
const args = [];
let startIndex = 0;
for (let i = 0; i < partialArgs.length; i++) {
const arg = partialArgs[i];
if (arg === bindKey.placeholder) args.push(providedArgs[startIndex++]);
else args.push(arg);
}
for (let i = startIndex; i < providedArgs.length; i++) args.push(providedArgs[i]);
if (this instanceof bound) return new object[key](...args);
return object[key].apply(object, args);
};
return bound;
}
bindKey.placeholder = Symbol("bindKey.placeholder");
//#endregion
export { bindKey };

View file

@ -0,0 +1,155 @@
//#region src/compat/function/curry.d.ts
type __ = typeof curryPlaceholder;
interface CurriedFunction1<T1, R> {
(): CurriedFunction1<T1, R>;
(t1: T1): R;
}
interface CurriedFunction2<T1, T2, R> {
(): CurriedFunction2<T1, T2, R>;
(t1: T1): CurriedFunction1<T2, R>;
(t1: __, t2: T2): CurriedFunction1<T1, R>;
(t1: T1, t2: T2): R;
}
interface CurriedFunction3<T1, T2, T3, R> {
(): CurriedFunction3<T1, T2, T3, R>;
(t1: T1): CurriedFunction2<T2, T3, R>;
(t1: __, t2: T2): CurriedFunction2<T1, T3, R>;
(t1: T1, t2: T2): CurriedFunction1<T3, R>;
(t1: __, t2: __, t3: T3): CurriedFunction2<T1, T2, R>;
(t1: T1, t2: __, t3: T3): CurriedFunction1<T2, R>;
(t1: __, t2: T2, t3: T3): CurriedFunction1<T1, R>;
(t1: T1, t2: T2, t3: T3): R;
}
interface CurriedFunction4<T1, T2, T3, T4, R> {
(): CurriedFunction4<T1, T2, T3, T4, R>;
(t1: T1): CurriedFunction3<T2, T3, T4, R>;
(t1: __, t2: T2): CurriedFunction3<T1, T3, T4, R>;
(t1: T1, t2: T2): CurriedFunction2<T3, T4, R>;
(t1: __, t2: __, t3: T3): CurriedFunction3<T1, T2, T4, R>;
(t1: __, t2: __, t3: T3): CurriedFunction2<T2, T4, R>;
(t1: __, t2: T2, t3: T3): CurriedFunction2<T1, T4, R>;
(t1: T1, t2: T2, t3: T3): CurriedFunction1<T4, R>;
(t1: __, t2: __, t3: __, t4: T4): CurriedFunction3<T1, T2, T3, R>;
(t1: T1, t2: __, t3: __, t4: T4): CurriedFunction2<T2, T3, R>;
(t1: __, t2: T2, t3: __, t4: T4): CurriedFunction2<T1, T3, R>;
(t1: __, t2: __, t3: T3, t4: T4): CurriedFunction2<T1, T2, R>;
(t1: T1, t2: T2, t3: __, t4: T4): CurriedFunction1<T3, R>;
(t1: T1, t2: __, t3: T3, t4: T4): CurriedFunction1<T2, R>;
(t1: __, t2: T2, t3: T3, t4: T4): CurriedFunction1<T1, R>;
(t1: T1, t2: T2, t3: T3, t4: T4): R;
}
interface CurriedFunction5<T1, T2, T3, T4, T5, R> {
(): CurriedFunction5<T1, T2, T3, T4, T5, R>;
(t1: T1): CurriedFunction4<T2, T3, T4, T5, R>;
(t1: __, t2: T2): CurriedFunction4<T1, T3, T4, T5, R>;
(t1: T1, t2: T2): CurriedFunction3<T3, T4, T5, R>;
(t1: __, t2: __, t3: T3): CurriedFunction4<T1, T2, T4, T5, R>;
(t1: T1, t2: __, t3: T3): CurriedFunction3<T2, T4, T5, R>;
(t1: __, t2: T2, t3: T3): CurriedFunction3<T1, T4, T5, R>;
(t1: T1, t2: T2, t3: T3): CurriedFunction2<T4, T5, R>;
(t1: __, t2: __, t3: __, t4: T4): CurriedFunction4<T1, T2, T3, T5, R>;
(t1: T1, t2: __, t3: __, t4: T4): CurriedFunction3<T2, T3, T5, R>;
(t1: __, t2: T2, t3: __, t4: T4): CurriedFunction3<T1, T3, T5, R>;
(t1: __, t2: __, t3: T3, t4: T4): CurriedFunction3<T1, T2, T5, R>;
(t1: T1, t2: T2, t3: __, t4: T4): CurriedFunction2<T3, T5, R>;
(t1: T1, t2: __, t3: T3, t4: T4): CurriedFunction2<T2, T5, R>;
(t1: __, t2: T2, t3: T3, t4: T4): CurriedFunction2<T1, T5, R>;
(t1: T1, t2: T2, t3: T3, t4: T4): CurriedFunction1<T5, R>;
(t1: __, t2: __, t3: __, t4: __, t5: T5): CurriedFunction4<T1, T2, T3, T4, R>;
(t1: T1, t2: __, t3: __, t4: __, t5: T5): CurriedFunction3<T2, T3, T4, R>;
(t1: __, t2: T2, t3: __, t4: __, t5: T5): CurriedFunction3<T1, T3, T4, R>;
(t1: __, t2: __, t3: T3, t4: __, t5: T5): CurriedFunction3<T1, T2, T4, R>;
(t1: __, t2: __, t3: __, t4: T4, t5: T5): CurriedFunction3<T1, T2, T3, R>;
(t1: T1, t2: T2, t3: __, t4: __, t5: T5): CurriedFunction2<T3, T4, R>;
(t1: T1, t2: __, t3: T3, t4: __, t5: T5): CurriedFunction2<T2, T4, R>;
(t1: T1, t2: __, t3: __, t4: T4, t5: T5): CurriedFunction2<T2, T3, R>;
(t1: __, t2: T2, t3: T3, t4: __, t5: T5): CurriedFunction2<T1, T4, R>;
(t1: __, t2: T2, t3: __, t4: T4, t5: T5): CurriedFunction2<T1, T3, R>;
(t1: __, t2: __, t3: T3, t4: T4, t5: T5): CurriedFunction2<T1, T2, R>;
(t1: T1, t2: T2, t3: T3, t4: __, t5: T5): CurriedFunction1<T4, R>;
(t1: T1, t2: T2, t3: __, t4: T4, t5: T5): CurriedFunction1<T3, R>;
(t1: T1, t2: __, t3: T3, t4: T4, t5: T5): CurriedFunction1<T2, R>;
(t1: __, t2: T2, t3: T3, t4: T4, t5: T5): CurriedFunction1<T1, R>;
(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5): R;
}
/**
* Creates a curried function that accepts a single argument.
* @param func - The function to curry.
* @param arity - The arity of func.
* @returns Returns the new curried function.
* @example
* const greet = (name: string) => `Hello ${name}`;
* const curriedGreet = curry(greet);
* curriedGreet('John'); // => 'Hello John'
*/
declare function curry<T1, R>(func: (t1: T1) => R, arity?: number): CurriedFunction1<T1, R>;
/**
* Creates a curried function that accepts two arguments.
* @param func - The function to curry.
* @param arity - The arity of func.
* @returns Returns the new curried function.
* @example
* const add = (a: number, b: number) => a + b;
* const curriedAdd = curry(add);
* curriedAdd(1)(2); // => 3
* curriedAdd(1, 2); // => 3
*/
declare function curry<T1, T2, R>(func: (t1: T1, t2: T2) => R, arity?: number): CurriedFunction2<T1, T2, R>;
/**
* Creates a curried function that accepts three arguments.
* @param func - The function to curry.
* @param arity - The arity of func.
* @returns Returns the new curried function.
* @example
* const volume = (l: number, w: number, h: number) => l * w * h;
* const curriedVolume = curry(volume);
* curriedVolume(2)(3)(4); // => 24
* curriedVolume(2, 3)(4); // => 24
* curriedVolume(2, 3, 4); // => 24
*/
declare function curry<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arity?: number): CurriedFunction3<T1, T2, T3, R>;
/**
* Creates a curried function that accepts four arguments.
* @param func - The function to curry.
* @param arity - The arity of func.
* @returns Returns the new curried function.
* @example
* const fn = (a: number, b: number, c: number, d: number) => a + b + c + d;
* const curriedFn = curry(fn);
* curriedFn(1)(2)(3)(4); // => 10
* curriedFn(1, 2)(3, 4); // => 10
* curriedFn(1, 2, 3, 4); // => 10
*/
declare function curry<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arity?: number): CurriedFunction4<T1, T2, T3, T4, R>;
/**
* Creates a curried function that accepts five arguments.
* @param func - The function to curry.
* @param arity - The arity of func.
* @returns Returns the new curried function.
* @example
* const fn = (a: number, b: number, c: number, d: number, e: number) => a + b + c + d + e;
* const curriedFn = curry(fn);
* curriedFn(1)(2)(3)(4)(5); // => 15
* curriedFn(1, 2)(3, 4)(5); // => 15
* curriedFn(1, 2, 3, 4, 5); // => 15
*/
declare function curry<T1, T2, T3, T4, T5, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5) => R, arity?: number): CurriedFunction5<T1, T2, T3, T4, T5, R>;
/**
* Creates a curried function that accepts any number of arguments.
* @param func - The function to curry.
* @param arity - The arity of func.
* @returns Returns the new curried function.
* @example
* const sum = (...args: number[]) => args.reduce((a, b) => a + b, 0);
* const curriedSum = curry(sum);
* curriedSum(1, 2, 3); // => 6
* curriedSum(1)(2, 3); // => 6
* curriedSum(1)(2)(3); // => 6
*/
declare function curry(func: (...args: any[]) => any, arity?: number): (...args: any[]) => any;
declare namespace curry {
var placeholder: typeof curryPlaceholder;
}
declare const curryPlaceholder: unique symbol;
//#endregion
export { curry };

View file

@ -0,0 +1,155 @@
//#region src/compat/function/curry.d.ts
type __ = typeof curryPlaceholder;
interface CurriedFunction1<T1, R> {
(): CurriedFunction1<T1, R>;
(t1: T1): R;
}
interface CurriedFunction2<T1, T2, R> {
(): CurriedFunction2<T1, T2, R>;
(t1: T1): CurriedFunction1<T2, R>;
(t1: __, t2: T2): CurriedFunction1<T1, R>;
(t1: T1, t2: T2): R;
}
interface CurriedFunction3<T1, T2, T3, R> {
(): CurriedFunction3<T1, T2, T3, R>;
(t1: T1): CurriedFunction2<T2, T3, R>;
(t1: __, t2: T2): CurriedFunction2<T1, T3, R>;
(t1: T1, t2: T2): CurriedFunction1<T3, R>;
(t1: __, t2: __, t3: T3): CurriedFunction2<T1, T2, R>;
(t1: T1, t2: __, t3: T3): CurriedFunction1<T2, R>;
(t1: __, t2: T2, t3: T3): CurriedFunction1<T1, R>;
(t1: T1, t2: T2, t3: T3): R;
}
interface CurriedFunction4<T1, T2, T3, T4, R> {
(): CurriedFunction4<T1, T2, T3, T4, R>;
(t1: T1): CurriedFunction3<T2, T3, T4, R>;
(t1: __, t2: T2): CurriedFunction3<T1, T3, T4, R>;
(t1: T1, t2: T2): CurriedFunction2<T3, T4, R>;
(t1: __, t2: __, t3: T3): CurriedFunction3<T1, T2, T4, R>;
(t1: __, t2: __, t3: T3): CurriedFunction2<T2, T4, R>;
(t1: __, t2: T2, t3: T3): CurriedFunction2<T1, T4, R>;
(t1: T1, t2: T2, t3: T3): CurriedFunction1<T4, R>;
(t1: __, t2: __, t3: __, t4: T4): CurriedFunction3<T1, T2, T3, R>;
(t1: T1, t2: __, t3: __, t4: T4): CurriedFunction2<T2, T3, R>;
(t1: __, t2: T2, t3: __, t4: T4): CurriedFunction2<T1, T3, R>;
(t1: __, t2: __, t3: T3, t4: T4): CurriedFunction2<T1, T2, R>;
(t1: T1, t2: T2, t3: __, t4: T4): CurriedFunction1<T3, R>;
(t1: T1, t2: __, t3: T3, t4: T4): CurriedFunction1<T2, R>;
(t1: __, t2: T2, t3: T3, t4: T4): CurriedFunction1<T1, R>;
(t1: T1, t2: T2, t3: T3, t4: T4): R;
}
interface CurriedFunction5<T1, T2, T3, T4, T5, R> {
(): CurriedFunction5<T1, T2, T3, T4, T5, R>;
(t1: T1): CurriedFunction4<T2, T3, T4, T5, R>;
(t1: __, t2: T2): CurriedFunction4<T1, T3, T4, T5, R>;
(t1: T1, t2: T2): CurriedFunction3<T3, T4, T5, R>;
(t1: __, t2: __, t3: T3): CurriedFunction4<T1, T2, T4, T5, R>;
(t1: T1, t2: __, t3: T3): CurriedFunction3<T2, T4, T5, R>;
(t1: __, t2: T2, t3: T3): CurriedFunction3<T1, T4, T5, R>;
(t1: T1, t2: T2, t3: T3): CurriedFunction2<T4, T5, R>;
(t1: __, t2: __, t3: __, t4: T4): CurriedFunction4<T1, T2, T3, T5, R>;
(t1: T1, t2: __, t3: __, t4: T4): CurriedFunction3<T2, T3, T5, R>;
(t1: __, t2: T2, t3: __, t4: T4): CurriedFunction3<T1, T3, T5, R>;
(t1: __, t2: __, t3: T3, t4: T4): CurriedFunction3<T1, T2, T5, R>;
(t1: T1, t2: T2, t3: __, t4: T4): CurriedFunction2<T3, T5, R>;
(t1: T1, t2: __, t3: T3, t4: T4): CurriedFunction2<T2, T5, R>;
(t1: __, t2: T2, t3: T3, t4: T4): CurriedFunction2<T1, T5, R>;
(t1: T1, t2: T2, t3: T3, t4: T4): CurriedFunction1<T5, R>;
(t1: __, t2: __, t3: __, t4: __, t5: T5): CurriedFunction4<T1, T2, T3, T4, R>;
(t1: T1, t2: __, t3: __, t4: __, t5: T5): CurriedFunction3<T2, T3, T4, R>;
(t1: __, t2: T2, t3: __, t4: __, t5: T5): CurriedFunction3<T1, T3, T4, R>;
(t1: __, t2: __, t3: T3, t4: __, t5: T5): CurriedFunction3<T1, T2, T4, R>;
(t1: __, t2: __, t3: __, t4: T4, t5: T5): CurriedFunction3<T1, T2, T3, R>;
(t1: T1, t2: T2, t3: __, t4: __, t5: T5): CurriedFunction2<T3, T4, R>;
(t1: T1, t2: __, t3: T3, t4: __, t5: T5): CurriedFunction2<T2, T4, R>;
(t1: T1, t2: __, t3: __, t4: T4, t5: T5): CurriedFunction2<T2, T3, R>;
(t1: __, t2: T2, t3: T3, t4: __, t5: T5): CurriedFunction2<T1, T4, R>;
(t1: __, t2: T2, t3: __, t4: T4, t5: T5): CurriedFunction2<T1, T3, R>;
(t1: __, t2: __, t3: T3, t4: T4, t5: T5): CurriedFunction2<T1, T2, R>;
(t1: T1, t2: T2, t3: T3, t4: __, t5: T5): CurriedFunction1<T4, R>;
(t1: T1, t2: T2, t3: __, t4: T4, t5: T5): CurriedFunction1<T3, R>;
(t1: T1, t2: __, t3: T3, t4: T4, t5: T5): CurriedFunction1<T2, R>;
(t1: __, t2: T2, t3: T3, t4: T4, t5: T5): CurriedFunction1<T1, R>;
(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5): R;
}
/**
* Creates a curried function that accepts a single argument.
* @param func - The function to curry.
* @param arity - The arity of func.
* @returns Returns the new curried function.
* @example
* const greet = (name: string) => `Hello ${name}`;
* const curriedGreet = curry(greet);
* curriedGreet('John'); // => 'Hello John'
*/
declare function curry<T1, R>(func: (t1: T1) => R, arity?: number): CurriedFunction1<T1, R>;
/**
* Creates a curried function that accepts two arguments.
* @param func - The function to curry.
* @param arity - The arity of func.
* @returns Returns the new curried function.
* @example
* const add = (a: number, b: number) => a + b;
* const curriedAdd = curry(add);
* curriedAdd(1)(2); // => 3
* curriedAdd(1, 2); // => 3
*/
declare function curry<T1, T2, R>(func: (t1: T1, t2: T2) => R, arity?: number): CurriedFunction2<T1, T2, R>;
/**
* Creates a curried function that accepts three arguments.
* @param func - The function to curry.
* @param arity - The arity of func.
* @returns Returns the new curried function.
* @example
* const volume = (l: number, w: number, h: number) => l * w * h;
* const curriedVolume = curry(volume);
* curriedVolume(2)(3)(4); // => 24
* curriedVolume(2, 3)(4); // => 24
* curriedVolume(2, 3, 4); // => 24
*/
declare function curry<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arity?: number): CurriedFunction3<T1, T2, T3, R>;
/**
* Creates a curried function that accepts four arguments.
* @param func - The function to curry.
* @param arity - The arity of func.
* @returns Returns the new curried function.
* @example
* const fn = (a: number, b: number, c: number, d: number) => a + b + c + d;
* const curriedFn = curry(fn);
* curriedFn(1)(2)(3)(4); // => 10
* curriedFn(1, 2)(3, 4); // => 10
* curriedFn(1, 2, 3, 4); // => 10
*/
declare function curry<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arity?: number): CurriedFunction4<T1, T2, T3, T4, R>;
/**
* Creates a curried function that accepts five arguments.
* @param func - The function to curry.
* @param arity - The arity of func.
* @returns Returns the new curried function.
* @example
* const fn = (a: number, b: number, c: number, d: number, e: number) => a + b + c + d + e;
* const curriedFn = curry(fn);
* curriedFn(1)(2)(3)(4)(5); // => 15
* curriedFn(1, 2)(3, 4)(5); // => 15
* curriedFn(1, 2, 3, 4, 5); // => 15
*/
declare function curry<T1, T2, T3, T4, T5, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5) => R, arity?: number): CurriedFunction5<T1, T2, T3, T4, T5, R>;
/**
* Creates a curried function that accepts any number of arguments.
* @param func - The function to curry.
* @param arity - The arity of func.
* @returns Returns the new curried function.
* @example
* const sum = (...args: number[]) => args.reduce((a, b) => a + b, 0);
* const curriedSum = curry(sum);
* curriedSum(1, 2, 3); // => 6
* curriedSum(1)(2, 3); // => 6
* curriedSum(1)(2)(3); // => 6
*/
declare function curry(func: (...args: any[]) => any, arity?: number): (...args: any[]) => any;
declare namespace curry {
var placeholder: typeof curryPlaceholder;
}
declare const curryPlaceholder: unique symbol;
//#endregion
export { curry };

View file

@ -0,0 +1,81 @@
//#region src/compat/function/curry.ts
/**
* Creates a function that accepts arguments of `func` and either invokes `func` returning its result, if at least `arity` number of arguments have been provided, or returns a function that accepts the remaining `func` arguments, and so on.
* The arity of `func` may be specified if `func.length` is not sufficient.
*
* The `curry.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 curried functions.
*
* @param func - The function to curry.
* @param arity - The arity of func.
* @param guard - Enables use as an iteratee for methods like `Array#map`.
* @returns} - Returns the new curried function.
*
* @example
* const abc = function(a, b, c) {
* return Array.from(arguments);
* };
*
* let curried = curry(abc);
*
* curried(1)(2)(3);
* // => [1, 2, 3]
*
* curried(1, 2)(3);
* // => [1, 2, 3]
*
* curried(1, 2, 3);
* // => [1, 2, 3]
*
* // Curried with placeholders.
* curried(1)(curry.placeholder, 3)(2);
* // => [1, 2, 3]
*
* // Curried with arity.
* curried = curry(abc, 2);
*
* curried(1)(2);
* // => [1, 2]
*/
function curry(func, arity = func.length, guard) {
arity = guard ? func.length : arity;
arity = Number.parseInt(arity, 10);
if (Number.isNaN(arity) || arity < 1) arity = 0;
const wrapper = function(...partialArgs) {
const holders = partialArgs.filter((item) => item === curry.placeholder);
const length = partialArgs.length - holders.length;
if (length < arity) return makeCurry(func, arity - length, partialArgs);
if (this instanceof wrapper) return new func(...partialArgs);
return func.apply(this, partialArgs);
};
wrapper.placeholder = curryPlaceholder;
return wrapper;
}
function makeCurry(func, arity, partialArgs) {
function wrapper(...providedArgs) {
const holders = providedArgs.filter((item) => item === curry.placeholder);
const length = providedArgs.length - holders.length;
providedArgs = composeArgs(providedArgs, partialArgs);
if (length < arity) return makeCurry(func, arity - length, providedArgs);
if (this instanceof wrapper) return new func(...providedArgs);
return func.apply(this, providedArgs);
}
wrapper.placeholder = curryPlaceholder;
return wrapper;
}
function composeArgs(providedArgs, partialArgs) {
const args = [];
let startIndex = 0;
for (let i = 0; i < partialArgs.length; i++) {
const arg = partialArgs[i];
if (arg === curry.placeholder && startIndex < providedArgs.length) args.push(providedArgs[startIndex++]);
else args.push(arg);
}
for (let i = startIndex; i < providedArgs.length; i++) args.push(providedArgs[i]);
return args;
}
const curryPlaceholder = Symbol("curry.placeholder");
curry.placeholder = curryPlaceholder;
//#endregion
exports.curry = curry;

View file

@ -0,0 +1,81 @@
//#region src/compat/function/curry.ts
/**
* Creates a function that accepts arguments of `func` and either invokes `func` returning its result, if at least `arity` number of arguments have been provided, or returns a function that accepts the remaining `func` arguments, and so on.
* The arity of `func` may be specified if `func.length` is not sufficient.
*
* The `curry.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 curried functions.
*
* @param func - The function to curry.
* @param arity - The arity of func.
* @param guard - Enables use as an iteratee for methods like `Array#map`.
* @returns} - Returns the new curried function.
*
* @example
* const abc = function(a, b, c) {
* return Array.from(arguments);
* };
*
* let curried = curry(abc);
*
* curried(1)(2)(3);
* // => [1, 2, 3]
*
* curried(1, 2)(3);
* // => [1, 2, 3]
*
* curried(1, 2, 3);
* // => [1, 2, 3]
*
* // Curried with placeholders.
* curried(1)(curry.placeholder, 3)(2);
* // => [1, 2, 3]
*
* // Curried with arity.
* curried = curry(abc, 2);
*
* curried(1)(2);
* // => [1, 2]
*/
function curry(func, arity = func.length, guard) {
arity = guard ? func.length : arity;
arity = Number.parseInt(arity, 10);
if (Number.isNaN(arity) || arity < 1) arity = 0;
const wrapper = function(...partialArgs) {
const holders = partialArgs.filter((item) => item === curry.placeholder);
const length = partialArgs.length - holders.length;
if (length < arity) return makeCurry(func, arity - length, partialArgs);
if (this instanceof wrapper) return new func(...partialArgs);
return func.apply(this, partialArgs);
};
wrapper.placeholder = curryPlaceholder;
return wrapper;
}
function makeCurry(func, arity, partialArgs) {
function wrapper(...providedArgs) {
const holders = providedArgs.filter((item) => item === curry.placeholder);
const length = providedArgs.length - holders.length;
providedArgs = composeArgs(providedArgs, partialArgs);
if (length < arity) return makeCurry(func, arity - length, providedArgs);
if (this instanceof wrapper) return new func(...providedArgs);
return func.apply(this, providedArgs);
}
wrapper.placeholder = curryPlaceholder;
return wrapper;
}
function composeArgs(providedArgs, partialArgs) {
const args = [];
let startIndex = 0;
for (let i = 0; i < partialArgs.length; i++) {
const arg = partialArgs[i];
if (arg === curry.placeholder && startIndex < providedArgs.length) args.push(providedArgs[startIndex++]);
else args.push(arg);
}
for (let i = startIndex; i < providedArgs.length; i++) args.push(providedArgs[i]);
return args;
}
const curryPlaceholder = Symbol("curry.placeholder");
curry.placeholder = curryPlaceholder;
//#endregion
export { curry };

View file

@ -0,0 +1,86 @@
//#region src/compat/function/curryRight.d.ts
type __ = typeof curryRightPlaceholder;
interface RightCurriedFunction1<T1, R> {
(): RightCurriedFunction1<T1, R>;
(t1: T1): R;
}
interface RightCurriedFunction2<T1, T2, R> {
(): RightCurriedFunction2<T1, T2, R>;
(t2: T2): RightCurriedFunction1<T1, R>;
(t1: T1, t2: __): RightCurriedFunction1<T2, R>;
(t1: T1, t2: T2): R;
}
interface RightCurriedFunction3<T1, T2, T3, R> {
(): RightCurriedFunction3<T1, T2, T3, R>;
(t3: T3): RightCurriedFunction2<T1, T2, R>;
(t2: T2, t3: __): RightCurriedFunction2<T1, T3, R>;
(t2: T2, t3: T3): RightCurriedFunction1<T1, R>;
(t1: T1, t2: __, t3: __): RightCurriedFunction2<T2, T3, R>;
(t1: T1, t2: T2, t3: __): RightCurriedFunction1<T3, R>;
(t1: T1, t2: __, t3: T3): RightCurriedFunction1<T2, R>;
(t1: T1, t2: T2, t3: T3): R;
}
interface RightCurriedFunction4<T1, T2, T3, T4, R> {
(): RightCurriedFunction4<T1, T2, T3, T4, R>;
(t4: T4): RightCurriedFunction3<T1, T2, T3, R>;
(t3: T3, t4: __): RightCurriedFunction3<T1, T2, T4, R>;
(t3: T3, t4: T4): RightCurriedFunction2<T1, T2, R>;
(t2: T2, t3: __, t4: __): RightCurriedFunction3<T1, T3, T4, R>;
(t2: T2, t3: T3, t4: __): RightCurriedFunction2<T1, T4, R>;
(t2: T2, t3: __, t4: T4): RightCurriedFunction2<T1, T3, R>;
(t2: T2, t3: T3, t4: T4): RightCurriedFunction1<T1, R>;
(t1: T1, t2: __, t3: __, t4: __): RightCurriedFunction3<T2, T3, T4, R>;
(t1: T1, t2: T2, t3: __, t4: __): RightCurriedFunction2<T3, T4, R>;
(t1: T1, t2: __, t3: T3, t4: __): RightCurriedFunction2<T2, T4, R>;
(t1: T1, t2: __, t3: __, t4: T4): RightCurriedFunction2<T2, T3, R>;
(t1: T1, t2: T2, t3: T3, t4: __): RightCurriedFunction1<T4, R>;
(t1: T1, t2: T2, t3: __, t4: T4): RightCurriedFunction1<T3, R>;
(t1: T1, t2: __, t3: T3, t4: T4): RightCurriedFunction1<T2, R>;
(t1: T1, t2: T2, t3: T3, t4: T4): R;
}
interface RightCurriedFunction5<T1, T2, T3, T4, T5, R> {
(): RightCurriedFunction5<T1, T2, T3, T4, T5, R>;
(t5: T5): RightCurriedFunction4<T1, T2, T3, T4, R>;
(t4: T4, t5: __): RightCurriedFunction4<T1, T2, T3, T5, R>;
(t4: T4, t5: T5): RightCurriedFunction3<T1, T2, T3, R>;
(t3: T3, t4: __, t5: __): RightCurriedFunction4<T1, T2, T4, T5, R>;
(t3: T3, t4: T4, t5: __): RightCurriedFunction3<T1, T2, T5, R>;
(t3: T3, t4: __, t5: T5): RightCurriedFunction3<T1, T2, T4, R>;
(t3: T3, t4: T4, t5: T5): RightCurriedFunction2<T1, T2, R>;
(t2: T2, t3: __, t4: __, t5: __): RightCurriedFunction4<T1, T3, T4, T5, R>;
(t2: T2, t3: T3, t4: __, t5: __): RightCurriedFunction3<T1, T4, T5, R>;
(t2: T2, t3: __, t4: T4, t5: __): RightCurriedFunction3<T1, T3, T5, R>;
(t2: T2, t3: __, t4: __, t5: T5): RightCurriedFunction3<T1, T3, T4, R>;
(t2: T2, t3: T3, t4: T4, t5: __): RightCurriedFunction2<T1, T5, R>;
(t2: T2, t3: T3, t4: __, t5: T5): RightCurriedFunction2<T1, T4, R>;
(t2: T2, t3: __, t4: T4, t5: T5): RightCurriedFunction2<T1, T3, R>;
(t2: T2, t3: T3, t4: T4, t5: T5): RightCurriedFunction1<T1, R>;
(t1: T1, t2: __, t3: __, t4: __, t5: __): RightCurriedFunction4<T2, T3, T4, T5, R>;
(t1: T1, t2: T2, t3: __, t4: __, t5: __): RightCurriedFunction3<T3, T4, T5, R>;
(t1: T1, t2: __, t3: T3, t4: __, t5: __): RightCurriedFunction3<T2, T4, T5, R>;
(t1: T1, t2: __, t3: __, t4: T4, t5: __): RightCurriedFunction3<T2, T3, T5, R>;
(t1: T1, t2: __, t3: __, t4: __, t5: T5): RightCurriedFunction3<T2, T3, T4, R>;
(t1: T1, t2: T2, t3: T3, t4: __, t5: __): RightCurriedFunction2<T4, T5, R>;
(t1: T1, t2: T2, t3: __, t4: T4, t5: __): RightCurriedFunction2<T3, T5, R>;
(t1: T1, t2: T2, t3: __, t4: __, t5: T5): RightCurriedFunction2<T3, T4, R>;
(t1: T1, t2: __, t3: T3, t4: T4, t5: __): RightCurriedFunction2<T2, T5, R>;
(t1: T1, t2: __, t3: T3, t4: __, t5: T5): RightCurriedFunction2<T2, T4, R>;
(t1: T1, t2: __, t3: __, t4: T4, t5: T5): RightCurriedFunction2<T2, T3, R>;
(t1: T1, t2: T2, t3: T3, t4: T4, t5: __): RightCurriedFunction1<T5, R>;
(t1: T1, t2: T2, t3: T3, t4: __, t5: T5): RightCurriedFunction1<T4, R>;
(t1: T1, t2: T2, t3: __, t4: T4, t5: T5): RightCurriedFunction1<T3, R>;
(t1: T1, t2: __, t3: T3, t4: T4, t5: T5): RightCurriedFunction1<T2, R>;
(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5): R;
}
declare function curryRight<T1, R>(func: (t1: T1) => R, arity?: number): RightCurriedFunction1<T1, R>;
declare function curryRight<T1, T2, R>(func: (t1: T1, t2: T2) => R, arity?: number): RightCurriedFunction2<T1, T2, R>;
declare function curryRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arity?: number): RightCurriedFunction3<T1, T2, T3, R>;
declare function curryRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arity?: number): RightCurriedFunction4<T1, T2, T3, T4, R>;
declare function curryRight<T1, T2, T3, T4, T5, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5) => R, arity?: number): RightCurriedFunction5<T1, T2, T3, T4, T5, R>;
declare function curryRight(func: (...args: any[]) => any, arity?: number): (...args: any[]) => any;
declare namespace curryRight {
var placeholder: typeof curryRightPlaceholder;
}
declare const curryRightPlaceholder: unique symbol;
//#endregion
export { curryRight };

View file

@ -0,0 +1,86 @@
//#region src/compat/function/curryRight.d.ts
type __ = typeof curryRightPlaceholder;
interface RightCurriedFunction1<T1, R> {
(): RightCurriedFunction1<T1, R>;
(t1: T1): R;
}
interface RightCurriedFunction2<T1, T2, R> {
(): RightCurriedFunction2<T1, T2, R>;
(t2: T2): RightCurriedFunction1<T1, R>;
(t1: T1, t2: __): RightCurriedFunction1<T2, R>;
(t1: T1, t2: T2): R;
}
interface RightCurriedFunction3<T1, T2, T3, R> {
(): RightCurriedFunction3<T1, T2, T3, R>;
(t3: T3): RightCurriedFunction2<T1, T2, R>;
(t2: T2, t3: __): RightCurriedFunction2<T1, T3, R>;
(t2: T2, t3: T3): RightCurriedFunction1<T1, R>;
(t1: T1, t2: __, t3: __): RightCurriedFunction2<T2, T3, R>;
(t1: T1, t2: T2, t3: __): RightCurriedFunction1<T3, R>;
(t1: T1, t2: __, t3: T3): RightCurriedFunction1<T2, R>;
(t1: T1, t2: T2, t3: T3): R;
}
interface RightCurriedFunction4<T1, T2, T3, T4, R> {
(): RightCurriedFunction4<T1, T2, T3, T4, R>;
(t4: T4): RightCurriedFunction3<T1, T2, T3, R>;
(t3: T3, t4: __): RightCurriedFunction3<T1, T2, T4, R>;
(t3: T3, t4: T4): RightCurriedFunction2<T1, T2, R>;
(t2: T2, t3: __, t4: __): RightCurriedFunction3<T1, T3, T4, R>;
(t2: T2, t3: T3, t4: __): RightCurriedFunction2<T1, T4, R>;
(t2: T2, t3: __, t4: T4): RightCurriedFunction2<T1, T3, R>;
(t2: T2, t3: T3, t4: T4): RightCurriedFunction1<T1, R>;
(t1: T1, t2: __, t3: __, t4: __): RightCurriedFunction3<T2, T3, T4, R>;
(t1: T1, t2: T2, t3: __, t4: __): RightCurriedFunction2<T3, T4, R>;
(t1: T1, t2: __, t3: T3, t4: __): RightCurriedFunction2<T2, T4, R>;
(t1: T1, t2: __, t3: __, t4: T4): RightCurriedFunction2<T2, T3, R>;
(t1: T1, t2: T2, t3: T3, t4: __): RightCurriedFunction1<T4, R>;
(t1: T1, t2: T2, t3: __, t4: T4): RightCurriedFunction1<T3, R>;
(t1: T1, t2: __, t3: T3, t4: T4): RightCurriedFunction1<T2, R>;
(t1: T1, t2: T2, t3: T3, t4: T4): R;
}
interface RightCurriedFunction5<T1, T2, T3, T4, T5, R> {
(): RightCurriedFunction5<T1, T2, T3, T4, T5, R>;
(t5: T5): RightCurriedFunction4<T1, T2, T3, T4, R>;
(t4: T4, t5: __): RightCurriedFunction4<T1, T2, T3, T5, R>;
(t4: T4, t5: T5): RightCurriedFunction3<T1, T2, T3, R>;
(t3: T3, t4: __, t5: __): RightCurriedFunction4<T1, T2, T4, T5, R>;
(t3: T3, t4: T4, t5: __): RightCurriedFunction3<T1, T2, T5, R>;
(t3: T3, t4: __, t5: T5): RightCurriedFunction3<T1, T2, T4, R>;
(t3: T3, t4: T4, t5: T5): RightCurriedFunction2<T1, T2, R>;
(t2: T2, t3: __, t4: __, t5: __): RightCurriedFunction4<T1, T3, T4, T5, R>;
(t2: T2, t3: T3, t4: __, t5: __): RightCurriedFunction3<T1, T4, T5, R>;
(t2: T2, t3: __, t4: T4, t5: __): RightCurriedFunction3<T1, T3, T5, R>;
(t2: T2, t3: __, t4: __, t5: T5): RightCurriedFunction3<T1, T3, T4, R>;
(t2: T2, t3: T3, t4: T4, t5: __): RightCurriedFunction2<T1, T5, R>;
(t2: T2, t3: T3, t4: __, t5: T5): RightCurriedFunction2<T1, T4, R>;
(t2: T2, t3: __, t4: T4, t5: T5): RightCurriedFunction2<T1, T3, R>;
(t2: T2, t3: T3, t4: T4, t5: T5): RightCurriedFunction1<T1, R>;
(t1: T1, t2: __, t3: __, t4: __, t5: __): RightCurriedFunction4<T2, T3, T4, T5, R>;
(t1: T1, t2: T2, t3: __, t4: __, t5: __): RightCurriedFunction3<T3, T4, T5, R>;
(t1: T1, t2: __, t3: T3, t4: __, t5: __): RightCurriedFunction3<T2, T4, T5, R>;
(t1: T1, t2: __, t3: __, t4: T4, t5: __): RightCurriedFunction3<T2, T3, T5, R>;
(t1: T1, t2: __, t3: __, t4: __, t5: T5): RightCurriedFunction3<T2, T3, T4, R>;
(t1: T1, t2: T2, t3: T3, t4: __, t5: __): RightCurriedFunction2<T4, T5, R>;
(t1: T1, t2: T2, t3: __, t4: T4, t5: __): RightCurriedFunction2<T3, T5, R>;
(t1: T1, t2: T2, t3: __, t4: __, t5: T5): RightCurriedFunction2<T3, T4, R>;
(t1: T1, t2: __, t3: T3, t4: T4, t5: __): RightCurriedFunction2<T2, T5, R>;
(t1: T1, t2: __, t3: T3, t4: __, t5: T5): RightCurriedFunction2<T2, T4, R>;
(t1: T1, t2: __, t3: __, t4: T4, t5: T5): RightCurriedFunction2<T2, T3, R>;
(t1: T1, t2: T2, t3: T3, t4: T4, t5: __): RightCurriedFunction1<T5, R>;
(t1: T1, t2: T2, t3: T3, t4: __, t5: T5): RightCurriedFunction1<T4, R>;
(t1: T1, t2: T2, t3: __, t4: T4, t5: T5): RightCurriedFunction1<T3, R>;
(t1: T1, t2: __, t3: T3, t4: T4, t5: T5): RightCurriedFunction1<T2, R>;
(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5): R;
}
declare function curryRight<T1, R>(func: (t1: T1) => R, arity?: number): RightCurriedFunction1<T1, R>;
declare function curryRight<T1, T2, R>(func: (t1: T1, t2: T2) => R, arity?: number): RightCurriedFunction2<T1, T2, R>;
declare function curryRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arity?: number): RightCurriedFunction3<T1, T2, T3, R>;
declare function curryRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arity?: number): RightCurriedFunction4<T1, T2, T3, T4, R>;
declare function curryRight<T1, T2, T3, T4, T5, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5) => R, arity?: number): RightCurriedFunction5<T1, T2, T3, T4, T5, R>;
declare function curryRight(func: (...args: any[]) => any, arity?: number): (...args: any[]) => any;
declare namespace curryRight {
var placeholder: typeof curryRightPlaceholder;
}
declare const curryRightPlaceholder: unique symbol;
//#endregion
export { curryRight };

View file

@ -0,0 +1,86 @@
//#region src/compat/function/curryRight.ts
/**
* Creates a function that accepts arguments of `func` and either invokes `func` returning its result, if at least `arity` number of arguments have been provided, or returns a function that accepts the remaining `func` arguments, and so on.
* The arity of `func` may be specified if `func.length` is not sufficient.
*
* Unlike `curry`, this function curries the function from right to left.
*
* The `curryRight.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 curried functions.
*
* @param func - The function to curry.
* @param arity - The arity of func.
* @param guard - Enables use as an iteratee for methods like `Array#map`.
* @returns} - Returns the new curried function.
*
* @example
* const abc = function(a, b, c) {
* return Array.from(arguments);
* };
*
* let curried = curryRight(abc);
*
* curried(3)(2)(1);
* // => [1, 2, 3]
*
* curried(2, 3)(1);
* // => [1, 2, 3]
*
* curried(1, 2, 3);
* // => [1, 2, 3]
*
* // Curried with placeholders.
* curried(3)(curryRight.placeholder, 2)(1);
* // => [1, 2, 3]
*
* // Curried with arity.
* curried = curryRight(abc, 2);
*
* curried(2)(1);
* // => [1, 2]
*/
function curryRight(func, arity = func.length, guard) {
arity = guard ? func.length : arity;
arity = Number.parseInt(arity, 10);
if (Number.isNaN(arity) || arity < 1) arity = 0;
const wrapper = function(...partialArgs) {
const holders = partialArgs.filter((item) => item === curryRight.placeholder);
const length = partialArgs.length - holders.length;
if (length < arity) return makeCurryRight(func, arity - length, partialArgs);
if (this instanceof wrapper) return new func(...partialArgs);
return func.apply(this, partialArgs);
};
wrapper.placeholder = curryRightPlaceholder;
return wrapper;
}
function makeCurryRight(func, arity, partialArgs) {
function wrapper(...providedArgs) {
const holders = providedArgs.filter((item) => item === curryRight.placeholder);
const length = providedArgs.length - holders.length;
providedArgs = composeArgs(providedArgs, partialArgs);
if (length < arity) return makeCurryRight(func, arity - length, providedArgs);
if (this instanceof wrapper) return new func(...providedArgs);
return func.apply(this, providedArgs);
}
wrapper.placeholder = curryRightPlaceholder;
return wrapper;
}
function composeArgs(providedArgs, partialArgs) {
const placeholderLength = partialArgs.filter((arg) => arg === curryRight.placeholder).length;
const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
const args = [];
let providedIndex = 0;
for (let i = 0; i < rangeLength; i++) args.push(providedArgs[providedIndex++]);
for (let i = 0; i < partialArgs.length; i++) {
const arg = partialArgs[i];
if (arg === curryRight.placeholder) if (providedIndex < providedArgs.length) args.push(providedArgs[providedIndex++]);
else args.push(arg);
else args.push(arg);
}
return args;
}
const curryRightPlaceholder = Symbol("curryRight.placeholder");
curryRight.placeholder = curryRightPlaceholder;
//#endregion
exports.curryRight = curryRight;

View file

@ -0,0 +1,86 @@
//#region src/compat/function/curryRight.ts
/**
* Creates a function that accepts arguments of `func` and either invokes `func` returning its result, if at least `arity` number of arguments have been provided, or returns a function that accepts the remaining `func` arguments, and so on.
* The arity of `func` may be specified if `func.length` is not sufficient.
*
* Unlike `curry`, this function curries the function from right to left.
*
* The `curryRight.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 curried functions.
*
* @param func - The function to curry.
* @param arity - The arity of func.
* @param guard - Enables use as an iteratee for methods like `Array#map`.
* @returns} - Returns the new curried function.
*
* @example
* const abc = function(a, b, c) {
* return Array.from(arguments);
* };
*
* let curried = curryRight(abc);
*
* curried(3)(2)(1);
* // => [1, 2, 3]
*
* curried(2, 3)(1);
* // => [1, 2, 3]
*
* curried(1, 2, 3);
* // => [1, 2, 3]
*
* // Curried with placeholders.
* curried(3)(curryRight.placeholder, 2)(1);
* // => [1, 2, 3]
*
* // Curried with arity.
* curried = curryRight(abc, 2);
*
* curried(2)(1);
* // => [1, 2]
*/
function curryRight(func, arity = func.length, guard) {
arity = guard ? func.length : arity;
arity = Number.parseInt(arity, 10);
if (Number.isNaN(arity) || arity < 1) arity = 0;
const wrapper = function(...partialArgs) {
const holders = partialArgs.filter((item) => item === curryRight.placeholder);
const length = partialArgs.length - holders.length;
if (length < arity) return makeCurryRight(func, arity - length, partialArgs);
if (this instanceof wrapper) return new func(...partialArgs);
return func.apply(this, partialArgs);
};
wrapper.placeholder = curryRightPlaceholder;
return wrapper;
}
function makeCurryRight(func, arity, partialArgs) {
function wrapper(...providedArgs) {
const holders = providedArgs.filter((item) => item === curryRight.placeholder);
const length = providedArgs.length - holders.length;
providedArgs = composeArgs(providedArgs, partialArgs);
if (length < arity) return makeCurryRight(func, arity - length, providedArgs);
if (this instanceof wrapper) return new func(...providedArgs);
return func.apply(this, providedArgs);
}
wrapper.placeholder = curryRightPlaceholder;
return wrapper;
}
function composeArgs(providedArgs, partialArgs) {
const placeholderLength = partialArgs.filter((arg) => arg === curryRight.placeholder).length;
const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
const args = [];
let providedIndex = 0;
for (let i = 0; i < rangeLength; i++) args.push(providedArgs[providedIndex++]);
for (let i = 0; i < partialArgs.length; i++) {
const arg = partialArgs[i];
if (arg === curryRight.placeholder) if (providedIndex < providedArgs.length) args.push(providedArgs[providedIndex++]);
else args.push(arg);
else args.push(arg);
}
return args;
}
const curryRightPlaceholder = Symbol("curryRight.placeholder");
curryRight.placeholder = curryRightPlaceholder;
//#endregion
export { curryRight };

View file

@ -0,0 +1,145 @@
//#region src/compat/function/debounce.d.ts
interface DebounceSettings {
/**
* If `true`, the function will be invoked on the leading edge of the timeout.
* @default false
*/
leading?: boolean | undefined;
/**
* The maximum time `func` is allowed to be delayed before it's invoked.
* @default Infinity
*/
maxWait?: number | undefined;
/**
* If `true`, the function will be invoked on the trailing edge of the timeout.
* @default true
*/
trailing?: boolean | undefined;
}
interface DebounceSettingsLeading extends DebounceSettings {
leading: true;
}
interface DebouncedFunc<T extends (...args: any[]) => any> {
/**
* Call the original function, but applying the debounce rules.
*
* If the debounced function can be run immediately, this calls it and returns its return
* value.
*
* Otherwise, it returns the return value of the last invocation, or undefined if the debounced
* function was not invoked yet.
*/
(...args: Parameters<T>): ReturnType<T> | undefined;
/**
* Throw away any pending invocation of the debounced function.
*/
cancel(): void;
/**
* If there is a pending invocation of the debounced function, invoke it immediately and return
* its return value.
*
* Otherwise, return the value from the last invocation, or undefined if the debounced function
* was never invoked.
*/
flush(): ReturnType<T> | undefined;
}
interface DebouncedFuncLeading<T extends (...args: any[]) => any> extends DebouncedFunc<T> {
(...args: Parameters<T>): ReturnType<T>;
flush(): ReturnType<T>;
}
/**
* 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.
*
* You can set the debounced function to run at the start (`leading`) or end (`trailing`) of the delay period.
* If `leading` is true, the function runs immediately on the first call.
* If `trailing` is true, the function runs after `debounceMs` milliseconds have passed since the last call.
* If both `leading` and `trailing` are true, the function runs at both the start and end, but it must be called at least twice within `debounceMs` milliseconds for this to happen
* (since one debounced function call cannot trigger the function twice).
*
* You can also set a `maxWait` time, which is the maximum time the function is allowed to be delayed before it is called.
*
* @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.leading - If `true`, the function will be invoked on the leading edge of the timeout.
* @param options.trailing - If `true`, the function will be invoked on the trailing edge of the timeout.
* @param options.maxWait - The maximum time `func` is allowed to be delayed before it's invoked.
* @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<T extends (...args: any) => any>(func: T, wait: number | undefined, options: DebounceSettingsLeading): DebouncedFuncLeading<T>;
/**
* 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.
*
* You can set the debounced function to run at the start (`leading`) or end (`trailing`) of the delay period.
* If `leading` is true, the function runs immediately on the first call.
* If `trailing` is true, the function runs after `debounceMs` milliseconds have passed since the last call.
* If both `leading` and `trailing` are true, the function runs at both the start and end, but it must be called at least twice within `debounceMs` milliseconds for this to happen
* (since one debounced function call cannot trigger the function twice).
*
* You can also set a `maxWait` time, which is the maximum time the function is allowed to be delayed before it is called.
*
* @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.leading - If `true`, the function will be invoked on the leading edge of the timeout.
* @param options.trailing - If `true`, the function will be invoked on the trailing edge of the timeout.
* @param options.maxWait - The maximum time `func` is allowed to be delayed before it's invoked.
* @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<T extends (...args: any) => any>(func: T, wait?: number, options?: DebounceSettings): DebouncedFunc<T>;
//#endregion
export { DebouncedFunc, DebouncedFuncLeading, debounce };

View file

@ -0,0 +1,145 @@
//#region src/compat/function/debounce.d.ts
interface DebounceSettings {
/**
* If `true`, the function will be invoked on the leading edge of the timeout.
* @default false
*/
leading?: boolean | undefined;
/**
* The maximum time `func` is allowed to be delayed before it's invoked.
* @default Infinity
*/
maxWait?: number | undefined;
/**
* If `true`, the function will be invoked on the trailing edge of the timeout.
* @default true
*/
trailing?: boolean | undefined;
}
interface DebounceSettingsLeading extends DebounceSettings {
leading: true;
}
interface DebouncedFunc<T extends (...args: any[]) => any> {
/**
* Call the original function, but applying the debounce rules.
*
* If the debounced function can be run immediately, this calls it and returns its return
* value.
*
* Otherwise, it returns the return value of the last invocation, or undefined if the debounced
* function was not invoked yet.
*/
(...args: Parameters<T>): ReturnType<T> | undefined;
/**
* Throw away any pending invocation of the debounced function.
*/
cancel(): void;
/**
* If there is a pending invocation of the debounced function, invoke it immediately and return
* its return value.
*
* Otherwise, return the value from the last invocation, or undefined if the debounced function
* was never invoked.
*/
flush(): ReturnType<T> | undefined;
}
interface DebouncedFuncLeading<T extends (...args: any[]) => any> extends DebouncedFunc<T> {
(...args: Parameters<T>): ReturnType<T>;
flush(): ReturnType<T>;
}
/**
* 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.
*
* You can set the debounced function to run at the start (`leading`) or end (`trailing`) of the delay period.
* If `leading` is true, the function runs immediately on the first call.
* If `trailing` is true, the function runs after `debounceMs` milliseconds have passed since the last call.
* If both `leading` and `trailing` are true, the function runs at both the start and end, but it must be called at least twice within `debounceMs` milliseconds for this to happen
* (since one debounced function call cannot trigger the function twice).
*
* You can also set a `maxWait` time, which is the maximum time the function is allowed to be delayed before it is called.
*
* @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.leading - If `true`, the function will be invoked on the leading edge of the timeout.
* @param options.trailing - If `true`, the function will be invoked on the trailing edge of the timeout.
* @param options.maxWait - The maximum time `func` is allowed to be delayed before it's invoked.
* @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<T extends (...args: any) => any>(func: T, wait: number | undefined, options: DebounceSettingsLeading): DebouncedFuncLeading<T>;
/**
* 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.
*
* You can set the debounced function to run at the start (`leading`) or end (`trailing`) of the delay period.
* If `leading` is true, the function runs immediately on the first call.
* If `trailing` is true, the function runs after `debounceMs` milliseconds have passed since the last call.
* If both `leading` and `trailing` are true, the function runs at both the start and end, but it must be called at least twice within `debounceMs` milliseconds for this to happen
* (since one debounced function call cannot trigger the function twice).
*
* You can also set a `maxWait` time, which is the maximum time the function is allowed to be delayed before it is called.
*
* @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.leading - If `true`, the function will be invoked on the leading edge of the timeout.
* @param options.trailing - If `true`, the function will be invoked on the trailing edge of the timeout.
* @param options.maxWait - The maximum time `func` is allowed to be delayed before it's invoked.
* @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<T extends (...args: any) => any>(func: T, wait?: number, options?: DebounceSettings): DebouncedFunc<T>;
//#endregion
export { DebouncedFunc, DebouncedFuncLeading, debounce };

View file

@ -0,0 +1,38 @@
const require_debounce = require("../../function/debounce.js");
//#region src/compat/function/debounce.ts
function debounce(func, debounceMs = 0, options = {}) {
if (typeof options !== "object") options = {};
const { leading = false, trailing = true, maxWait } = options;
const edges = Array(2);
if (leading) edges[0] = "leading";
if (trailing) edges[1] = "trailing";
let result = void 0;
let pendingAt = null;
const _debounced = require_debounce.debounce(function(...args) {
result = func.apply(this, args);
pendingAt = null;
}, debounceMs, { edges });
const debounced = function(...args) {
if (maxWait != null) {
if (pendingAt === null) pendingAt = Date.now();
if (Date.now() - pendingAt >= maxWait) {
result = func.apply(this, args);
pendingAt = Date.now();
_debounced.cancel();
_debounced.schedule();
return result;
}
}
_debounced.apply(this, args);
return result;
};
const flush = () => {
_debounced.flush();
return result;
};
debounced.cancel = _debounced.cancel;
debounced.flush = flush;
return debounced;
}
//#endregion
exports.debounce = debounce;

View file

@ -0,0 +1,38 @@
import { debounce as debounce$1 } from "../../function/debounce.mjs";
//#region src/compat/function/debounce.ts
function debounce(func, debounceMs = 0, options = {}) {
if (typeof options !== "object") options = {};
const { leading = false, trailing = true, maxWait } = options;
const edges = Array(2);
if (leading) edges[0] = "leading";
if (trailing) edges[1] = "trailing";
let result = void 0;
let pendingAt = null;
const _debounced = debounce$1(function(...args) {
result = func.apply(this, args);
pendingAt = null;
}, debounceMs, { edges });
const debounced = function(...args) {
if (maxWait != null) {
if (pendingAt === null) pendingAt = Date.now();
if (Date.now() - pendingAt >= maxWait) {
result = func.apply(this, args);
pendingAt = Date.now();
_debounced.cancel();
_debounced.schedule();
return result;
}
}
_debounced.apply(this, args);
return result;
};
const flush = () => {
_debounced.flush();
return result;
};
debounced.cancel = _debounced.cancel;
debounced.flush = flush;
return debounced;
}
//#endregion
export { debounce };

View file

@ -0,0 +1,15 @@
//#region src/compat/function/defer.d.ts
/**
* Defers invoking the `func` until the current call stack has cleared. Any additional arguments are provided to func when it's invoked.
*
* @param func The function to defer.
* @param args The arguments to invoke `func` with.
* @returns Returns the timer id.
*
* @example
* defer(console.log, 'deferred');
* // => Logs 'deferred' after the current call stack has cleared.
*/
declare function defer(func: (...args: any[]) => any, ...args: any[]): number;
//#endregion
export { defer };

View file

@ -0,0 +1,15 @@
//#region src/compat/function/defer.d.ts
/**
* Defers invoking the `func` until the current call stack has cleared. Any additional arguments are provided to func when it's invoked.
*
* @param func The function to defer.
* @param args The arguments to invoke `func` with.
* @returns Returns the timer id.
*
* @example
* defer(console.log, 'deferred');
* // => Logs 'deferred' after the current call stack has cleared.
*/
declare function defer(func: (...args: any[]) => any, ...args: any[]): number;
//#endregion
export { defer };

View file

@ -0,0 +1,20 @@
//#region src/compat/function/defer.ts
/**
* Defers invoking the `func` until the current call stack has cleared. Any additional arguments are provided to func when it's invoked.
*
* @param func The function to defer.
* @param args The arguments to invoke `func` with.
* @returns Returns the timer id.
*
* @example
* defer((text) => {
* console.log(text);
* }, 'deferred');
* // => Logs 'deferred' after the current call stack has cleared.
*/
function defer(func, ...args) {
if (typeof func !== "function") throw new TypeError("Expected a function");
return setTimeout(func, 1, ...args);
}
//#endregion
exports.defer = defer;

View file

@ -0,0 +1,20 @@
//#region src/compat/function/defer.ts
/**
* Defers invoking the `func` until the current call stack has cleared. Any additional arguments are provided to func when it's invoked.
*
* @param func The function to defer.
* @param args The arguments to invoke `func` with.
* @returns Returns the timer id.
*
* @example
* defer((text) => {
* console.log(text);
* }, 'deferred');
* // => Logs 'deferred' after the current call stack has cleared.
*/
function defer(func, ...args) {
if (typeof func !== "function") throw new TypeError("Expected a function");
return setTimeout(func, 1, ...args);
}
//#endregion
export { defer };

View file

@ -0,0 +1,30 @@
//#region src/compat/function/delay.d.ts
/**
* Invokes the specified function after a delay of the given number of milliseconds.
* Any additional arguments are passed to the function when it is invoked.
*
* @param func - The function to delay.
* @param wait - The number of milliseconds to delay the invocation.
* @param args - The arguments to pass to the function when it is invoked.
* @returns Returns the timer id.
* @throws {TypeError} If the first argument is not a function.
*
* @example
* // Example 1: Delayed function execution
* const timerId = delay(
* (greeting, recipient) => {
* console.log(`${greeting}, ${recipient}!`);
* },
* 1000,
* 'Hello',
* 'Alice'
* );
* // => 'Hello, Alice!' will be logged after one second.
*
* // Example 2: Clearing the timeout before execution
* clearTimeout(timerId);
* // The function will not be executed because the timeout was cleared.
*/
declare function delay(func: (...args: any[]) => any, wait: number, ...args: any[]): number;
//#endregion
export { delay };

View file

@ -0,0 +1,30 @@
//#region src/compat/function/delay.d.ts
/**
* Invokes the specified function after a delay of the given number of milliseconds.
* Any additional arguments are passed to the function when it is invoked.
*
* @param func - The function to delay.
* @param wait - The number of milliseconds to delay the invocation.
* @param args - The arguments to pass to the function when it is invoked.
* @returns Returns the timer id.
* @throws {TypeError} If the first argument is not a function.
*
* @example
* // Example 1: Delayed function execution
* const timerId = delay(
* (greeting, recipient) => {
* console.log(`${greeting}, ${recipient}!`);
* },
* 1000,
* 'Hello',
* 'Alice'
* );
* // => 'Hello, Alice!' will be logged after one second.
*
* // Example 2: Clearing the timeout before execution
* clearTimeout(timerId);
* // The function will not be executed because the timeout was cleared.
*/
declare function delay(func: (...args: any[]) => any, wait: number, ...args: any[]): number;
//#endregion
export { delay };

View file

@ -0,0 +1,34 @@
const require_toNumber = require("../util/toNumber.js");
//#region src/compat/function/delay.ts
/**
* Invokes the specified function after a delay of the given number of milliseconds.
* Any additional arguments are passed to the function when it is invoked.
*
* @param func - The function to delay.
* @param wait - The number of milliseconds to delay the invocation.
* @param args - The arguments to pass to the function when it is invoked.
* @returns Returns the timer id.
* @throws {TypeError} If the first argument is not a function.
*
* @example
* // Example 1: Delayed function execution
* const timerId = delay(
* (greeting, recipient) => {
* console.log(`${greeting}, ${recipient}!`);
* },
* 1000,
* 'Hello',
* 'Alice'
* );
* // => 'Hello, Alice!' will be logged after one second.
*
* // Example 2: Clearing the timeout before execution
* clearTimeout(timerId);
* // The function will not be executed because the timeout was cleared.
*/
function delay(func, wait, ...args) {
if (typeof func !== "function") throw new TypeError("Expected a function");
return setTimeout(func, require_toNumber.toNumber(wait) || 0, ...args);
}
//#endregion
exports.delay = delay;

View file

@ -0,0 +1,34 @@
import { toNumber } from "../util/toNumber.mjs";
//#region src/compat/function/delay.ts
/**
* Invokes the specified function after a delay of the given number of milliseconds.
* Any additional arguments are passed to the function when it is invoked.
*
* @param func - The function to delay.
* @param wait - The number of milliseconds to delay the invocation.
* @param args - The arguments to pass to the function when it is invoked.
* @returns Returns the timer id.
* @throws {TypeError} If the first argument is not a function.
*
* @example
* // Example 1: Delayed function execution
* const timerId = delay(
* (greeting, recipient) => {
* console.log(`${greeting}, ${recipient}!`);
* },
* 1000,
* 'Hello',
* 'Alice'
* );
* // => 'Hello, Alice!' will be logged after one second.
*
* // Example 2: Clearing the timeout before execution
* clearTimeout(timerId);
* // The function will not be executed because the timeout was cleared.
*/
function delay(func, wait, ...args) {
if (typeof func !== "function") throw new TypeError("Expected a function");
return setTimeout(func, toNumber(wait) || 0, ...args);
}
//#endregion
export { delay };

View file

@ -0,0 +1,19 @@
//#region src/compat/function/flip.d.ts
/**
* Reverses the order of arguments for a given function.
*
* @template T - The type of the function being flipped.
* @param func - The function whose arguments will be reversed.
* @returns A new function that takes the reversed arguments and returns the result of calling `func`.
*
* @example
* var flipped = flip(function() {
* return Array.prototype.slice.call(arguments);
* });
*
* flipped('a', 'b', 'c', 'd');
* // => ['d', 'c', 'b', 'a']
*/
declare function flip<T extends (...args: any) => any>(func: T): T;
//#endregion
export { flip };

View file

@ -0,0 +1,19 @@
//#region src/compat/function/flip.d.ts
/**
* Reverses the order of arguments for a given function.
*
* @template T - The type of the function being flipped.
* @param func - The function whose arguments will be reversed.
* @returns A new function that takes the reversed arguments and returns the result of calling `func`.
*
* @example
* var flipped = flip(function() {
* return Array.prototype.slice.call(arguments);
* });
*
* flipped('a', 'b', 'c', 'd');
* // => ['d', 'c', 'b', 'a']
*/
declare function flip<T extends (...args: any) => any>(func: T): T;
//#endregion
export { flip };

View file

@ -0,0 +1,24 @@
//#region src/compat/function/flip.ts
/**
* Reverses the order of arguments for a given function.
*
* @template F - The type of the function being flipped.
* @param func - The function whose arguments will be reversed.
* @returns A new function that takes the
* reversed arguments and returns the result of calling `func`.
*
* @example
* function fn(a: string, b: string, c: string, d: string) {
* return [a, b, c, d];
* }
*
* const flipped = flip(fn);
* flipped('a', 'b', 'c', 'd'); // => ['d', 'c', 'b', 'a']
*/
function flip(func) {
return function(...args) {
return func.apply(this, args.reverse());
};
}
//#endregion
exports.flip = flip;

View file

@ -0,0 +1,24 @@
//#region src/compat/function/flip.ts
/**
* Reverses the order of arguments for a given function.
*
* @template F - The type of the function being flipped.
* @param func - The function whose arguments will be reversed.
* @returns A new function that takes the
* reversed arguments and returns the result of calling `func`.
*
* @example
* function fn(a: string, b: string, c: string, d: string) {
* return [a, b, c, d];
* }
*
* const flipped = flip(fn);
* flipped('a', 'b', 'c', 'd'); // => ['d', 'c', 'b', 'a']
*/
function flip(func) {
return function(...args) {
return func.apply(this, args.reverse());
};
}
//#endregion
export { flip };

View file

@ -0,0 +1,120 @@
import { Many } from "../_internal/Many.mjs";
//#region src/compat/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.
*
* @template A - The type of the arguments.
* @template R - The type of the return values.
* @param f1 - The first function to invoke.
* @param f2 - The second function to invoke.
* @param f3 - The third function to invoke.
* @param f4 - The fourth function to invoke.
* @param f5 - The fifth function to invoke.
* @param f6 - The sixth function to invoke.
* @param f7 - The seventh function to invoke.
* @returns Returns the new composite function.
*
* @example
* function square(n) {
* return n * n;
* }
*
* var addSquare = flow([add, square]);
* addSquare(1, 2);
* // => 9
*/
declare function flow<A extends any[], R1, R2, R3, R4, R5, R6, R7>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5, f6: (a: R5) => R6, f7: (a: R6) => R7): (...args: A) => R7;
/**
* Creates a new function that executes up to 7 functions in sequence, with additional functions flattened.
* The return value of each function is passed as an argument to the next function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toString = (n: number) => n.toString();
*
* const combined = flow(add, square, double, toString);
* console.log(combined(1, 2)); // "18"
*/
declare function flow<A extends any[], R1, R2, R3, R4, R5, R6, R7>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5, f6: (a: R5) => R6, f7: (a: R6) => R7, ...func: Array<Many<(a: any) => any>>): (...args: A) => any;
/**
* Creates a new function that executes 6 functions in sequence.
* The return value of each function is passed as an argument to the next 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, R4, R5, R6>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5, f6: (a: R5) => R6): (...args: A) => R6;
/**
* Creates a new function that executes 5 functions in sequence.
* The return value of each function is passed as an argument to the next 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, 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 4 functions in sequence.
* The return value of each function is passed as an argument to the next 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, 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 3 functions in sequence.
* The return value of each function is passed as an argument to the next 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 2 functions in sequence.
* The return value of the first function is passed as an argument to the second function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
*
* const addThenSquare = flow(add, square);
* console.log(addThenSquare(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 each function is passed as an argument to the next 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(...func: Array<Many<(...args: any[]) => any>>): (...args: any[]) => any;
//#endregion
export { flow };

View file

@ -0,0 +1,120 @@
import { Many } from "../_internal/Many.js";
//#region src/compat/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.
*
* @template A - The type of the arguments.
* @template R - The type of the return values.
* @param f1 - The first function to invoke.
* @param f2 - The second function to invoke.
* @param f3 - The third function to invoke.
* @param f4 - The fourth function to invoke.
* @param f5 - The fifth function to invoke.
* @param f6 - The sixth function to invoke.
* @param f7 - The seventh function to invoke.
* @returns Returns the new composite function.
*
* @example
* function square(n) {
* return n * n;
* }
*
* var addSquare = flow([add, square]);
* addSquare(1, 2);
* // => 9
*/
declare function flow<A extends any[], R1, R2, R3, R4, R5, R6, R7>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5, f6: (a: R5) => R6, f7: (a: R6) => R7): (...args: A) => R7;
/**
* Creates a new function that executes up to 7 functions in sequence, with additional functions flattened.
* The return value of each function is passed as an argument to the next function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toString = (n: number) => n.toString();
*
* const combined = flow(add, square, double, toString);
* console.log(combined(1, 2)); // "18"
*/
declare function flow<A extends any[], R1, R2, R3, R4, R5, R6, R7>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5, f6: (a: R5) => R6, f7: (a: R6) => R7, ...func: Array<Many<(a: any) => any>>): (...args: A) => any;
/**
* Creates a new function that executes 6 functions in sequence.
* The return value of each function is passed as an argument to the next 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, R4, R5, R6>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5, f6: (a: R5) => R6): (...args: A) => R6;
/**
* Creates a new function that executes 5 functions in sequence.
* The return value of each function is passed as an argument to the next 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, 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 4 functions in sequence.
* The return value of each function is passed as an argument to the next 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, 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 3 functions in sequence.
* The return value of each function is passed as an argument to the next 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 2 functions in sequence.
* The return value of the first function is passed as an argument to the second function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
*
* const addThenSquare = flow(add, square);
* console.log(addThenSquare(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 each function is passed as an argument to the next 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(...func: Array<Many<(...args: any[]) => any>>): (...args: any[]) => any;
//#endregion
export { flow };

View file

@ -0,0 +1,26 @@
const require_flatten = require("../../array/flatten.js");
const require_flow = require("../../function/flow.js");
//#region src/compat/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 double = (n: number) => n * 2;
*
* const combined = flow([add, square], double);
* console.log(combined(1, 2)); // 18
*/
function flow(...funcs) {
const flattenFuncs = require_flatten.flatten(funcs, 1);
if (flattenFuncs.some((func) => typeof func !== "function")) throw new TypeError("Expected a function");
return require_flow.flow(...flattenFuncs);
}
//#endregion
exports.flow = flow;

View file

@ -0,0 +1,26 @@
import { flatten } from "../../array/flatten.mjs";
import { flow as flow$1 } from "../../function/flow.mjs";
//#region src/compat/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 double = (n: number) => n * 2;
*
* const combined = flow([add, square], double);
* console.log(combined(1, 2)); // 18
*/
function flow(...funcs) {
const flattenFuncs = flatten(funcs, 1);
if (flattenFuncs.some((func) => typeof func !== "function")) throw new TypeError("Expected a function");
return flow$1(...flattenFuncs);
}
//#endregion
export { flow };

View file

@ -0,0 +1,118 @@
import { Many } from "../_internal/Many.mjs";
//#region src/compat/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.
*
* @template A - The type of the arguments.
* @template R - The type of the return values.
* @param f7 - The seventh function to invoke.
* @param f6 - The sixth function to invoke.
* @param f5 - The fifth function to invoke.
* @param f4 - The fourth function to invoke.
* @param f3 - The third function to invoke.
* @param f2 - The second function to invoke.
* @param f1 - The first function to invoke.
* @returns Returns the new composite function.
*
* @example
* function square(n) {
* return n * n;
* }
*
* var addSquare = flowRight(square, add);
* addSquare(1, 2);
* // => 9
*/
declare function flowRight<A extends any[], R1, R2, R3, R4, R5, R6, R7>(f7: (a: R6) => R7, f6: (a: R5) => R6, f5: (a: R4) => R5, f4: (a: R3) => R4, f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R7;
/**
* Creates a new function that executes 6 functions in sequence from right to left.
* The return value of each function is passed as an argument to the next function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toString = (n: number) => String(n);
* const append = (s: string) => s + '!';
* const length = (s: string) => s.length;
*
* const combined = flowRight(length, append, toString, double, square, add);
* console.log(combined(1, 2)); // 7
*/
declare function flowRight<A extends any[], R1, R2, R3, R4, R5, R6>(f6: (a: R5) => R6, f5: (a: R4) => R5, f4: (a: R3) => R4, f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R6;
/**
* Creates a new function that executes 5 functions in sequence from right to left.
* The return value of each function is passed as an argument to the next function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toString = (n: number) => String(n);
* const append = (s: string) => s + '!';
*
* const combined = flowRight(append, toString, double, square, add);
* console.log(combined(1, 2)); // '18!'
*/
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 4 functions in sequence from right to left.
* The return value of each function is passed as an argument to the next function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toString = (n: number) => String(n);
*
* const combined = flowRight(toString, 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 3 functions in sequence from right to left.
* The return value of each function is passed as an argument to the next 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 2 functions in sequence from right to left.
* The return value of the first function is passed as an argument to the second 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 each function is passed as an argument to the next function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toString = (n: number) => String(n);
*
* // Pass functions as separate arguments
* const combined1 = flowRight(toString, double, square, add);
* console.log(combined1(1, 2)); // '18'
*
* // Pass functions as arrays
* const combined2 = flowRight([toString, double], [square, add]);
* console.log(combined2(1, 2)); // '18'
*/
declare function flowRight(...func: Array<Many<(...args: any[]) => any>>): (...args: any[]) => any;
//#endregion
export { flowRight };

View file

@ -0,0 +1,118 @@
import { Many } from "../_internal/Many.js";
//#region src/compat/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.
*
* @template A - The type of the arguments.
* @template R - The type of the return values.
* @param f7 - The seventh function to invoke.
* @param f6 - The sixth function to invoke.
* @param f5 - The fifth function to invoke.
* @param f4 - The fourth function to invoke.
* @param f3 - The third function to invoke.
* @param f2 - The second function to invoke.
* @param f1 - The first function to invoke.
* @returns Returns the new composite function.
*
* @example
* function square(n) {
* return n * n;
* }
*
* var addSquare = flowRight(square, add);
* addSquare(1, 2);
* // => 9
*/
declare function flowRight<A extends any[], R1, R2, R3, R4, R5, R6, R7>(f7: (a: R6) => R7, f6: (a: R5) => R6, f5: (a: R4) => R5, f4: (a: R3) => R4, f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R7;
/**
* Creates a new function that executes 6 functions in sequence from right to left.
* The return value of each function is passed as an argument to the next function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toString = (n: number) => String(n);
* const append = (s: string) => s + '!';
* const length = (s: string) => s.length;
*
* const combined = flowRight(length, append, toString, double, square, add);
* console.log(combined(1, 2)); // 7
*/
declare function flowRight<A extends any[], R1, R2, R3, R4, R5, R6>(f6: (a: R5) => R6, f5: (a: R4) => R5, f4: (a: R3) => R4, f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R6;
/**
* Creates a new function that executes 5 functions in sequence from right to left.
* The return value of each function is passed as an argument to the next function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toString = (n: number) => String(n);
* const append = (s: string) => s + '!';
*
* const combined = flowRight(append, toString, double, square, add);
* console.log(combined(1, 2)); // '18!'
*/
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 4 functions in sequence from right to left.
* The return value of each function is passed as an argument to the next function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toString = (n: number) => String(n);
*
* const combined = flowRight(toString, 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 3 functions in sequence from right to left.
* The return value of each function is passed as an argument to the next 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 2 functions in sequence from right to left.
* The return value of the first function is passed as an argument to the second 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 each function is passed as an argument to the next function.
*
* @example
* const add = (x: number, y: number) => x + y;
* const square = (n: number) => n * n;
* const double = (n: number) => n * 2;
* const toString = (n: number) => String(n);
*
* // Pass functions as separate arguments
* const combined1 = flowRight(toString, double, square, add);
* console.log(combined1(1, 2)); // '18'
*
* // Pass functions as arrays
* const combined2 = flowRight([toString, double], [square, add]);
* console.log(combined2(1, 2)); // '18'
*/
declare function flowRight(...func: Array<Many<(...args: any[]) => any>>): (...args: any[]) => any;
//#endregion
export { flowRight };

View file

@ -0,0 +1,28 @@
const require_flatten = require("../../array/flatten.js");
const require_flowRight = require("../../function/flowRight.js");
//#region src/compat/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 double = (n: number) => n * 2;
*
* const combined = flowRight(double, [square, add]);
* console.log(combined(1, 2)); // 18
*/
function flowRight(...funcs) {
const flattenFuncs = require_flatten.flatten(funcs, 1);
if (flattenFuncs.some((func) => typeof func !== "function")) throw new TypeError("Expected a function");
return require_flowRight.flowRight(...flattenFuncs);
}
//#endregion
exports.flowRight = flowRight;

View file

@ -0,0 +1,28 @@
import { flatten } from "../../array/flatten.mjs";
import { flowRight as flowRight$1 } from "../../function/flowRight.mjs";
//#region src/compat/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 double = (n: number) => n * 2;
*
* const combined = flowRight(double, [square, add]);
* console.log(combined(1, 2)); // 18
*/
function flowRight(...funcs) {
const flattenFuncs = flatten(funcs, 1);
if (flattenFuncs.some((func) => typeof func !== "function")) throw new TypeError("Expected a function");
return flowRight$1(...flattenFuncs);
}
//#endregion
export { flowRight };

View file

@ -0,0 +1,43 @@
//#region src/compat/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>(value: T): T;
/**
* 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(): undefined;
//#endregion
export { identity };

View file

@ -0,0 +1,43 @@
//#region src/compat/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>(value: T): T;
/**
* 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(): undefined;
//#endregion
export { identity };

View file

@ -0,0 +1,6 @@
//#region src/compat/function/identity.ts
function identity(x) {
return x;
}
//#endregion
exports.identity = identity;

View file

@ -0,0 +1,6 @@
//#region src/compat/function/identity.ts
function identity(x) {
return x;
}
//#endregion
export { identity };

View file

@ -0,0 +1,120 @@
//#region src/compat/function/memoize.d.ts
interface MapCache {
/**
* Removes the value associated with the specified key from the cache.
*
* @param key - The key of the value to remove
* @returns `true` if an element was removed, `false` if the key wasn't found
*
* @example
* ```typescript
* cache.set('user', { id: 123, name: 'John' });
* cache.delete('user'); // Returns true
* cache.delete('unknown'); // Returns false
* ```
*/
delete(key: any): boolean;
/**
* Retrieves the value associated with the specified key from the cache.
*
* @param key - The key of the value to retrieve
* @returns The cached value or undefined if not found
*
* @example
* ```typescript
* cache.set('user', { id: 123, name: 'John' });
* cache.get('user'); // Returns { id: 123, name: 'John' }
* cache.get('unknown'); // Returns undefined
* ```
*/
get(key: any): any;
/**
* Checks if the cache contains a value for the specified key.
*
* @param key - The key to check for existence
* @returns `true` if the key exists in the cache, otherwise `false`
*
* @example
* ```typescript
* cache.set('user', { id: 123, name: 'John' });
* cache.has('user'); // Returns true
* cache.has('unknown'); // Returns false
* ```
*/
has(key: any): boolean;
/**
* Stores a value in the cache with the specified key.
* If the key already exists, its value is updated.
*
* @param key - The key to associate with the value
* @param value - The value to store in the cache
* @returns The cache instance for method chaining
*
* @example
* ```typescript
* cache.set('user', { id: 123, name: 'John' })
* .set('settings', { theme: 'dark' });
* ```
*/
set(key: any, value: any): this;
/**
* Removes all key-value pairs from the cache.
* This method is optional as some cache implementations may be immutable.
*
* @example
* ```typescript
* cache.set('user', { id: 123, name: 'John' });
* cache.set('settings', { theme: 'dark' });
* cache.clear(); // Cache is now empty
* ```
*/
clear?(): void;
}
/**
* Constructor interface for creating a new MapCache instance.
* This defines the shape of a constructor that can create cache objects
* conforming to the MapCache interface.
*
* @example
* ```typescript
* class CustomCache implements MapCache {
* // Cache implementation
* }
*
* const CacheConstructor: MapCacheConstructor = CustomCache;
* const cache = new CacheConstructor();
* ```
*/
interface MapCacheConstructor {
new (): MapCache;
}
/**
* Represents a function that has been memoized.
* A memoized function maintains the same signature as the original function
* but adds a cache property to store previously computed results.
*
* @template T - The type of the original function being memoized
*/
interface MemoizedFunction {
/**
* The cache storing previously computed results
*/
cache: MapCache;
}
/**
* Creates a function that memoizes the result of func. If resolver is provided it determines the cache key for
* storing the result based on the arguments provided to the memoized function. By default, the first argument
* provided to the memoized function is coerced to a string and used as the cache key. The func is invoked with
* the this binding of the memoized function.
*
* @template T - The type of the original function being memoized
* @param func The function to have its output memoized.
* @param [resolver] The function to resolve the cache key.
* @return {MemoizedFunction<T>} Returns the new memoizing function.
*/
declare function memoize<T extends (...args: any) => any>(func: T, resolver?: (...args: Parameters<T>) => any): T & MemoizedFunction;
declare namespace memoize {
var Cache: MapCacheConstructor;
}
//#endregion
export { memoize };

View file

@ -0,0 +1,120 @@
//#region src/compat/function/memoize.d.ts
interface MapCache {
/**
* Removes the value associated with the specified key from the cache.
*
* @param key - The key of the value to remove
* @returns `true` if an element was removed, `false` if the key wasn't found
*
* @example
* ```typescript
* cache.set('user', { id: 123, name: 'John' });
* cache.delete('user'); // Returns true
* cache.delete('unknown'); // Returns false
* ```
*/
delete(key: any): boolean;
/**
* Retrieves the value associated with the specified key from the cache.
*
* @param key - The key of the value to retrieve
* @returns The cached value or undefined if not found
*
* @example
* ```typescript
* cache.set('user', { id: 123, name: 'John' });
* cache.get('user'); // Returns { id: 123, name: 'John' }
* cache.get('unknown'); // Returns undefined
* ```
*/
get(key: any): any;
/**
* Checks if the cache contains a value for the specified key.
*
* @param key - The key to check for existence
* @returns `true` if the key exists in the cache, otherwise `false`
*
* @example
* ```typescript
* cache.set('user', { id: 123, name: 'John' });
* cache.has('user'); // Returns true
* cache.has('unknown'); // Returns false
* ```
*/
has(key: any): boolean;
/**
* Stores a value in the cache with the specified key.
* If the key already exists, its value is updated.
*
* @param key - The key to associate with the value
* @param value - The value to store in the cache
* @returns The cache instance for method chaining
*
* @example
* ```typescript
* cache.set('user', { id: 123, name: 'John' })
* .set('settings', { theme: 'dark' });
* ```
*/
set(key: any, value: any): this;
/**
* Removes all key-value pairs from the cache.
* This method is optional as some cache implementations may be immutable.
*
* @example
* ```typescript
* cache.set('user', { id: 123, name: 'John' });
* cache.set('settings', { theme: 'dark' });
* cache.clear(); // Cache is now empty
* ```
*/
clear?(): void;
}
/**
* Constructor interface for creating a new MapCache instance.
* This defines the shape of a constructor that can create cache objects
* conforming to the MapCache interface.
*
* @example
* ```typescript
* class CustomCache implements MapCache {
* // Cache implementation
* }
*
* const CacheConstructor: MapCacheConstructor = CustomCache;
* const cache = new CacheConstructor();
* ```
*/
interface MapCacheConstructor {
new (): MapCache;
}
/**
* Represents a function that has been memoized.
* A memoized function maintains the same signature as the original function
* but adds a cache property to store previously computed results.
*
* @template T - The type of the original function being memoized
*/
interface MemoizedFunction {
/**
* The cache storing previously computed results
*/
cache: MapCache;
}
/**
* Creates a function that memoizes the result of func. If resolver is provided it determines the cache key for
* storing the result based on the arguments provided to the memoized function. By default, the first argument
* provided to the memoized function is coerced to a string and used as the cache key. The func is invoked with
* the this binding of the memoized function.
*
* @template T - The type of the original function being memoized
* @param func The function to have its output memoized.
* @param [resolver] The function to resolve the cache key.
* @return {MemoizedFunction<T>} Returns the new memoizing function.
*/
declare function memoize<T extends (...args: any) => any>(func: T, resolver?: (...args: Parameters<T>) => any): T & MemoizedFunction;
declare namespace memoize {
var Cache: MapCacheConstructor;
}
//#endregion
export { memoize };

View file

@ -0,0 +1,28 @@
//#region src/compat/function/memoize.ts
/**
* Creates a function that memoizes the result of func. If resolver is provided it determines the cache key for
* storing the result based on the arguments provided to the memoized function. By default, the first argument
* provided to the memoized function is coerced to a string and used as the cache key. The func is invoked with
* the this binding of the memoized function.
*
* @template T - The type of the original function being memoized
* @param func The function to have its output memoized.
* @param [resolver] The function to resolve the cache key.
* @return {MemoizedFunction<T>} Returns the new memoizing function.
*/
function memoize(func, resolver) {
if (typeof func !== "function" || resolver != null && typeof resolver !== "function") throw new TypeError("Expected a function");
const memoized = function(...args) {
const key = resolver ? resolver.apply(this, args) : args[0];
const cache = memoized.cache;
if (cache.has(key)) return cache.get(key);
const result = func.apply(this, args);
memoized.cache = cache.set(key, result) || cache;
return result;
};
memoized.cache = new (memoize.Cache || Map)();
return memoized;
}
memoize.Cache = Map;
//#endregion
exports.memoize = memoize;

View file

@ -0,0 +1,28 @@
//#region src/compat/function/memoize.ts
/**
* Creates a function that memoizes the result of func. If resolver is provided it determines the cache key for
* storing the result based on the arguments provided to the memoized function. By default, the first argument
* provided to the memoized function is coerced to a string and used as the cache key. The func is invoked with
* the this binding of the memoized function.
*
* @template T - The type of the original function being memoized
* @param func The function to have its output memoized.
* @param [resolver] The function to resolve the cache key.
* @return {MemoizedFunction<T>} Returns the new memoizing function.
*/
function memoize(func, resolver) {
if (typeof func !== "function" || resolver != null && typeof resolver !== "function") throw new TypeError("Expected a function");
const memoized = function(...args) {
const key = resolver ? resolver.apply(this, args) : args[0];
const cache = memoized.cache;
if (cache.has(key)) return cache.get(key);
const result = func.apply(this, args);
memoized.cache = cache.set(key, result) || cache;
return result;
};
memoized.cache = new (memoize.Cache || Map)();
return memoized;
}
memoize.Cache = Map;
//#endregion
export { memoize };

View file

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

View file

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

View file

@ -0,0 +1,22 @@
//#region src/compat/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) {
if (typeof func !== "function") throw new TypeError("Expected a function");
return function(...args) {
return !func.apply(this, args);
};
}
//#endregion
exports.negate = negate;

View file

@ -0,0 +1,22 @@
//#region src/compat/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) {
if (typeof func !== "function") throw new TypeError("Expected a function");
return function(...args) {
return !func.apply(this, args);
};
}
//#endregion
export { negate };

View file

@ -0,0 +1,13 @@
//#region src/compat/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(..._: any[]): void;
//#endregion
export { noop };

View file

@ -0,0 +1,13 @@
//#region src/compat/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(..._: any[]): void;
//#endregion
export { noop };

View file

@ -0,0 +1,13 @@
//#region src/compat/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/compat/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,19 @@
//#region src/compat/function/nthArg.d.ts
/**
* Creates a function that gets the argument at index `n`. If `n` is negative, the nth argument from the end is returned.
*
* @param [n=0] - The index of the argument to return.
* @returns Returns the new function.
*
* @example
* var func = nthArg(1);
* func('a', 'b', 'c', 'd');
* // => 'b'
*
* var func = nthArg(-2);
* func('a', 'b', 'c', 'd');
* // => 'c'
*/
declare function nthArg(n?: number): (...args: any[]) => any;
//#endregion
export { nthArg };

View file

@ -0,0 +1,19 @@
//#region src/compat/function/nthArg.d.ts
/**
* Creates a function that gets the argument at index `n`. If `n` is negative, the nth argument from the end is returned.
*
* @param [n=0] - The index of the argument to return.
* @returns Returns the new function.
*
* @example
* var func = nthArg(1);
* func('a', 'b', 'c', 'd');
* // => 'b'
*
* var func = nthArg(-2);
* func('a', 'b', 'c', 'd');
* // => 'c'
*/
declare function nthArg(n?: number): (...args: any[]) => any;
//#endregion
export { nthArg };

View file

@ -0,0 +1,28 @@
const require_toInteger = require("../util/toInteger.js");
//#region src/compat/function/nthArg.ts
/**
* Creates a function that retrieves the argument at the specified index `n`.
*
* If `n` is negative, the nth argument from the end is returned.
*
* @param [n=0] - The index of the argument to retrieve.
* If negative, counts from the end of the arguments list.
* @returns A new function that returns the argument at the specified index.
*
* @example
* const getSecondArg = nthArg(1);
* const result = getSecondArg('a', 'b', 'c');
* console.log(result); // => 'b'
*
* @example
* const getLastArg = nthArg(-1);
* const result = getLastArg('a', 'b', 'c');
* console.log(result); // => 'c'
*/
function nthArg(n = 0) {
return function(...args) {
return args.at(require_toInteger.toInteger(n));
};
}
//#endregion
exports.nthArg = nthArg;

View file

@ -0,0 +1,28 @@
import { toInteger } from "../util/toInteger.mjs";
//#region src/compat/function/nthArg.ts
/**
* Creates a function that retrieves the argument at the specified index `n`.
*
* If `n` is negative, the nth argument from the end is returned.
*
* @param [n=0] - The index of the argument to retrieve.
* If negative, counts from the end of the arguments list.
* @returns A new function that returns the argument at the specified index.
*
* @example
* const getSecondArg = nthArg(1);
* const result = getSecondArg('a', 'b', 'c');
* console.log(result); // => 'b'
*
* @example
* const getLastArg = nthArg(-1);
* const result = getLastArg('a', 'b', 'c');
* console.log(result); // => 'c'
*/
function nthArg(n = 0) {
return function(...args) {
return args.at(toInteger(n));
};
}
//#endregion
export { nthArg };

View file

@ -0,0 +1,4 @@
//#region src/compat/function/once.d.ts
declare function once<T extends (...args: any) => any>(func: T): T;
//#endregion
export { once };

View file

@ -0,0 +1,4 @@
//#region src/compat/function/once.d.ts
declare function once<T extends (...args: any) => any>(func: T): T;
//#endregion
export { once };

View file

@ -0,0 +1,7 @@
const require_once = require("../../function/once.js");
//#region src/compat/function/once.ts
function once(func) {
return require_once.once(func);
}
//#endregion
exports.once = once;

View file

@ -0,0 +1,7 @@
import { once as once$1 } from "../../function/once.mjs";
//#region src/compat/function/once.ts
function once(func) {
return once$1(func);
}
//#endregion
export { once };

View file

@ -0,0 +1,51 @@
import { Many } from "../_internal/Many.mjs";
//#region src/compat/function/overArgs.d.ts
/**
* Creates a function that invokes `func` with its arguments transformed by corresponding transform functions.
*
* Transform functions can be:
* - Functions that accept and return a value
* - Property names (strings) to get a property value from each argument
* - Objects to check if arguments match the object properties
* - Arrays of [property, value] to check if argument properties match values
*
* If a transform is nullish, the identity function is used instead.
* Only transforms arguments up to the number of transform functions provided.
*
* @param func - The function to wrap
* @param transforms - The functions to transform arguments. Each transform can be:
* - A function that accepts and returns a value
* - A string to get a property value (e.g. 'name' gets the name property)
* - An object to check if arguments match its properties
* - An array of [property, value] to check property matches
* @returns A new function that transforms arguments before passing them to func
* @throws {TypeError} If func is not a function.
* @example
* ```ts
* function doubled(n: number) {
* return n * 2;
* }
*
* function square(n: number) {
* return n * n;
* }
*
* const func = overArgs((x, y) => [x, y], [doubled, square]);
*
* func(5, 3);
* // => [10, 9]
*
* // With property shorthand
* const user = { name: 'John', age: 30 };
* const getUserInfo = overArgs(
* (name, age) => `${name} is ${age} years old`,
* ['name', 'age']
* );
* getUserInfo(user, user);
* // => "John is 30 years old"
* ```
*/
declare function overArgs(func: (...args: any[]) => any, ..._transforms: Array<Many<(...args: any[]) => any>>): (...args: any[]) => any;
//#endregion
export { overArgs };

View file

@ -0,0 +1,51 @@
import { Many } from "../_internal/Many.js";
//#region src/compat/function/overArgs.d.ts
/**
* Creates a function that invokes `func` with its arguments transformed by corresponding transform functions.
*
* Transform functions can be:
* - Functions that accept and return a value
* - Property names (strings) to get a property value from each argument
* - Objects to check if arguments match the object properties
* - Arrays of [property, value] to check if argument properties match values
*
* If a transform is nullish, the identity function is used instead.
* Only transforms arguments up to the number of transform functions provided.
*
* @param func - The function to wrap
* @param transforms - The functions to transform arguments. Each transform can be:
* - A function that accepts and returns a value
* - A string to get a property value (e.g. 'name' gets the name property)
* - An object to check if arguments match its properties
* - An array of [property, value] to check property matches
* @returns A new function that transforms arguments before passing them to func
* @throws {TypeError} If func is not a function.
* @example
* ```ts
* function doubled(n: number) {
* return n * 2;
* }
*
* function square(n: number) {
* return n * n;
* }
*
* const func = overArgs((x, y) => [x, y], [doubled, square]);
*
* func(5, 3);
* // => [10, 9]
*
* // With property shorthand
* const user = { name: 'John', age: 30 };
* const getUserInfo = overArgs(
* (name, age) => `${name} is ${age} years old`,
* ['name', 'age']
* );
* getUserInfo(user, user);
* // => "John is 30 years old"
* ```
*/
declare function overArgs(func: (...args: any[]) => any, ..._transforms: Array<Many<(...args: any[]) => any>>): (...args: any[]) => any;
//#endregion
export { overArgs };

View file

@ -0,0 +1,60 @@
const require_identity = require("../../function/identity.js");
const require_iteratee = require("../util/iteratee.js");
//#region src/compat/function/overArgs.ts
/**
* Creates a function that invokes `func` with its arguments transformed by corresponding transform functions.
*
* Transform functions can be:
* - Functions that accept and return a value
* - Property names (strings) to get a property value from each argument
* - Objects to check if arguments match the object properties
* - Arrays of [property, value] to check if argument properties match values
*
* If a transform is nullish, the identity function is used instead.
* Only transforms arguments up to the number of transform functions provided.
*
* @param func - The function to wrap
* @param transforms - The functions to transform arguments. Each transform can be:
* - A function that accepts and returns a value
* - A string to get a property value (e.g. 'name' gets the name property)
* - An object to check if arguments match its properties
* - An array of [property, value] to check property matches
* @returns A new function that transforms arguments before passing them to func
* @throws {TypeError} If func is not a function.
* @example
* ```ts
* function doubled(n: number) {
* return n * 2;
* }
*
* function square(n: number) {
* return n * n;
* }
*
* const func = overArgs((x, y) => [x, y], [doubled, square]);
*
* func(5, 3);
* // => [10, 9]
*
* // With property shorthand
* const user = { name: 'John', age: 30 };
* const getUserInfo = overArgs(
* (name, age) => `${name} is ${age} years old`,
* ['name', 'age']
* );
* getUserInfo(user, user);
* // => "John is 30 years old"
* ```
*/
function overArgs(func, ..._transforms) {
if (typeof func !== "function") throw new TypeError("Expected a function");
const transforms = _transforms.flat();
return function(...args) {
const length = Math.min(args.length, transforms.length);
const transformedArgs = [...args];
for (let i = 0; i < length; i++) transformedArgs[i] = require_iteratee.iteratee(transforms[i] ?? require_identity.identity).call(this, args[i]);
return func.apply(this, transformedArgs);
};
}
//#endregion
exports.overArgs = overArgs;

View file

@ -0,0 +1,60 @@
import { identity } from "../../function/identity.mjs";
import { iteratee } from "../util/iteratee.mjs";
//#region src/compat/function/overArgs.ts
/**
* Creates a function that invokes `func` with its arguments transformed by corresponding transform functions.
*
* Transform functions can be:
* - Functions that accept and return a value
* - Property names (strings) to get a property value from each argument
* - Objects to check if arguments match the object properties
* - Arrays of [property, value] to check if argument properties match values
*
* If a transform is nullish, the identity function is used instead.
* Only transforms arguments up to the number of transform functions provided.
*
* @param func - The function to wrap
* @param transforms - The functions to transform arguments. Each transform can be:
* - A function that accepts and returns a value
* - A string to get a property value (e.g. 'name' gets the name property)
* - An object to check if arguments match its properties
* - An array of [property, value] to check property matches
* @returns A new function that transforms arguments before passing them to func
* @throws {TypeError} If func is not a function.
* @example
* ```ts
* function doubled(n: number) {
* return n * 2;
* }
*
* function square(n: number) {
* return n * n;
* }
*
* const func = overArgs((x, y) => [x, y], [doubled, square]);
*
* func(5, 3);
* // => [10, 9]
*
* // With property shorthand
* const user = { name: 'John', age: 30 };
* const getUserInfo = overArgs(
* (name, age) => `${name} is ${age} years old`,
* ['name', 'age']
* );
* getUserInfo(user, user);
* // => "John is 30 years old"
* ```
*/
function overArgs(func, ..._transforms) {
if (typeof func !== "function") throw new TypeError("Expected a function");
const transforms = _transforms.flat();
return function(...args) {
const length = Math.min(args.length, transforms.length);
const transformedArgs = [...args];
for (let i = 0; i < length; i++) transformedArgs[i] = iteratee(transforms[i] ?? identity).call(this, args[i]);
return func.apply(this, transformedArgs);
};
}
//#endregion
export { overArgs };

View file

@ -0,0 +1,205 @@
import { Toolkit } from "../toolkit.mjs";
//#region src/compat/function/partial.d.ts
type __ = Placeholder | Toolkit;
/**
* 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.
*
* @example
* const greet = (greeting: string, name: string) => `${greeting} ${name}`;
* const sayHello = partial(greet, _, 'world');
* console.log(sayHello('Hello')); // => 'Hello world'
*/
declare function partial<T1, T2, R>(func: (t1: T1, t2: T2) => R, plc1: __, arg2: T2): (t1: 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.
*
* @example
* const calculate = (x: number, y: number, z: number) => x + y + z;
* const addToY = partial(calculate, _, 2);
* console.log(addToY(1, 3)); // => 6
*/
declare function partial<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, plc1: __, arg2: T2): (t1: T1, t3: 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.
*
* @example
* const calculate = (x: number, y: number, z: number) => x + y + z;
* const addZ = partial(calculate, _, _, 3);
* console.log(addZ(1, 2)); // => 6
*/
declare function partial<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, plc1: __, plc2: __, arg3: T3): (t1: T1, t2: 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.
*
* @example
* const calculate = (x: number, y: number, z: number) => x + y + z;
* const withXandZ = partial(calculate, 1, _, 3);
* console.log(withXandZ(2)); // => 6
*/
declare function partial<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg1: T1, plc2: __, arg3: T3): (t2: 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.
*
* @example
* const calculate = (x: number, y: number, z: number) => x + y + z;
* const withYandZ = partial(calculate, _, 2, 3);
* console.log(withYandZ(1)); // => 6
*/
declare function partial<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, plc1: __, arg2: T2, arg3: T3): (t1: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withB = partial(format, _, 'b');
* console.log(withB('a', 'c', 'd')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, arg2: T2): (t1: T1, t3: T3, t4: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withC = partial(format, _, _, 'c');
* console.log(withC('a', 'b', 'd')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, plc2: __, arg3: T3): (t1: T1, t2: T2, t4: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withAandC = partial(format, 'a', _, 'c');
* console.log(withAandC('b', 'd')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, arg3: T3): (t2: T2, t4: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withBandC = partial(format, _, 'b', 'c');
* console.log(withBandC('a', 'd')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, arg2: T2, arg3: T3): (t1: T1, t4: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withD = partial(format, _, _, _, 'd');
* console.log(withD('a', 'b', 'c')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, plc2: __, plc3: __, arg4: T4): (t1: T1, t2: T2, t3: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withAandD = partial(format, 'a', _, _, 'd');
* console.log(withAandD('b', 'c')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, plc3: __, arg4: T4): (t2: T2, t3: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withBandD = partial(format, _, 'b', _, 'd');
* console.log(withBandD('a', 'c')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, arg2: T2, plc3: __, arg4: T4): (t1: T1, t3: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withABandD = partial(format, 'a', 'b', _, 'd');
* console.log(withABandD('c')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, arg2: T2, plc3: __, arg4: T4): (t3: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withCandD = partial(format, _, _, 'c', 'd');
* console.log(withCandD('a', 'b')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, plc2: __, arg3: T3, arg4: T4): (t1: T1, t2: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withACandD = partial(format, 'a', _, 'c', 'd');
* console.log(withACandD('b')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, arg3: T3, arg4: T4): (t2: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withBCandD = partial(format, _, 'b', 'c', 'd');
* console.log(withBCandD('a')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, arg2: T2, arg3: T3, arg4: T4): (t1: 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.
*
* @example
* const sum = (...numbers: number[]) => numbers.reduce((a, b) => a + b, 0);
* const partialSum = partial(sum);
* console.log(partialSum(1, 2, 3)); // => 6
*/
declare function partial<TS extends any[], R>(func: (...ts: TS) => R): (...ts: 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.
*
* @example
* const log = (prefix: string, ...messages: string[]) => console.log(prefix, ...messages);
* const debugLog = partial(log, '[DEBUG]');
* debugLog('message 1', 'message 2'); // => '[DEBUG] message 1 message 2'
*/
declare function partial<TS extends any[], T1, R>(func: (t1: T1, ...ts: TS) => R, arg1: T1): (...ts: 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.
*
* @example
* const format = (prefix: string, separator: string, ...messages: string[]) => `${prefix}${messages.join(separator)}`;
* const logWithPrefix = partial(format, '[LOG]', ' - ');
* console.log(logWithPrefix('msg1', 'msg2')); // => '[LOG]msg1 - msg2'
*/
declare function partial<TS extends any[], T1, T2, R>(func: (t1: T1, t2: T2, ...ts: TS) => R, t1: T1, t2: T2): (...ts: 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.
*
* @example
* const format = (type: string, level: string, message: string, ...tags: string[]) =>
* `[${type}][${level}] ${message} ${tags.join(',')}`;
* const errorLog = partial(format, 'ERROR', 'HIGH', 'Something went wrong');
* console.log(errorLog('critical', 'urgent')); // => '[ERROR][HIGH] Something went wrong critical,urgent'
*/
declare function partial<TS extends any[], T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3, ...ts: TS) => R, t1: T1, t2: T2, t3: T3): (...ts: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string, ...rest: string[]) =>
* `${a}-${b}-${c}-${d}:${rest.join(',')}`;
* const prefixedFormat = partial(format, 'a', 'b', 'c', 'd');
* console.log(prefixedFormat('e', 'f')); // => 'a-b-c-d:e,f'
*/
declare function partial<TS extends any[], T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, ...ts: TS) => R, t1: T1, t2: T2, t3: T3, t4: T4): (...ts: TS) => R;
declare namespace partial {
var placeholder: Placeholder;
}
type Placeholder = symbol | (((value: any) => any) & {
partial: typeof partial;
});
//#endregion
export { partial };

View file

@ -0,0 +1,205 @@
import { Toolkit } from "../toolkit.js";
//#region src/compat/function/partial.d.ts
type __ = Placeholder | Toolkit;
/**
* 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.
*
* @example
* const greet = (greeting: string, name: string) => `${greeting} ${name}`;
* const sayHello = partial(greet, _, 'world');
* console.log(sayHello('Hello')); // => 'Hello world'
*/
declare function partial<T1, T2, R>(func: (t1: T1, t2: T2) => R, plc1: __, arg2: T2): (t1: 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.
*
* @example
* const calculate = (x: number, y: number, z: number) => x + y + z;
* const addToY = partial(calculate, _, 2);
* console.log(addToY(1, 3)); // => 6
*/
declare function partial<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, plc1: __, arg2: T2): (t1: T1, t3: 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.
*
* @example
* const calculate = (x: number, y: number, z: number) => x + y + z;
* const addZ = partial(calculate, _, _, 3);
* console.log(addZ(1, 2)); // => 6
*/
declare function partial<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, plc1: __, plc2: __, arg3: T3): (t1: T1, t2: 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.
*
* @example
* const calculate = (x: number, y: number, z: number) => x + y + z;
* const withXandZ = partial(calculate, 1, _, 3);
* console.log(withXandZ(2)); // => 6
*/
declare function partial<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg1: T1, plc2: __, arg3: T3): (t2: 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.
*
* @example
* const calculate = (x: number, y: number, z: number) => x + y + z;
* const withYandZ = partial(calculate, _, 2, 3);
* console.log(withYandZ(1)); // => 6
*/
declare function partial<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, plc1: __, arg2: T2, arg3: T3): (t1: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withB = partial(format, _, 'b');
* console.log(withB('a', 'c', 'd')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, arg2: T2): (t1: T1, t3: T3, t4: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withC = partial(format, _, _, 'c');
* console.log(withC('a', 'b', 'd')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, plc2: __, arg3: T3): (t1: T1, t2: T2, t4: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withAandC = partial(format, 'a', _, 'c');
* console.log(withAandC('b', 'd')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, arg3: T3): (t2: T2, t4: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withBandC = partial(format, _, 'b', 'c');
* console.log(withBandC('a', 'd')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, arg2: T2, arg3: T3): (t1: T1, t4: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withD = partial(format, _, _, _, 'd');
* console.log(withD('a', 'b', 'c')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, plc2: __, plc3: __, arg4: T4): (t1: T1, t2: T2, t3: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withAandD = partial(format, 'a', _, _, 'd');
* console.log(withAandD('b', 'c')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, plc3: __, arg4: T4): (t2: T2, t3: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withBandD = partial(format, _, 'b', _, 'd');
* console.log(withBandD('a', 'c')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, arg2: T2, plc3: __, arg4: T4): (t1: T1, t3: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withABandD = partial(format, 'a', 'b', _, 'd');
* console.log(withABandD('c')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, arg2: T2, plc3: __, arg4: T4): (t3: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withCandD = partial(format, _, _, 'c', 'd');
* console.log(withCandD('a', 'b')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, plc2: __, arg3: T3, arg4: T4): (t1: T1, t2: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withACandD = partial(format, 'a', _, 'c', 'd');
* console.log(withACandD('b')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, arg3: T3, arg4: T4): (t2: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
* const withBCandD = partial(format, _, 'b', 'c', 'd');
* console.log(withBCandD('a')); // => 'a-b-c-d'
*/
declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, arg2: T2, arg3: T3, arg4: T4): (t1: 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.
*
* @example
* const sum = (...numbers: number[]) => numbers.reduce((a, b) => a + b, 0);
* const partialSum = partial(sum);
* console.log(partialSum(1, 2, 3)); // => 6
*/
declare function partial<TS extends any[], R>(func: (...ts: TS) => R): (...ts: 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.
*
* @example
* const log = (prefix: string, ...messages: string[]) => console.log(prefix, ...messages);
* const debugLog = partial(log, '[DEBUG]');
* debugLog('message 1', 'message 2'); // => '[DEBUG] message 1 message 2'
*/
declare function partial<TS extends any[], T1, R>(func: (t1: T1, ...ts: TS) => R, arg1: T1): (...ts: 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.
*
* @example
* const format = (prefix: string, separator: string, ...messages: string[]) => `${prefix}${messages.join(separator)}`;
* const logWithPrefix = partial(format, '[LOG]', ' - ');
* console.log(logWithPrefix('msg1', 'msg2')); // => '[LOG]msg1 - msg2'
*/
declare function partial<TS extends any[], T1, T2, R>(func: (t1: T1, t2: T2, ...ts: TS) => R, t1: T1, t2: T2): (...ts: 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.
*
* @example
* const format = (type: string, level: string, message: string, ...tags: string[]) =>
* `[${type}][${level}] ${message} ${tags.join(',')}`;
* const errorLog = partial(format, 'ERROR', 'HIGH', 'Something went wrong');
* console.log(errorLog('critical', 'urgent')); // => '[ERROR][HIGH] Something went wrong critical,urgent'
*/
declare function partial<TS extends any[], T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3, ...ts: TS) => R, t1: T1, t2: T2, t3: T3): (...ts: 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.
*
* @example
* const format = (a: string, b: string, c: string, d: string, ...rest: string[]) =>
* `${a}-${b}-${c}-${d}:${rest.join(',')}`;
* const prefixedFormat = partial(format, 'a', 'b', 'c', 'd');
* console.log(prefixedFormat('e', 'f')); // => 'a-b-c-d:e,f'
*/
declare function partial<TS extends any[], T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, ...ts: TS) => R, t1: T1, t2: T2, t3: T3, t4: T4): (...ts: TS) => R;
declare namespace partial {
var placeholder: Placeholder;
}
type Placeholder = symbol | (((value: any) => any) & {
partial: typeof partial;
});
//#endregion
export { partial };

View file

@ -0,0 +1,34 @@
const require_partial = require("../../function/partial.js");
//#region src/compat/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 require_partial.partialImpl(func, partial.placeholder, ...partialArgs);
}
partial.placeholder = Symbol("compat.partial.placeholder");
//#endregion
exports.partial = partial;

View file

@ -0,0 +1,34 @@
import { partialImpl } from "../../function/partial.mjs";
//#region src/compat/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, partial.placeholder, ...partialArgs);
}
partial.placeholder = Symbol("compat.partial.placeholder");
//#endregion
export { partial };

View file

@ -0,0 +1,623 @@
import { Toolkit } from "../toolkit.mjs";
//#region src/compat/function/partialRight.d.ts
type __ = Placeholder | Toolkit;
/**
* Creates a function that invokes the provided function with no arguments.
*
* @template R The return type of the function
* @param func The function to partially apply
* @returns Returns the new partially applied function
*
* @example
* const greet = () => 'Hello!';
* const sayHello = partialRight(greet);
* sayHello(); // => 'Hello!'
*/
declare function partialRight<R>(func: () => R): () => R;
/**
* Creates a function that invokes the provided function with one argument.
*
* @template T The type of the argument
* @template R The return type of the function
* @param func The function to partially apply
* @returns Returns the new partially applied function
*
* @example
* const greet = (name: string) => `Hello ${name}!`;
* const greetPerson = partialRight(greet);
* greetPerson('Fred'); // => 'Hello Fred!'
*/
declare function partialRight<T, R>(func: (t1: T) => R): (t1: T) => R;
/**
* Creates a function that invokes the provided function with one argument pre-filled.
*
* @template T The type of the argument
* @template R The return type of the function
* @param func The function to partially apply
* @param arg1 The argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const greet = (name: string) => `Hello ${name}!`;
* const greetFred = partialRight(greet, 'Fred');
* greetFred(); // => 'Hello Fred!'
*/
declare function partialRight<T, R>(func: (t1: T) => R, arg1: T): () => R;
/**
* Creates a function that invokes the provided function with two 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
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string) => `${greeting} ${name}!`;
* const greetWithParams = partialRight(greet);
* greetWithParams('Hi', 'Fred'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, R>(func: (t1: T1, t2: T2) => R): (t1: T1, t2: T2) => R;
/**
* Creates a function that invokes the provided function with one argument pre-filled and a placeholder.
*
* @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 argument to pre-fill
* @param plc2 The placeholder for the second argument
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string) => `${greeting} ${name}!`;
* const hiWithName = partialRight(greet, 'Hi', partialRight.placeholder);
* hiWithName('Fred'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, R>(func: (t1: T1, t2: T2) => R, arg1: T1, plc2: __): (t2: T2) => R;
/**
* Creates a function that invokes the provided function with the second argument pre-filled.
*
* @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 arg2 The argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string) => `${greeting} ${name}!`;
* const greetFred = partialRight(greet, 'Fred');
* greetFred('Hi'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, R>(func: (t1: T1, t2: T2) => R, arg2: T2): (t1: T1) => R;
/**
* Creates a function that invokes the provided function with both arguments pre-filled.
*
* @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 pre-fill
* @param arg2 The second argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string) => `${greeting} ${name}!`;
* const sayHiToFred = partialRight(greet, 'Hi', 'Fred');
* sayHiToFred(); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, R>(func: (t1: T1, t2: T2) => R, arg1: T1, arg2: T2): () => R;
/**
* Creates a function that invokes the provided function with no pre-filled 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
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const greetWithArgs = partialRight(greet);
* greetWithArgs('Hi', 'Fred', '!'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R): (t1: T1, t2: T2, t3: T3) => R;
/**
* Creates a function that invokes the provided function with the first argument pre-filled and placeholders for the rest.
*
* @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 pre-fill
* @param plc2 The placeholder for the second argument
* @param plc3 The placeholder for the third argument
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const hiWithNameAndPunc = partialRight(greet, 'Hi', partialRight.placeholder, partialRight.placeholder);
* hiWithNameAndPunc('Fred', '!'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg1: T1, plc2: __, plc3: __): (t2: T2, t3: T3) => R;
/**
* Creates a function that invokes the provided function with the second argument pre-filled and a placeholder for the third.
*
* @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 arg2 The second argument to pre-fill
* @param plc3 The placeholder for the third argument
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const greetFredWithPunc = partialRight(greet, 'Fred', partialRight.placeholder);
* greetFredWithPunc('Hi', '!'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg2: T2, plc3: __): (t1: T1, t3: T3) => R;
/**
* Creates a function that invokes the provided function with the first two arguments pre-filled and a placeholder for the third.
*
* @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 pre-fill
* @param arg2 The second argument to pre-fill
* @param plc3 The placeholder for the third argument
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const hiToFredWithPunc = partialRight(greet, 'Hi', 'Fred', partialRight.placeholder);
* hiToFredWithPunc('!'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg1: T1, arg2: T2, plc3: __): (t3: T3) => R;
/**
* Creates a function that invokes the provided function with the third argument pre-filled.
*
* @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 arg3 The third argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const greetWithExclamation = partialRight(greet, '!');
* greetWithExclamation('Hi', 'Fred'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg3: T3): (t1: T1, t2: T2) => R;
/**
* Creates a function that invokes the provided function with the first and third arguments pre-filled.
*
* @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 pre-fill
* @param plc2 The placeholder for the second argument
* @param arg3 The third argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const hiWithNameAndExclamation = partialRight(greet, 'Hi', partialRight.placeholder, '!');
* hiWithNameAndExclamation('Fred'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg1: T1, plc2: __, arg3: T3): (t2: T2) => R;
/**
* Creates a function that invokes the provided function with the second and third arguments pre-filled.
*
* @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 arg2 The second argument to pre-fill
* @param arg3 The third argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const greetFredWithExclamation = partialRight(greet, 'Fred', '!');
* greetFredWithExclamation('Hi'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg2: T2, arg3: T3): (t1: T1) => R;
/**
* Creates a function that invokes the provided function with all three arguments pre-filled.
*
* @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 pre-fill
* @param arg2 The second argument to pre-fill
* @param arg3 The third argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const sayHiToFredWithExclamation = partialRight(greet, 'Hi', 'Fred', '!');
* sayHiToFredWithExclamation(); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg1: T1, arg2: T2, arg3: T3): () => R;
/**
* Creates a function that invokes the provided function with no pre-filled 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
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const formatWithArgs = partialRight(format);
* formatWithArgs('Hi', 'Fred', 'morning', '!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R): (t1: T1, t2: T2, t3: T3, t4: T4) => R;
/**
* Creates a function that invokes the provided function with the first argument pre-filled and placeholders for the rest.
*
* @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 pre-fill
* @param plc2 The placeholder for the second argument
* @param plc3 The placeholder for the third argument
* @param plc4 The placeholder for the fourth argument
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const hiWithRest = partialRight(format, 'Hi', partialRight.placeholder, partialRight.placeholder, partialRight.placeholder);
* hiWithRest('Fred', 'morning', '!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, plc3: __, plc4: __): (t2: T2, t3: T3, t4: T4) => R;
/**
* Creates a function that invokes the provided function with the second argument pre-filled and placeholders for the rest.
*
* @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 arg2 The second argument to pre-fill
* @param plc3 The placeholder for the third argument
* @param plc4 The placeholder for the fourth argument
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const greetFredWithRest = partialRight(format, 'Fred', partialRight.placeholder, partialRight.placeholder);
* greetFredWithRest('Hi', 'morning', '!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg2: T2, plc3: __, plc4: __): (t1: T1, t3: T3, t4: T4) => R;
/**
* Creates a function that invokes the provided function with the first two arguments pre-filled and placeholders for the rest.
*
* @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 pre-fill
* @param arg2 The second argument to pre-fill
* @param plc3 The placeholder for the third argument
* @param plc4 The placeholder for the fourth argument
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const hiToFredWithRest = partialRight(format, 'Hi', 'Fred', partialRight.placeholder, partialRight.placeholder);
* hiToFredWithRest('morning', '!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, arg2: T2, plc3: __, plc4: __): (t3: T3, t4: T4) => R;
/**
* Creates a function that invokes the provided function with the third argument pre-filled and a placeholder for the fourth.
*
* @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 arg3 The third argument to pre-fill
* @param plc4 The placeholder for the fourth argument
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const atMorningWithPunc = partialRight(format, 'morning', partialRight.placeholder);
* atMorningWithPunc('Hi', 'Fred', '!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg3: T3, plc4: __): (t1: T1, t2: T2, t4: T4) => R;
/**
* Creates a function that invokes the provided function with the first and third arguments pre-filled and a placeholder for the fourth.
*
* @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 pre-fill
* @param plc2 The placeholder for the second argument
* @param arg3 The third argument to pre-fill
* @param plc4 The placeholder for the fourth argument
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const hiAtMorningWithNameAndPunc = partialRight(format, 'Hi', partialRight.placeholder, 'morning', partialRight.placeholder);
* hiAtMorningWithNameAndPunc('Fred', '!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, arg3: T3, plc4: __): (t2: T2, t4: T4) => R;
/**
* Creates a function that invokes the provided function with the second and third arguments pre-filled and a placeholder for the fourth.
*
* @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 arg2 The second argument to pre-fill
* @param arg3 The third argument to pre-fill
* @param plc4 The placeholder for the fourth argument
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const greetFredAtMorningWithPunc = partialRight(format, 'Fred', 'morning', partialRight.placeholder);
* greetFredAtMorningWithPunc('Hi', '!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg2: T2, arg3: T3, plc4: __): (t1: T1, t4: T4) => R;
/**
* Creates a function that invokes the provided function with the first three arguments pre-filled and a placeholder for the fourth.
*
* @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 pre-fill
* @param arg2 The second argument to pre-fill
* @param arg3 The third argument to pre-fill
* @param plc4 The placeholder for the fourth argument
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const hiToFredAtMorningWithPunc = partialRight(format, 'Hi', 'Fred', 'morning', partialRight.placeholder);
* hiToFredAtMorningWithPunc('!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, arg2: T2, arg3: T3, plc4: __): (t4: T4) => R;
/**
* Creates a function that invokes the provided function with the fourth argument pre-filled.
*
* @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 arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const withExclamation = partialRight(format, '!');
* withExclamation('Hi', 'Fred', 'morning'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg4: T4): (t1: T1, t2: T2, t3: T3) => R;
/**
* Creates a function that invokes the provided function with the first and fourth arguments pre-filled.
*
* @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 pre-fill
* @param plc2 The placeholder for the second argument
* @param plc3 The placeholder for the third argument
* @param arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const hiWithExclamation = partialRight(format, 'Hi', partialRight.placeholder, partialRight.placeholder, '!');
* hiWithExclamation('Fred', 'morning'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, plc3: __, arg4: T4): (t2: T2, t3: T3) => R;
/**
* Creates a function that invokes the provided function with the second and fourth arguments pre-filled and a placeholder for the third.
*
* @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 arg2 The second argument to pre-fill
* @param plc3 The placeholder for the third argument
* @param arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const greetFredWithTime = partialRight(format, 'Fred', partialRight.placeholder, '!');
* greetFredWithTime('Hi', 'morning'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg2: T2, plc3: __, arg4: T4): (t1: T1, t3: T3) => R;
/**
* Creates a function that invokes the provided function with the first, second and fourth arguments pre-filled and a placeholder for the third.
*
* @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 pre-fill
* @param arg2 The second argument to pre-fill
* @param plc3 The placeholder for the third argument
* @param arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const hiToFredWithTime = partialRight(format, 'Hi', 'Fred', partialRight.placeholder, '!');
* hiToFredWithTime('morning'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, arg2: T2, plc3: __, arg4: T4): (t3: T3) => R;
/**
* Creates a function that invokes the provided function with the third and fourth arguments pre-filled.
*
* @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 arg3 The third argument to pre-fill
* @param arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const inMorningWithExclamation = partialRight(format, 'morning', '!');
* inMorningWithExclamation('Hi', 'Fred'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg3: T3, arg4: T4): (t1: T1, t2: T2) => R;
/**
* Creates a function that invokes the provided function with the first, third and fourth arguments pre-filled.
*
* @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 pre-fill
* @param plc2 The placeholder for the second argument
* @param arg3 The third argument to pre-fill
* @param arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const hiInMorningWithExclamation = partialRight(format, 'Hi', partialRight.placeholder, 'morning', '!');
* hiInMorningWithExclamation('Fred'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, arg3: T3, arg4: T4): (t2: T2) => R;
/**
* Creates a function that invokes the provided function with the second, third and fourth arguments pre-filled.
*
* @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 arg2 The second argument to pre-fill
* @param arg3 The third argument to pre-fill
* @param arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const greetFredInMorningWithExclamation = partialRight(format, 'Fred', 'morning', '!');
* greetFredInMorningWithExclamation('Hi'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg2: T2, arg3: T3, arg4: T4): (t1: T1) => R;
/**
* Creates a function that invokes the provided function with all arguments pre-filled.
*
* @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 pre-fill
* @param arg2 The second argument to pre-fill
* @param arg3 The third argument to pre-fill
* @param arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const sayHiToFredInMorningWithExclamation = partialRight(format, 'Hi', 'Fred', 'morning', '!');
* sayHiToFredInMorningWithExclamation(); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, arg2: T2, arg3: T3, arg4: T4): () => R;
/**
* Creates a function that invokes the provided function with partially applied arguments appended to the arguments it receives.
* The partialRight.placeholder value can be used as a placeholder for partially applied arguments.
*
* @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
* function greet(greeting: string, name: string) {
* return greeting + ' ' + name;
* }
*
* const greetFred = partialRight(greet, 'Fred');
* greetFred('Hi'); // => 'Hi Fred'
*
* // Using placeholders
* const sayHelloTo = partialRight(greet, 'Hello', partialRight.placeholder);
* sayHelloTo('Fred'); // => 'Hello Fred'
*/
declare function partialRight(func: (...args: any[]) => any, ...args: any[]): (...args: any[]) => any;
declare namespace partialRight {
var placeholder: Placeholder;
}
type Placeholder = symbol | (((value: any) => any) & {
partialRight: typeof partialRight;
});
//#endregion
export { partialRight };

View file

@ -0,0 +1,623 @@
import { Toolkit } from "../toolkit.js";
//#region src/compat/function/partialRight.d.ts
type __ = Placeholder | Toolkit;
/**
* Creates a function that invokes the provided function with no arguments.
*
* @template R The return type of the function
* @param func The function to partially apply
* @returns Returns the new partially applied function
*
* @example
* const greet = () => 'Hello!';
* const sayHello = partialRight(greet);
* sayHello(); // => 'Hello!'
*/
declare function partialRight<R>(func: () => R): () => R;
/**
* Creates a function that invokes the provided function with one argument.
*
* @template T The type of the argument
* @template R The return type of the function
* @param func The function to partially apply
* @returns Returns the new partially applied function
*
* @example
* const greet = (name: string) => `Hello ${name}!`;
* const greetPerson = partialRight(greet);
* greetPerson('Fred'); // => 'Hello Fred!'
*/
declare function partialRight<T, R>(func: (t1: T) => R): (t1: T) => R;
/**
* Creates a function that invokes the provided function with one argument pre-filled.
*
* @template T The type of the argument
* @template R The return type of the function
* @param func The function to partially apply
* @param arg1 The argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const greet = (name: string) => `Hello ${name}!`;
* const greetFred = partialRight(greet, 'Fred');
* greetFred(); // => 'Hello Fred!'
*/
declare function partialRight<T, R>(func: (t1: T) => R, arg1: T): () => R;
/**
* Creates a function that invokes the provided function with two 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
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string) => `${greeting} ${name}!`;
* const greetWithParams = partialRight(greet);
* greetWithParams('Hi', 'Fred'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, R>(func: (t1: T1, t2: T2) => R): (t1: T1, t2: T2) => R;
/**
* Creates a function that invokes the provided function with one argument pre-filled and a placeholder.
*
* @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 argument to pre-fill
* @param plc2 The placeholder for the second argument
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string) => `${greeting} ${name}!`;
* const hiWithName = partialRight(greet, 'Hi', partialRight.placeholder);
* hiWithName('Fred'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, R>(func: (t1: T1, t2: T2) => R, arg1: T1, plc2: __): (t2: T2) => R;
/**
* Creates a function that invokes the provided function with the second argument pre-filled.
*
* @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 arg2 The argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string) => `${greeting} ${name}!`;
* const greetFred = partialRight(greet, 'Fred');
* greetFred('Hi'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, R>(func: (t1: T1, t2: T2) => R, arg2: T2): (t1: T1) => R;
/**
* Creates a function that invokes the provided function with both arguments pre-filled.
*
* @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 pre-fill
* @param arg2 The second argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string) => `${greeting} ${name}!`;
* const sayHiToFred = partialRight(greet, 'Hi', 'Fred');
* sayHiToFred(); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, R>(func: (t1: T1, t2: T2) => R, arg1: T1, arg2: T2): () => R;
/**
* Creates a function that invokes the provided function with no pre-filled 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
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const greetWithArgs = partialRight(greet);
* greetWithArgs('Hi', 'Fred', '!'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R): (t1: T1, t2: T2, t3: T3) => R;
/**
* Creates a function that invokes the provided function with the first argument pre-filled and placeholders for the rest.
*
* @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 pre-fill
* @param plc2 The placeholder for the second argument
* @param plc3 The placeholder for the third argument
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const hiWithNameAndPunc = partialRight(greet, 'Hi', partialRight.placeholder, partialRight.placeholder);
* hiWithNameAndPunc('Fred', '!'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg1: T1, plc2: __, plc3: __): (t2: T2, t3: T3) => R;
/**
* Creates a function that invokes the provided function with the second argument pre-filled and a placeholder for the third.
*
* @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 arg2 The second argument to pre-fill
* @param plc3 The placeholder for the third argument
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const greetFredWithPunc = partialRight(greet, 'Fred', partialRight.placeholder);
* greetFredWithPunc('Hi', '!'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg2: T2, plc3: __): (t1: T1, t3: T3) => R;
/**
* Creates a function that invokes the provided function with the first two arguments pre-filled and a placeholder for the third.
*
* @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 pre-fill
* @param arg2 The second argument to pre-fill
* @param plc3 The placeholder for the third argument
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const hiToFredWithPunc = partialRight(greet, 'Hi', 'Fred', partialRight.placeholder);
* hiToFredWithPunc('!'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg1: T1, arg2: T2, plc3: __): (t3: T3) => R;
/**
* Creates a function that invokes the provided function with the third argument pre-filled.
*
* @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 arg3 The third argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const greetWithExclamation = partialRight(greet, '!');
* greetWithExclamation('Hi', 'Fred'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg3: T3): (t1: T1, t2: T2) => R;
/**
* Creates a function that invokes the provided function with the first and third arguments pre-filled.
*
* @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 pre-fill
* @param plc2 The placeholder for the second argument
* @param arg3 The third argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const hiWithNameAndExclamation = partialRight(greet, 'Hi', partialRight.placeholder, '!');
* hiWithNameAndExclamation('Fred'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg1: T1, plc2: __, arg3: T3): (t2: T2) => R;
/**
* Creates a function that invokes the provided function with the second and third arguments pre-filled.
*
* @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 arg2 The second argument to pre-fill
* @param arg3 The third argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const greetFredWithExclamation = partialRight(greet, 'Fred', '!');
* greetFredWithExclamation('Hi'); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg2: T2, arg3: T3): (t1: T1) => R;
/**
* Creates a function that invokes the provided function with all three arguments pre-filled.
*
* @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 pre-fill
* @param arg2 The second argument to pre-fill
* @param arg3 The third argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const greet = (greeting: string, name: string, punctuation: string) => `${greeting} ${name}${punctuation}`;
* const sayHiToFredWithExclamation = partialRight(greet, 'Hi', 'Fred', '!');
* sayHiToFredWithExclamation(); // => 'Hi Fred!'
*/
declare function partialRight<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg1: T1, arg2: T2, arg3: T3): () => R;
/**
* Creates a function that invokes the provided function with no pre-filled 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
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const formatWithArgs = partialRight(format);
* formatWithArgs('Hi', 'Fred', 'morning', '!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R): (t1: T1, t2: T2, t3: T3, t4: T4) => R;
/**
* Creates a function that invokes the provided function with the first argument pre-filled and placeholders for the rest.
*
* @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 pre-fill
* @param plc2 The placeholder for the second argument
* @param plc3 The placeholder for the third argument
* @param plc4 The placeholder for the fourth argument
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const hiWithRest = partialRight(format, 'Hi', partialRight.placeholder, partialRight.placeholder, partialRight.placeholder);
* hiWithRest('Fred', 'morning', '!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, plc3: __, plc4: __): (t2: T2, t3: T3, t4: T4) => R;
/**
* Creates a function that invokes the provided function with the second argument pre-filled and placeholders for the rest.
*
* @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 arg2 The second argument to pre-fill
* @param plc3 The placeholder for the third argument
* @param plc4 The placeholder for the fourth argument
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const greetFredWithRest = partialRight(format, 'Fred', partialRight.placeholder, partialRight.placeholder);
* greetFredWithRest('Hi', 'morning', '!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg2: T2, plc3: __, plc4: __): (t1: T1, t3: T3, t4: T4) => R;
/**
* Creates a function that invokes the provided function with the first two arguments pre-filled and placeholders for the rest.
*
* @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 pre-fill
* @param arg2 The second argument to pre-fill
* @param plc3 The placeholder for the third argument
* @param plc4 The placeholder for the fourth argument
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const hiToFredWithRest = partialRight(format, 'Hi', 'Fred', partialRight.placeholder, partialRight.placeholder);
* hiToFredWithRest('morning', '!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, arg2: T2, plc3: __, plc4: __): (t3: T3, t4: T4) => R;
/**
* Creates a function that invokes the provided function with the third argument pre-filled and a placeholder for the fourth.
*
* @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 arg3 The third argument to pre-fill
* @param plc4 The placeholder for the fourth argument
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const atMorningWithPunc = partialRight(format, 'morning', partialRight.placeholder);
* atMorningWithPunc('Hi', 'Fred', '!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg3: T3, plc4: __): (t1: T1, t2: T2, t4: T4) => R;
/**
* Creates a function that invokes the provided function with the first and third arguments pre-filled and a placeholder for the fourth.
*
* @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 pre-fill
* @param plc2 The placeholder for the second argument
* @param arg3 The third argument to pre-fill
* @param plc4 The placeholder for the fourth argument
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const hiAtMorningWithNameAndPunc = partialRight(format, 'Hi', partialRight.placeholder, 'morning', partialRight.placeholder);
* hiAtMorningWithNameAndPunc('Fred', '!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, arg3: T3, plc4: __): (t2: T2, t4: T4) => R;
/**
* Creates a function that invokes the provided function with the second and third arguments pre-filled and a placeholder for the fourth.
*
* @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 arg2 The second argument to pre-fill
* @param arg3 The third argument to pre-fill
* @param plc4 The placeholder for the fourth argument
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const greetFredAtMorningWithPunc = partialRight(format, 'Fred', 'morning', partialRight.placeholder);
* greetFredAtMorningWithPunc('Hi', '!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg2: T2, arg3: T3, plc4: __): (t1: T1, t4: T4) => R;
/**
* Creates a function that invokes the provided function with the first three arguments pre-filled and a placeholder for the fourth.
*
* @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 pre-fill
* @param arg2 The second argument to pre-fill
* @param arg3 The third argument to pre-fill
* @param plc4 The placeholder for the fourth argument
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const hiToFredAtMorningWithPunc = partialRight(format, 'Hi', 'Fred', 'morning', partialRight.placeholder);
* hiToFredAtMorningWithPunc('!'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, arg2: T2, arg3: T3, plc4: __): (t4: T4) => R;
/**
* Creates a function that invokes the provided function with the fourth argument pre-filled.
*
* @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 arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const withExclamation = partialRight(format, '!');
* withExclamation('Hi', 'Fred', 'morning'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg4: T4): (t1: T1, t2: T2, t3: T3) => R;
/**
* Creates a function that invokes the provided function with the first and fourth arguments pre-filled.
*
* @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 pre-fill
* @param plc2 The placeholder for the second argument
* @param plc3 The placeholder for the third argument
* @param arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const hiWithExclamation = partialRight(format, 'Hi', partialRight.placeholder, partialRight.placeholder, '!');
* hiWithExclamation('Fred', 'morning'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, plc3: __, arg4: T4): (t2: T2, t3: T3) => R;
/**
* Creates a function that invokes the provided function with the second and fourth arguments pre-filled and a placeholder for the third.
*
* @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 arg2 The second argument to pre-fill
* @param plc3 The placeholder for the third argument
* @param arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const greetFredWithTime = partialRight(format, 'Fred', partialRight.placeholder, '!');
* greetFredWithTime('Hi', 'morning'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg2: T2, plc3: __, arg4: T4): (t1: T1, t3: T3) => R;
/**
* Creates a function that invokes the provided function with the first, second and fourth arguments pre-filled and a placeholder for the third.
*
* @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 pre-fill
* @param arg2 The second argument to pre-fill
* @param plc3 The placeholder for the third argument
* @param arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const hiToFredWithTime = partialRight(format, 'Hi', 'Fred', partialRight.placeholder, '!');
* hiToFredWithTime('morning'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, arg2: T2, plc3: __, arg4: T4): (t3: T3) => R;
/**
* Creates a function that invokes the provided function with the third and fourth arguments pre-filled.
*
* @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 arg3 The third argument to pre-fill
* @param arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const inMorningWithExclamation = partialRight(format, 'morning', '!');
* inMorningWithExclamation('Hi', 'Fred'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg3: T3, arg4: T4): (t1: T1, t2: T2) => R;
/**
* Creates a function that invokes the provided function with the first, third and fourth arguments pre-filled.
*
* @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 pre-fill
* @param plc2 The placeholder for the second argument
* @param arg3 The third argument to pre-fill
* @param arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const hiInMorningWithExclamation = partialRight(format, 'Hi', partialRight.placeholder, 'morning', '!');
* hiInMorningWithExclamation('Fred'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, arg3: T3, arg4: T4): (t2: T2) => R;
/**
* Creates a function that invokes the provided function with the second, third and fourth arguments pre-filled.
*
* @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 arg2 The second argument to pre-fill
* @param arg3 The third argument to pre-fill
* @param arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const greetFredInMorningWithExclamation = partialRight(format, 'Fred', 'morning', '!');
* greetFredInMorningWithExclamation('Hi'); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg2: T2, arg3: T3, arg4: T4): (t1: T1) => R;
/**
* Creates a function that invokes the provided function with all arguments pre-filled.
*
* @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 pre-fill
* @param arg2 The second argument to pre-fill
* @param arg3 The third argument to pre-fill
* @param arg4 The fourth argument to pre-fill
* @returns Returns the new partially applied function
*
* @example
* const format = (greeting: string, name: string, time: string, punctuation: string) =>
* `${greeting} ${name}, it's ${time}${punctuation}`;
* const sayHiToFredInMorningWithExclamation = partialRight(format, 'Hi', 'Fred', 'morning', '!');
* sayHiToFredInMorningWithExclamation(); // => 'Hi Fred, it's morning!'
*/
declare function partialRight<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, arg2: T2, arg3: T3, arg4: T4): () => R;
/**
* Creates a function that invokes the provided function with partially applied arguments appended to the arguments it receives.
* The partialRight.placeholder value can be used as a placeholder for partially applied arguments.
*
* @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
* function greet(greeting: string, name: string) {
* return greeting + ' ' + name;
* }
*
* const greetFred = partialRight(greet, 'Fred');
* greetFred('Hi'); // => 'Hi Fred'
*
* // Using placeholders
* const sayHelloTo = partialRight(greet, 'Hello', partialRight.placeholder);
* sayHelloTo('Fred'); // => 'Hello Fred'
*/
declare function partialRight(func: (...args: any[]) => any, ...args: any[]): (...args: any[]) => any;
declare namespace partialRight {
var placeholder: Placeholder;
}
type Placeholder = symbol | (((value: any) => any) & {
partialRight: typeof partialRight;
});
//#endregion
export { partialRight };

View file

@ -0,0 +1,34 @@
const require_partialRight = require("../../function/partialRight.js");
//#region src/compat/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 require_partialRight.partialRightImpl(func, partialRight.placeholder, ...partialArgs);
}
partialRight.placeholder = Symbol("compat.partialRight.placeholder");
//#endregion
exports.partialRight = partialRight;

View file

@ -0,0 +1,34 @@
import { partialRightImpl } from "../../function/partialRight.mjs";
//#region src/compat/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, partialRight.placeholder, ...partialArgs);
}
partialRight.placeholder = Symbol("compat.partialRight.placeholder");
//#endregion
export { partialRight };

View file

@ -0,0 +1,20 @@
import { Many } from "../_internal/Many.mjs";
//#region src/compat/function/rearg.d.ts
/**
* Creates a function that invokes `func` with arguments arranged according to the specified `indices`
* where the argument value at the first index is provided as the first argument,
* the argument value at the second index is provided as the second argument, and so on.
*
* @param func The function to rearrange arguments for.
* @param indices The arranged argument indices.
* @returns Returns the new function.
*
* @example
* const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
* const rearrangedGreet = rearg(greet, 1, 0);
* console.log(rearrangedGreet('World', 'Hello')); // Output: "Hello, World!"
*/
declare function rearg(func: (...args: any[]) => any, ...indices: Array<Many<number>>): (...args: any[]) => any;
//#endregion
export { rearg };

View file

@ -0,0 +1,20 @@
import { Many } from "../_internal/Many.js";
//#region src/compat/function/rearg.d.ts
/**
* Creates a function that invokes `func` with arguments arranged according to the specified `indices`
* where the argument value at the first index is provided as the first argument,
* the argument value at the second index is provided as the second argument, and so on.
*
* @param func The function to rearrange arguments for.
* @param indices The arranged argument indices.
* @returns Returns the new function.
*
* @example
* const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
* const rearrangedGreet = rearg(greet, 1, 0);
* console.log(rearrangedGreet('World', 'Hello')); // Output: "Hello, World!"
*/
declare function rearg(func: (...args: any[]) => any, ...indices: Array<Many<number>>): (...args: any[]) => any;
//#endregion
export { rearg };

View file

@ -0,0 +1,26 @@
const require_flatten = require("../array/flatten.js");
//#region src/compat/function/rearg.ts
/**
* Creates a function that invokes `func` with arguments arranged according to the specified `indices`
* where the argument value at the first index is provided as the first argument,
* the argument value at the second index is provided as the second argument, and so on.
*
* @param func The function to rearrange arguments for.
* @param indices The arranged argument indices.
* @returns Returns the new function.
*
* @example
* const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
* const rearrangedGreet = rearg(greet, 1, 0);
* console.log(rearrangedGreet('World', 'Hello')); // Output: "Hello, World!"
*/
function rearg(func, ...indices) {
const flattenIndices = require_flatten.flatten(indices);
return function(...args) {
const reorderedArgs = flattenIndices.map((i) => args[i]).slice(0, args.length);
for (let i = reorderedArgs.length; i < args.length; i++) reorderedArgs.push(args[i]);
return func.apply(this, reorderedArgs);
};
}
//#endregion
exports.rearg = rearg;

View file

@ -0,0 +1,26 @@
import { flatten } from "../array/flatten.mjs";
//#region src/compat/function/rearg.ts
/**
* Creates a function that invokes `func` with arguments arranged according to the specified `indices`
* where the argument value at the first index is provided as the first argument,
* the argument value at the second index is provided as the second argument, and so on.
*
* @param func The function to rearrange arguments for.
* @param indices The arranged argument indices.
* @returns Returns the new function.
*
* @example
* const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
* const rearrangedGreet = rearg(greet, 1, 0);
* console.log(rearrangedGreet('World', 'Hello')); // Output: "Hello, World!"
*/
function rearg(func, ...indices) {
const flattenIndices = flatten(indices);
return function(...args) {
const reorderedArgs = flattenIndices.map((i) => args[i]).slice(0, args.length);
for (let i = reorderedArgs.length; i < args.length; i++) reorderedArgs.push(args[i]);
return func.apply(this, reorderedArgs);
};
}
//#endregion
export { rearg };

View file

@ -0,0 +1,33 @@
//#region src/compat/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.
*
* @param func - The function whose arguments are to be transformed.
* @param [start=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(func: (...args: any[]) => any, start?: number): (...args: any[]) => any;
//#endregion
export { rest };

View file

@ -0,0 +1,33 @@
//#region src/compat/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.
*
* @param func - The function whose arguments are to be transformed.
* @param [start=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(func: (...args: any[]) => any, start?: number): (...args: any[]) => any;
//#endregion
export { rest };

View file

@ -0,0 +1,38 @@
const require_rest = require("../../function/rest.js");
//#region src/compat/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.
*
* @param func - The function whose arguments are to be transformed.
* @param [start=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, start = func.length - 1) {
start = Number.parseInt(start, 10);
if (Number.isNaN(start) || start < 0) start = func.length - 1;
return require_rest.rest(func, start);
}
//#endregion
exports.rest = rest;

View file

@ -0,0 +1,38 @@
import { rest as rest$1 } from "../../function/rest.mjs";
//#region src/compat/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.
*
* @param func - The function whose arguments are to be transformed.
* @param [start=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, start = func.length - 1) {
start = Number.parseInt(start, 10);
if (Number.isNaN(start) || start < 0) start = func.length - 1;
return rest$1(func, start);
}
//#endregion
export { rest };

Some files were not shown because too many files have changed in this diff Show more