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,20 @@
//#region src/fp/array/at.d.ts
/**
* Creates a function that retrieves elements from the piped array at the specified indices.
*
* Negative indices count back from the end of the array, matching the main {@link at}
* implementation. Use the returned function with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param indices - The indices of the elements to retrieve from the piped array.
* @returns A function that maps a readonly array to a new array of selected values.
*
* @example
* import { at, pipe } from 'es-toolkit/fp';
*
* pipe([10, 20, 30, 40], at([1, -1]));
* // => [20, 40]
*/
declare function at<T>(indices: number[]): (array: readonly T[]) => T[];
//#endregion
export { at };

20
frontend/node_modules/es-toolkit/dist/fp/array/at.d.ts generated vendored Normal file
View file

@ -0,0 +1,20 @@
//#region src/fp/array/at.d.ts
/**
* Creates a function that retrieves elements from the piped array at the specified indices.
*
* Negative indices count back from the end of the array, matching the main {@link at}
* implementation. Use the returned function with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param indices - The indices of the elements to retrieve from the piped array.
* @returns A function that maps a readonly array to a new array of selected values.
*
* @example
* import { at, pipe } from 'es-toolkit/fp';
*
* pipe([10, 20, 30, 40], at([1, -1]));
* // => [20, 40]
*/
declare function at<T>(indices: number[]): (array: readonly T[]) => T[];
//#endregion
export { at };

25
frontend/node_modules/es-toolkit/dist/fp/array/at.js generated vendored Normal file
View file

@ -0,0 +1,25 @@
const require_at = require("../../array/at.js");
//#region src/fp/array/at.ts
/**
* Creates a function that retrieves elements from the piped array at the specified indices.
*
* Negative indices count back from the end of the array, matching the main {@link at}
* implementation. Use the returned function with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param indices - The indices of the elements to retrieve from the piped array.
* @returns A function that maps a readonly array to a new array of selected values.
*
* @example
* import { at, pipe } from 'es-toolkit/fp';
*
* pipe([10, 20, 30, 40], at([1, -1]));
* // => [20, 40]
*/
function at(indices) {
return function(array) {
return require_at.at(array, indices);
};
}
//#endregion
exports.at = at;

25
frontend/node_modules/es-toolkit/dist/fp/array/at.mjs generated vendored Normal file
View file

@ -0,0 +1,25 @@
import { at as at$1 } from "../../array/at.mjs";
//#region src/fp/array/at.ts
/**
* Creates a function that retrieves elements from the piped array at the specified indices.
*
* Negative indices count back from the end of the array, matching the main {@link at}
* implementation. Use the returned function with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param indices - The indices of the elements to retrieve from the piped array.
* @returns A function that maps a readonly array to a new array of selected values.
*
* @example
* import { at, pipe } from 'es-toolkit/fp';
*
* pipe([10, 20, 30, 40], at([1, -1]));
* // => [20, 40]
*/
function at(indices) {
return function(array) {
return at$1(array, indices);
};
}
//#endregion
export { at };

View file

@ -0,0 +1,61 @@
//#region src/fp/array/cartesianProduct.d.ts
/**
* Creates a function that wraps each element of the piped array in a one-item tuple.
*
* @template T - The type of elements in the piped array.
* @returns A function that maps the piped array to one-item cartesian product tuples.
*
* @example
* import { cartesianProduct, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2], cartesianProduct());
* // => [[1], [2]]
*/
declare function cartesianProduct<T>(): (array: readonly T[]) => Array<[T]>;
/**
* Creates a function that computes the cartesian product of the piped array and one configured array.
*
* @template T - The type of elements in the piped array.
* @template U - The type of elements in the configured array.
* @param arr2 - The second array in the cartesian product.
* @returns A function that maps the piped array to two-item cartesian product tuples.
*
* @example
* pipe([1, 2], cartesianProduct(['a', 'b']));
* // => [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
*/
declare function cartesianProduct<T, U>(arr2: readonly U[]): (array: readonly T[]) => Array<[T, U]>;
/**
* Creates a function that computes the cartesian product of the piped array and two configured arrays.
*
* @template T - The type of elements in the piped array.
* @template U - The type of elements in the second array.
* @template V - The type of elements in the third array.
* @param arr2 - The second array in the cartesian product.
* @param arr3 - The third array in the cartesian product.
* @returns A function that maps the piped array to three-item cartesian product tuples.
*/
declare function cartesianProduct<T, U, V>(arr2: readonly U[], arr3: readonly V[]): (array: readonly T[]) => Array<[T, U, V]>;
/**
* Creates a function that computes the cartesian product of the piped array and three configured arrays.
*
* @template T - The type of elements in the piped array.
* @template U - The type of elements in the second array.
* @template V - The type of elements in the third array.
* @template W - The type of elements in the fourth array.
* @param arr2 - The second array in the cartesian product.
* @param arr3 - The third array in the cartesian product.
* @param arr4 - The fourth array in the cartesian product.
* @returns A function that maps the piped array to four-item cartesian product tuples.
*/
declare function cartesianProduct<T, U, V, W>(arr2: readonly U[], arr3: readonly V[], arr4: readonly W[]): (array: readonly T[]) => Array<[T, U, V, W]>;
/**
* Creates a function that computes the cartesian product of the piped array and any number of configured arrays.
*
* @template T - The shared element type of the arrays.
* @param arrs - Additional arrays included in the cartesian product.
* @returns A function that maps the piped array to cartesian product rows.
*/
declare function cartesianProduct<T>(...arrs: Array<readonly T[]>): (array: readonly T[]) => T[][];
//#endregion
export { cartesianProduct };

View file

@ -0,0 +1,61 @@
//#region src/fp/array/cartesianProduct.d.ts
/**
* Creates a function that wraps each element of the piped array in a one-item tuple.
*
* @template T - The type of elements in the piped array.
* @returns A function that maps the piped array to one-item cartesian product tuples.
*
* @example
* import { cartesianProduct, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2], cartesianProduct());
* // => [[1], [2]]
*/
declare function cartesianProduct<T>(): (array: readonly T[]) => Array<[T]>;
/**
* Creates a function that computes the cartesian product of the piped array and one configured array.
*
* @template T - The type of elements in the piped array.
* @template U - The type of elements in the configured array.
* @param arr2 - The second array in the cartesian product.
* @returns A function that maps the piped array to two-item cartesian product tuples.
*
* @example
* pipe([1, 2], cartesianProduct(['a', 'b']));
* // => [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
*/
declare function cartesianProduct<T, U>(arr2: readonly U[]): (array: readonly T[]) => Array<[T, U]>;
/**
* Creates a function that computes the cartesian product of the piped array and two configured arrays.
*
* @template T - The type of elements in the piped array.
* @template U - The type of elements in the second array.
* @template V - The type of elements in the third array.
* @param arr2 - The second array in the cartesian product.
* @param arr3 - The third array in the cartesian product.
* @returns A function that maps the piped array to three-item cartesian product tuples.
*/
declare function cartesianProduct<T, U, V>(arr2: readonly U[], arr3: readonly V[]): (array: readonly T[]) => Array<[T, U, V]>;
/**
* Creates a function that computes the cartesian product of the piped array and three configured arrays.
*
* @template T - The type of elements in the piped array.
* @template U - The type of elements in the second array.
* @template V - The type of elements in the third array.
* @template W - The type of elements in the fourth array.
* @param arr2 - The second array in the cartesian product.
* @param arr3 - The third array in the cartesian product.
* @param arr4 - The fourth array in the cartesian product.
* @returns A function that maps the piped array to four-item cartesian product tuples.
*/
declare function cartesianProduct<T, U, V, W>(arr2: readonly U[], arr3: readonly V[], arr4: readonly W[]): (array: readonly T[]) => Array<[T, U, V, W]>;
/**
* Creates a function that computes the cartesian product of the piped array and any number of configured arrays.
*
* @template T - The shared element type of the arrays.
* @param arrs - Additional arrays included in the cartesian product.
* @returns A function that maps the piped array to cartesian product rows.
*/
declare function cartesianProduct<T>(...arrs: Array<readonly T[]>): (array: readonly T[]) => T[][];
//#endregion
export { cartesianProduct };

View file

@ -0,0 +1,9 @@
const require_cartesianProduct = require("../../array/cartesianProduct.js");
//#region src/fp/array/cartesianProduct.ts
function cartesianProduct(...arrs) {
return function(array) {
return require_cartesianProduct.cartesianProduct(array, ...arrs);
};
}
//#endregion
exports.cartesianProduct = cartesianProduct;

View file

@ -0,0 +1,9 @@
import { cartesianProduct as cartesianProduct$1 } from "../../array/cartesianProduct.mjs";
//#region src/fp/array/cartesianProduct.ts
function cartesianProduct(...arrs) {
return function(array) {
return cartesianProduct$1(array, ...arrs);
};
}
//#endregion
export { cartesianProduct };

View file

@ -0,0 +1,19 @@
//#region src/fp/array/chunk.d.ts
/**
* Creates a function that splits an array into sub-arrays of length `size`. The
* final chunk holds the remaining elements when the array cannot be divided
* evenly. Use it with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param size - The length of each chunk. Must be a positive integer.
* @returns A function that maps a `readonly T[]` to a `T[][]`.
* @throws {Error} When `size` is not a positive integer (propagated from the underlying implementation).
*
* @example
* import { pipe, chunk } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4, 5], chunk(2)); // => [[1, 2], [3, 4], [5]]
*/
declare function chunk<T>(size: number): (array: readonly T[]) => T[][];
//#endregion
export { chunk };

View file

@ -0,0 +1,19 @@
//#region src/fp/array/chunk.d.ts
/**
* Creates a function that splits an array into sub-arrays of length `size`. The
* final chunk holds the remaining elements when the array cannot be divided
* evenly. Use it with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param size - The length of each chunk. Must be a positive integer.
* @returns A function that maps a `readonly T[]` to a `T[][]`.
* @throws {Error} When `size` is not a positive integer (propagated from the underlying implementation).
*
* @example
* import { pipe, chunk } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4, 5], chunk(2)); // => [[1, 2], [3, 4], [5]]
*/
declare function chunk<T>(size: number): (array: readonly T[]) => T[][];
//#endregion
export { chunk };

View file

@ -0,0 +1,24 @@
const require_chunk = require("../../array/chunk.js");
//#region src/fp/array/chunk.ts
/**
* Creates a function that splits an array into sub-arrays of length `size`. The
* final chunk holds the remaining elements when the array cannot be divided
* evenly. Use it with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param size - The length of each chunk. Must be a positive integer.
* @returns A function that maps a `readonly T[]` to a `T[][]`.
* @throws {Error} When `size` is not a positive integer (propagated from the underlying implementation).
*
* @example
* import { pipe, chunk } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4, 5], chunk(2)); // => [[1, 2], [3, 4], [5]]
*/
function chunk(size) {
return function(array) {
return require_chunk.chunk(array, size);
};
}
//#endregion
exports.chunk = chunk;

View file

@ -0,0 +1,24 @@
import { chunk as chunk$1 } from "../../array/chunk.mjs";
//#region src/fp/array/chunk.ts
/**
* Creates a function that splits an array into sub-arrays of length `size`. The
* final chunk holds the remaining elements when the array cannot be divided
* evenly. Use it with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param size - The length of each chunk. Must be a positive integer.
* @returns A function that maps a `readonly T[]` to a `T[][]`.
* @throws {Error} When `size` is not a positive integer (propagated from the underlying implementation).
*
* @example
* import { pipe, chunk } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4, 5], chunk(2)); // => [[1, 2], [3, 4], [5]]
*/
function chunk(size) {
return function(array) {
return chunk$1(array, size);
};
}
//#endregion
export { chunk };

View file

@ -0,0 +1,20 @@
//#region src/fp/array/chunkBy.d.ts
/**
* Creates a function that splits consecutive elements whenever the derived key changes.
*
* The iteratee is called from left to right. A new chunk starts when its key differs
* from the previous key by strict inequality. Use the returned function with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param iteratee - Called for each value to produce the comparison key.
* @returns A function that maps a readonly array to consecutive same-key chunks.
*
* @example
* import { chunkBy, pipe } from 'es-toolkit/fp';
*
* pipe([1, 1, 2, 3, 3], chunkBy(value => value));
* // => [[1, 1], [2], [3, 3]]
*/
declare function chunkBy<T>(iteratee: (value: T) => unknown): (array: readonly T[]) => T[][];
//#endregion
export { chunkBy };

View file

@ -0,0 +1,20 @@
//#region src/fp/array/chunkBy.d.ts
/**
* Creates a function that splits consecutive elements whenever the derived key changes.
*
* The iteratee is called from left to right. A new chunk starts when its key differs
* from the previous key by strict inequality. Use the returned function with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param iteratee - Called for each value to produce the comparison key.
* @returns A function that maps a readonly array to consecutive same-key chunks.
*
* @example
* import { chunkBy, pipe } from 'es-toolkit/fp';
*
* pipe([1, 1, 2, 3, 3], chunkBy(value => value));
* // => [[1, 1], [2], [3, 3]]
*/
declare function chunkBy<T>(iteratee: (value: T) => unknown): (array: readonly T[]) => T[][];
//#endregion
export { chunkBy };

View file

@ -0,0 +1,25 @@
const require_chunkBy = require("../../array/chunkBy.js");
//#region src/fp/array/chunkBy.ts
/**
* Creates a function that splits consecutive elements whenever the derived key changes.
*
* The iteratee is called from left to right. A new chunk starts when its key differs
* from the previous key by strict inequality. Use the returned function with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param iteratee - Called for each value to produce the comparison key.
* @returns A function that maps a readonly array to consecutive same-key chunks.
*
* @example
* import { chunkBy, pipe } from 'es-toolkit/fp';
*
* pipe([1, 1, 2, 3, 3], chunkBy(value => value));
* // => [[1, 1], [2], [3, 3]]
*/
function chunkBy(iteratee) {
return function(array) {
return require_chunkBy.chunkBy(array, iteratee);
};
}
//#endregion
exports.chunkBy = chunkBy;

View file

@ -0,0 +1,25 @@
import { chunkBy as chunkBy$1 } from "../../array/chunkBy.mjs";
//#region src/fp/array/chunkBy.ts
/**
* Creates a function that splits consecutive elements whenever the derived key changes.
*
* The iteratee is called from left to right. A new chunk starts when its key differs
* from the previous key by strict inequality. Use the returned function with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param iteratee - Called for each value to produce the comparison key.
* @returns A function that maps a readonly array to consecutive same-key chunks.
*
* @example
* import { chunkBy, pipe } from 'es-toolkit/fp';
*
* pipe([1, 1, 2, 3, 3], chunkBy(value => value));
* // => [[1, 1], [2], [3, 3]]
*/
function chunkBy(iteratee) {
return function(array) {
return chunkBy$1(array, iteratee);
};
}
//#endregion
export { chunkBy };

View file

@ -0,0 +1,21 @@
//#region src/fp/array/combinations.d.ts
/**
* Creates a function that returns every combination of the configured size.
*
* Elements are treated as unique by position, so duplicate values can produce identical-looking
* combinations. The returned function throws when size is not a non-negative integer.
*
* @template T - The type of elements in the array.
* @param size - The number of items in each combination.
* @returns A function that maps a readonly array to its size-length combinations.
* @throws {Error} When size is not a non-negative integer.
*
* @example
* import { combinations, pipe } from 'es-toolkit/fp';
*
* pipe(['A', 'B', 'C'], combinations(2));
* // => [['A', 'B'], ['A', 'C'], ['B', 'C']]
*/
declare function combinations<T>(size: number): (array: readonly T[]) => T[][];
//#endregion
export { combinations };

View file

@ -0,0 +1,21 @@
//#region src/fp/array/combinations.d.ts
/**
* Creates a function that returns every combination of the configured size.
*
* Elements are treated as unique by position, so duplicate values can produce identical-looking
* combinations. The returned function throws when size is not a non-negative integer.
*
* @template T - The type of elements in the array.
* @param size - The number of items in each combination.
* @returns A function that maps a readonly array to its size-length combinations.
* @throws {Error} When size is not a non-negative integer.
*
* @example
* import { combinations, pipe } from 'es-toolkit/fp';
*
* pipe(['A', 'B', 'C'], combinations(2));
* // => [['A', 'B'], ['A', 'C'], ['B', 'C']]
*/
declare function combinations<T>(size: number): (array: readonly T[]) => T[][];
//#endregion
export { combinations };

View file

@ -0,0 +1,26 @@
const require_combinations = require("../../array/combinations.js");
//#region src/fp/array/combinations.ts
/**
* Creates a function that returns every combination of the configured size.
*
* Elements are treated as unique by position, so duplicate values can produce identical-looking
* combinations. The returned function throws when size is not a non-negative integer.
*
* @template T - The type of elements in the array.
* @param size - The number of items in each combination.
* @returns A function that maps a readonly array to its size-length combinations.
* @throws {Error} When size is not a non-negative integer.
*
* @example
* import { combinations, pipe } from 'es-toolkit/fp';
*
* pipe(['A', 'B', 'C'], combinations(2));
* // => [['A', 'B'], ['A', 'C'], ['B', 'C']]
*/
function combinations(size) {
return function(array) {
return require_combinations.combinations(array, size);
};
}
//#endregion
exports.combinations = combinations;

View file

@ -0,0 +1,26 @@
import { combinations as combinations$1 } from "../../array/combinations.mjs";
//#region src/fp/array/combinations.ts
/**
* Creates a function that returns every combination of the configured size.
*
* Elements are treated as unique by position, so duplicate values can produce identical-looking
* combinations. The returned function throws when size is not a non-negative integer.
*
* @template T - The type of elements in the array.
* @param size - The number of items in each combination.
* @returns A function that maps a readonly array to its size-length combinations.
* @throws {Error} When size is not a non-negative integer.
*
* @example
* import { combinations, pipe } from 'es-toolkit/fp';
*
* pipe(['A', 'B', 'C'], combinations(2));
* // => [['A', 'B'], ['A', 'C'], ['B', 'C']]
*/
function combinations(size) {
return function(array) {
return combinations$1(array, size);
};
}
//#endregion
export { combinations };

View file

@ -0,0 +1,22 @@
//#region src/fp/array/compact.d.ts
type NotFalsey<T> = Exclude<T, false | null | 0 | 0n | '' | undefined>;
/**
* Creates a function that removes falsey values from an array. Use it with {@link pipe}.
*
* Falsey values include false, null, 0, -0, 0n, an empty string, undefined,
* and NaN. The returned function is lazy-capable inside {@link pipe}, so a
* trailing short-circuiting operator such as {@link take} can stop once enough
* truthy values have been emitted.
*
* @template T - The type of elements in the array.
* @returns A function that maps a readonly array to a new array with falsey values removed.
*
* @example
* import { compact, pipe } from 'es-toolkit/fp';
*
* pipe([0, 1, false, 2, '', 3], compact());
* // => [1, 2, 3]
*/
declare function compact<T>(): (array: readonly T[]) => Array<NotFalsey<T>>;
//#endregion
export { compact };

View file

@ -0,0 +1,22 @@
//#region src/fp/array/compact.d.ts
type NotFalsey<T> = Exclude<T, false | null | 0 | 0n | '' | undefined>;
/**
* Creates a function that removes falsey values from an array. Use it with {@link pipe}.
*
* Falsey values include false, null, 0, -0, 0n, an empty string, undefined,
* and NaN. The returned function is lazy-capable inside {@link pipe}, so a
* trailing short-circuiting operator such as {@link take} can stop once enough
* truthy values have been emitted.
*
* @template T - The type of elements in the array.
* @returns A function that maps a readonly array to a new array with falsey values removed.
*
* @example
* import { compact, pipe } from 'es-toolkit/fp';
*
* pipe([0, 1, false, 2, '', 3], compact());
* // => [1, 2, 3]
*/
declare function compact<T>(): (array: readonly T[]) => Array<NotFalsey<T>>;
//#endregion
export { compact };

View file

@ -0,0 +1,31 @@
const require_compact = require("../../array/compact.js");
const require_lazy = require("../_internal/lazy.js");
//#region src/fp/array/compact.ts
/**
* Creates a function that removes falsey values from an array. Use it with {@link pipe}.
*
* Falsey values include false, null, 0, -0, 0n, an empty string, undefined,
* and NaN. The returned function is lazy-capable inside {@link pipe}, so a
* trailing short-circuiting operator such as {@link take} can stop once enough
* truthy values have been emitted.
*
* @template T - The type of elements in the array.
* @returns A function that maps a readonly array to a new array with falsey values removed.
*
* @example
* import { compact, pipe } from 'es-toolkit/fp';
*
* pipe([0, 1, false, 2, '', 3], compact());
* // => [1, 2, 3]
*/
function compact() {
function compactEager(array) {
return require_compact.compact(array);
}
const compactLazy = require_lazy.createLazyFunction((value, _index, emit) => {
if (value) emit(value);
});
return require_lazy.combineEagerAndLazyFunctions(compactEager, compactLazy);
}
//#endregion
exports.compact = compact;

View file

@ -0,0 +1,30 @@
import { compact as compact$1 } from "../../array/compact.mjs";
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
//#region src/fp/array/compact.ts
/**
* Creates a function that removes falsey values from an array. Use it with {@link pipe}.
*
* Falsey values include false, null, 0, -0, 0n, an empty string, undefined,
* and NaN. The returned function is lazy-capable inside {@link pipe}, so a
* trailing short-circuiting operator such as {@link take} can stop once enough
* truthy values have been emitted.
*
* @template T - The type of elements in the array.
* @returns A function that maps a readonly array to a new array with falsey values removed.
*
* @example
* import { compact, pipe } from 'es-toolkit/fp';
*
* pipe([0, 1, false, 2, '', 3], compact());
* // => [1, 2, 3]
*/
function compact() {
function compactEager(array) {
return compact$1(array);
}
return combineEagerAndLazyFunctions(compactEager, createLazyFunction((value, _index, emit) => {
if (value) emit(value);
}));
}
//#endregion
export { compact };

View file

@ -0,0 +1,21 @@
//#region src/fp/array/countBy.d.ts
/**
* Creates a function that counts values by a derived key.
*
* The mapper receives each value, its index, and the full input array. The returned object
* uses mapper results as keys and occurrence counts as values.
*
* @template T - The type of elements in the array.
* @template K - The property-key type produced by the mapper.
* @param mapper - Called with each value, index, and array to produce a key.
* @returns A function that maps a readonly array to counts by key.
*
* @example
* import { countBy, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4, 5], countBy(value => (value % 2 === 0 ? 'even' : 'odd')));
* // => { odd: 3, even: 2 }
*/
declare function countBy<T, K extends PropertyKey>(mapper: (item: T, index: number, array: readonly T[]) => K): (array: readonly T[]) => Record<K, number>;
//#endregion
export { countBy };

View file

@ -0,0 +1,21 @@
//#region src/fp/array/countBy.d.ts
/**
* Creates a function that counts values by a derived key.
*
* The mapper receives each value, its index, and the full input array. The returned object
* uses mapper results as keys and occurrence counts as values.
*
* @template T - The type of elements in the array.
* @template K - The property-key type produced by the mapper.
* @param mapper - Called with each value, index, and array to produce a key.
* @returns A function that maps a readonly array to counts by key.
*
* @example
* import { countBy, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4, 5], countBy(value => (value % 2 === 0 ? 'even' : 'odd')));
* // => { odd: 3, even: 2 }
*/
declare function countBy<T, K extends PropertyKey>(mapper: (item: T, index: number, array: readonly T[]) => K): (array: readonly T[]) => Record<K, number>;
//#endregion
export { countBy };

View file

@ -0,0 +1,26 @@
const require_countBy = require("../../array/countBy.js");
//#region src/fp/array/countBy.ts
/**
* Creates a function that counts values by a derived key.
*
* The mapper receives each value, its index, and the full input array. The returned object
* uses mapper results as keys and occurrence counts as values.
*
* @template T - The type of elements in the array.
* @template K - The property-key type produced by the mapper.
* @param mapper - Called with each value, index, and array to produce a key.
* @returns A function that maps a readonly array to counts by key.
*
* @example
* import { countBy, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4, 5], countBy(value => (value % 2 === 0 ? 'even' : 'odd')));
* // => { odd: 3, even: 2 }
*/
function countBy(mapper) {
return function(array) {
return require_countBy.countBy(array, mapper);
};
}
//#endregion
exports.countBy = countBy;

View file

@ -0,0 +1,26 @@
import { countBy as countBy$1 } from "../../array/countBy.mjs";
//#region src/fp/array/countBy.ts
/**
* Creates a function that counts values by a derived key.
*
* The mapper receives each value, its index, and the full input array. The returned object
* uses mapper results as keys and occurrence counts as values.
*
* @template T - The type of elements in the array.
* @template K - The property-key type produced by the mapper.
* @param mapper - Called with each value, index, and array to produce a key.
* @returns A function that maps a readonly array to counts by key.
*
* @example
* import { countBy, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4, 5], countBy(value => (value % 2 === 0 ? 'even' : 'odd')));
* // => { odd: 3, even: 2 }
*/
function countBy(mapper) {
return function(array) {
return countBy$1(array, mapper);
};
}
//#endregion
export { countBy };

View file

@ -0,0 +1,21 @@
//#region src/fp/array/difference.d.ts
/**
* Creates a function that returns values from the piped array that are not present in another array.
*
* Equality follows SameValueZero through Set membership, matching the main
* {@link difference} implementation. The returned function is lazy-capable
* inside {@link pipe}.
*
* @template T - The type of elements in the arrays.
* @param secondArray - Values to exclude from the piped array.
* @returns A function that maps the piped array to its difference.
*
* @example
* import { difference, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3], difference([2, 4]));
* // => [1, 3]
*/
declare function difference<T>(secondArray: readonly T[]): (array: readonly T[]) => T[];
//#endregion
export { difference };

View file

@ -0,0 +1,21 @@
//#region src/fp/array/difference.d.ts
/**
* Creates a function that returns values from the piped array that are not present in another array.
*
* Equality follows SameValueZero through Set membership, matching the main
* {@link difference} implementation. The returned function is lazy-capable
* inside {@link pipe}.
*
* @template T - The type of elements in the arrays.
* @param secondArray - Values to exclude from the piped array.
* @returns A function that maps the piped array to its difference.
*
* @example
* import { difference, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3], difference([2, 4]));
* // => [1, 3]
*/
declare function difference<T>(secondArray: readonly T[]): (array: readonly T[]) => T[];
//#endregion
export { difference };

View file

@ -0,0 +1,32 @@
const require_difference = require("../../array/difference.js");
const require_lazy = require("../_internal/lazy.js");
//#region src/fp/array/difference.ts
/**
* Creates a function that returns values from the piped array that are not present in another array.
*
* Equality follows SameValueZero through Set membership, matching the main
* {@link difference} implementation. The returned function is lazy-capable
* inside {@link pipe}.
*
* @template T - The type of elements in the arrays.
* @param secondArray - Values to exclude from the piped array.
* @returns A function that maps the piped array to its difference.
*
* @example
* import { difference, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3], difference([2, 4]));
* // => [1, 3]
*/
function difference(secondArray) {
const secondSet = new Set(secondArray);
function differenceEager(array) {
return require_difference.difference(array, secondArray);
}
const differenceLazy = require_lazy.createLazyFunction((value, _index, emit) => {
if (!secondSet.has(value)) emit(value);
});
return require_lazy.combineEagerAndLazyFunctions(differenceEager, differenceLazy);
}
//#endregion
exports.difference = difference;

View file

@ -0,0 +1,31 @@
import { difference as difference$1 } from "../../array/difference.mjs";
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
//#region src/fp/array/difference.ts
/**
* Creates a function that returns values from the piped array that are not present in another array.
*
* Equality follows SameValueZero through Set membership, matching the main
* {@link difference} implementation. The returned function is lazy-capable
* inside {@link pipe}.
*
* @template T - The type of elements in the arrays.
* @param secondArray - Values to exclude from the piped array.
* @returns A function that maps the piped array to its difference.
*
* @example
* import { difference, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3], difference([2, 4]));
* // => [1, 3]
*/
function difference(secondArray) {
const secondSet = new Set(secondArray);
function differenceEager(array) {
return difference$1(array, secondArray);
}
return combineEagerAndLazyFunctions(differenceEager, createLazyFunction((value, _index, emit) => {
if (!secondSet.has(value)) emit(value);
}));
}
//#endregion
export { difference };

View file

@ -0,0 +1,22 @@
//#region src/fp/array/differenceBy.d.ts
/**
* Creates a function that returns values whose mapped identity is absent from another array.
*
* The mapper is applied to values from both arrays. The returned function is
* lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the piped array.
* @template U - The type of elements in the configured array.
* @param secondArray - Values to exclude from the piped array after mapping.
* @param mapper - Maps values from both arrays to comparison keys.
* @returns A function that maps the piped array to its mapped difference.
*
* @example
* import { differenceBy, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }], differenceBy([2], value => typeof value === 'number' ? value : value.id));
* // => [{ id: 1 }]
*/
declare function differenceBy<T, U>(secondArray: readonly U[], mapper: (value: T | U) => unknown): (array: readonly T[]) => T[];
//#endregion
export { differenceBy };

View file

@ -0,0 +1,22 @@
//#region src/fp/array/differenceBy.d.ts
/**
* Creates a function that returns values whose mapped identity is absent from another array.
*
* The mapper is applied to values from both arrays. The returned function is
* lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the piped array.
* @template U - The type of elements in the configured array.
* @param secondArray - Values to exclude from the piped array after mapping.
* @param mapper - Maps values from both arrays to comparison keys.
* @returns A function that maps the piped array to its mapped difference.
*
* @example
* import { differenceBy, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }], differenceBy([2], value => typeof value === 'number' ? value : value.id));
* // => [{ id: 1 }]
*/
declare function differenceBy<T, U>(secondArray: readonly U[], mapper: (value: T | U) => unknown): (array: readonly T[]) => T[];
//#endregion
export { differenceBy };

View file

@ -0,0 +1,33 @@
const require_differenceBy = require("../../array/differenceBy.js");
const require_lazy = require("../_internal/lazy.js");
//#region src/fp/array/differenceBy.ts
/**
* Creates a function that returns values whose mapped identity is absent from another array.
*
* The mapper is applied to values from both arrays. The returned function is
* lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the piped array.
* @template U - The type of elements in the configured array.
* @param secondArray - Values to exclude from the piped array after mapping.
* @param mapper - Maps values from both arrays to comparison keys.
* @returns A function that maps the piped array to its mapped difference.
*
* @example
* import { differenceBy, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }], differenceBy([2], value => typeof value === 'number' ? value : value.id));
* // => [{ id: 1 }]
*/
function differenceBy(secondArray, mapper) {
const mappedSecondSet = new Set(secondArray.map((item) => mapper(item)));
function differenceByEager(array) {
return require_differenceBy.differenceBy(array, secondArray, mapper);
}
const differenceByLazy = require_lazy.createLazyFunction((value, _index, emit) => {
if (!mappedSecondSet.has(mapper(value))) emit(value);
});
return require_lazy.combineEagerAndLazyFunctions(differenceByEager, differenceByLazy);
}
//#endregion
exports.differenceBy = differenceBy;

View file

@ -0,0 +1,32 @@
import { differenceBy as differenceBy$1 } from "../../array/differenceBy.mjs";
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
//#region src/fp/array/differenceBy.ts
/**
* Creates a function that returns values whose mapped identity is absent from another array.
*
* The mapper is applied to values from both arrays. The returned function is
* lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the piped array.
* @template U - The type of elements in the configured array.
* @param secondArray - Values to exclude from the piped array after mapping.
* @param mapper - Maps values from both arrays to comparison keys.
* @returns A function that maps the piped array to its mapped difference.
*
* @example
* import { differenceBy, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }], differenceBy([2], value => typeof value === 'number' ? value : value.id));
* // => [{ id: 1 }]
*/
function differenceBy(secondArray, mapper) {
const mappedSecondSet = new Set(secondArray.map((item) => mapper(item)));
function differenceByEager(array) {
return differenceBy$1(array, secondArray, mapper);
}
return combineEagerAndLazyFunctions(differenceByEager, createLazyFunction((value, _index, emit) => {
if (!mappedSecondSet.has(mapper(value))) emit(value);
}));
}
//#endregion
export { differenceBy };

View file

@ -0,0 +1,22 @@
//#region src/fp/array/differenceWith.d.ts
/**
* Creates a function that returns values that are not equal to any configured value.
*
* Equality is decided by the provided comparator. The returned function is
* lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the piped array.
* @template U - The type of elements in the configured array.
* @param secondArray - Values to compare against the piped array.
* @param areItemsEqual - Returns true when a piped value equals a configured value.
* @returns A function that maps the piped array to its custom difference.
*
* @example
* import { differenceWith, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }], differenceWith([2], (item, id) => item.id === id));
* // => [{ id: 1 }]
*/
declare function differenceWith<T, U>(secondArray: readonly U[], areItemsEqual: (item: T, other: U) => boolean): (array: readonly T[]) => T[];
//#endregion
export { differenceWith };

View file

@ -0,0 +1,22 @@
//#region src/fp/array/differenceWith.d.ts
/**
* Creates a function that returns values that are not equal to any configured value.
*
* Equality is decided by the provided comparator. The returned function is
* lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the piped array.
* @template U - The type of elements in the configured array.
* @param secondArray - Values to compare against the piped array.
* @param areItemsEqual - Returns true when a piped value equals a configured value.
* @returns A function that maps the piped array to its custom difference.
*
* @example
* import { differenceWith, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }], differenceWith([2], (item, id) => item.id === id));
* // => [{ id: 1 }]
*/
declare function differenceWith<T, U>(secondArray: readonly U[], areItemsEqual: (item: T, other: U) => boolean): (array: readonly T[]) => T[];
//#endregion
export { differenceWith };

View file

@ -0,0 +1,32 @@
const require_differenceWith = require("../../array/differenceWith.js");
const require_lazy = require("../_internal/lazy.js");
//#region src/fp/array/differenceWith.ts
/**
* Creates a function that returns values that are not equal to any configured value.
*
* Equality is decided by the provided comparator. The returned function is
* lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the piped array.
* @template U - The type of elements in the configured array.
* @param secondArray - Values to compare against the piped array.
* @param areItemsEqual - Returns true when a piped value equals a configured value.
* @returns A function that maps the piped array to its custom difference.
*
* @example
* import { differenceWith, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }], differenceWith([2], (item, id) => item.id === id));
* // => [{ id: 1 }]
*/
function differenceWith(secondArray, areItemsEqual) {
function differenceWithEager(array) {
return require_differenceWith.differenceWith(array, secondArray, areItemsEqual);
}
const differenceWithLazy = require_lazy.createLazyFunction((value, _index, emit) => {
if (secondArray.every((other) => !areItemsEqual(value, other))) emit(value);
});
return require_lazy.combineEagerAndLazyFunctions(differenceWithEager, differenceWithLazy);
}
//#endregion
exports.differenceWith = differenceWith;

View file

@ -0,0 +1,31 @@
import { differenceWith as differenceWith$1 } from "../../array/differenceWith.mjs";
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
//#region src/fp/array/differenceWith.ts
/**
* Creates a function that returns values that are not equal to any configured value.
*
* Equality is decided by the provided comparator. The returned function is
* lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the piped array.
* @template U - The type of elements in the configured array.
* @param secondArray - Values to compare against the piped array.
* @param areItemsEqual - Returns true when a piped value equals a configured value.
* @returns A function that maps the piped array to its custom difference.
*
* @example
* import { differenceWith, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }], differenceWith([2], (item, id) => item.id === id));
* // => [{ id: 1 }]
*/
function differenceWith(secondArray, areItemsEqual) {
function differenceWithEager(array) {
return differenceWith$1(array, secondArray, areItemsEqual);
}
return combineEagerAndLazyFunctions(differenceWithEager, createLazyFunction((value, _index, emit) => {
if (secondArray.every((other) => !areItemsEqual(value, other))) emit(value);
}));
}
//#endregion
export { differenceWith };

View file

@ -0,0 +1,20 @@
//#region src/fp/array/drop.d.ts
/**
* Creates a function that removes a number of values from the start of an array.
*
* Negative counts are treated as 0, matching the main {@link drop}
* implementation. The returned function is lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the array.
* @param count - The number of values to skip from the start.
* @returns A function that maps the piped array to the remaining suffix.
*
* @example
* import { drop, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], drop(2));
* // => [3, 4]
*/
declare function drop<T>(count: number): (array: readonly T[]) => T[];
//#endregion
export { drop };

View file

@ -0,0 +1,20 @@
//#region src/fp/array/drop.d.ts
/**
* Creates a function that removes a number of values from the start of an array.
*
* Negative counts are treated as 0, matching the main {@link drop}
* implementation. The returned function is lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the array.
* @param count - The number of values to skip from the start.
* @returns A function that maps the piped array to the remaining suffix.
*
* @example
* import { drop, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], drop(2));
* // => [3, 4]
*/
declare function drop<T>(count: number): (array: readonly T[]) => T[];
//#endregion
export { drop };

31
frontend/node_modules/es-toolkit/dist/fp/array/drop.js generated vendored Normal file
View file

@ -0,0 +1,31 @@
const require_drop = require("../../array/drop.js");
const require_lazy = require("../_internal/lazy.js");
//#region src/fp/array/drop.ts
/**
* Creates a function that removes a number of values from the start of an array.
*
* Negative counts are treated as 0, matching the main {@link drop}
* implementation. The returned function is lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the array.
* @param count - The number of values to skip from the start.
* @returns A function that maps the piped array to the remaining suffix.
*
* @example
* import { drop, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], drop(2));
* // => [3, 4]
*/
function drop(count) {
const normalizedCount = Number.isNaN(count) ? 0 : Math.trunc(Math.max(count, 0));
function dropEager(array) {
return require_drop.drop(array, count);
}
const dropLazy = require_lazy.createLazyFunction((value, index, emit) => {
if (index >= normalizedCount) emit(value);
});
return require_lazy.combineEagerAndLazyFunctions(dropEager, dropLazy);
}
//#endregion
exports.drop = drop;

View file

@ -0,0 +1,30 @@
import { drop as drop$1 } from "../../array/drop.mjs";
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
//#region src/fp/array/drop.ts
/**
* Creates a function that removes a number of values from the start of an array.
*
* Negative counts are treated as 0, matching the main {@link drop}
* implementation. The returned function is lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the array.
* @param count - The number of values to skip from the start.
* @returns A function that maps the piped array to the remaining suffix.
*
* @example
* import { drop, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], drop(2));
* // => [3, 4]
*/
function drop(count) {
const normalizedCount = Number.isNaN(count) ? 0 : Math.trunc(Math.max(count, 0));
function dropEager(array) {
return drop$1(array, count);
}
return combineEagerAndLazyFunctions(dropEager, createLazyFunction((value, index, emit) => {
if (index >= normalizedCount) emit(value);
}));
}
//#endregion
export { drop };

View file

@ -0,0 +1,20 @@
//#region src/fp/array/dropRight.d.ts
/**
* Creates a function that removes a number of values from the end of an array.
*
* The returned function follows the main {@link dropRight} behavior and returns a new array.
* Use it with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param count - The number of values to drop from the end.
* @returns A function that maps a readonly array to the remaining prefix.
*
* @example
* import { dropRight, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], dropRight(2));
* // => [1, 2]
*/
declare function dropRight<T>(count: number): (array: readonly T[]) => T[];
//#endregion
export { dropRight };

View file

@ -0,0 +1,20 @@
//#region src/fp/array/dropRight.d.ts
/**
* Creates a function that removes a number of values from the end of an array.
*
* The returned function follows the main {@link dropRight} behavior and returns a new array.
* Use it with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param count - The number of values to drop from the end.
* @returns A function that maps a readonly array to the remaining prefix.
*
* @example
* import { dropRight, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], dropRight(2));
* // => [1, 2]
*/
declare function dropRight<T>(count: number): (array: readonly T[]) => T[];
//#endregion
export { dropRight };

View file

@ -0,0 +1,25 @@
const require_dropRight = require("../../array/dropRight.js");
//#region src/fp/array/dropRight.ts
/**
* Creates a function that removes a number of values from the end of an array.
*
* The returned function follows the main {@link dropRight} behavior and returns a new array.
* Use it with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param count - The number of values to drop from the end.
* @returns A function that maps a readonly array to the remaining prefix.
*
* @example
* import { dropRight, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], dropRight(2));
* // => [1, 2]
*/
function dropRight(count) {
return function(array) {
return require_dropRight.dropRight(array, count);
};
}
//#endregion
exports.dropRight = dropRight;

View file

@ -0,0 +1,25 @@
import { dropRight as dropRight$1 } from "../../array/dropRight.mjs";
//#region src/fp/array/dropRight.ts
/**
* Creates a function that removes a number of values from the end of an array.
*
* The returned function follows the main {@link dropRight} behavior and returns a new array.
* Use it with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param count - The number of values to drop from the end.
* @returns A function that maps a readonly array to the remaining prefix.
*
* @example
* import { dropRight, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], dropRight(2));
* // => [1, 2]
*/
function dropRight(count) {
return function(array) {
return dropRight$1(array, count);
};
}
//#endregion
export { dropRight };

View file

@ -0,0 +1,20 @@
//#region src/fp/array/dropRightWhile.d.ts
/**
* Creates a function that drops trailing values while a predicate returns true.
*
* The predicate is evaluated from right to left and receives the value, index, and full
* input array. Use the returned function with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each value, index, and array while dropping from the end.
* @returns A function that maps a readonly array to the remaining prefix.
*
* @example
* import { dropRightWhile, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], dropRightWhile(value => value > 2));
* // => [1, 2]
*/
declare function dropRightWhile<T>(predicate: (item: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => T[];
//#endregion
export { dropRightWhile };

View file

@ -0,0 +1,20 @@
//#region src/fp/array/dropRightWhile.d.ts
/**
* Creates a function that drops trailing values while a predicate returns true.
*
* The predicate is evaluated from right to left and receives the value, index, and full
* input array. Use the returned function with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each value, index, and array while dropping from the end.
* @returns A function that maps a readonly array to the remaining prefix.
*
* @example
* import { dropRightWhile, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], dropRightWhile(value => value > 2));
* // => [1, 2]
*/
declare function dropRightWhile<T>(predicate: (item: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => T[];
//#endregion
export { dropRightWhile };

View file

@ -0,0 +1,25 @@
const require_dropRightWhile = require("../../array/dropRightWhile.js");
//#region src/fp/array/dropRightWhile.ts
/**
* Creates a function that drops trailing values while a predicate returns true.
*
* The predicate is evaluated from right to left and receives the value, index, and full
* input array. Use the returned function with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each value, index, and array while dropping from the end.
* @returns A function that maps a readonly array to the remaining prefix.
*
* @example
* import { dropRightWhile, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], dropRightWhile(value => value > 2));
* // => [1, 2]
*/
function dropRightWhile(predicate) {
return function(array) {
return require_dropRightWhile.dropRightWhile(array, predicate);
};
}
//#endregion
exports.dropRightWhile = dropRightWhile;

View file

@ -0,0 +1,25 @@
import { dropRightWhile as dropRightWhile$1 } from "../../array/dropRightWhile.mjs";
//#region src/fp/array/dropRightWhile.ts
/**
* Creates a function that drops trailing values while a predicate returns true.
*
* The predicate is evaluated from right to left and receives the value, index, and full
* input array. Use the returned function with {@link pipe}.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each value, index, and array while dropping from the end.
* @returns A function that maps a readonly array to the remaining prefix.
*
* @example
* import { dropRightWhile, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], dropRightWhile(value => value > 2));
* // => [1, 2]
*/
function dropRightWhile(predicate) {
return function(array) {
return dropRightWhile$1(array, predicate);
};
}
//#endregion
export { dropRightWhile };

View file

@ -0,0 +1,20 @@
//#region src/fp/array/dropWhile.d.ts
/**
* Creates a function that removes leading values while a predicate returns true.
*
* Once the predicate returns false, that value and all following values are
* emitted. The returned function is lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each leading value and index while values are being dropped.
* @returns A function that maps the piped array to the remaining suffix.
*
* @example
* import { dropWhile, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 1], dropWhile(value => value < 3));
* // => [3, 1]
*/
declare function dropWhile<T>(predicate: (item: T, index: number) => boolean): (array: readonly T[]) => T[];
//#endregion
export { dropWhile };

View file

@ -0,0 +1,20 @@
//#region src/fp/array/dropWhile.d.ts
/**
* Creates a function that removes leading values while a predicate returns true.
*
* Once the predicate returns false, that value and all following values are
* emitted. The returned function is lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each leading value and index while values are being dropped.
* @returns A function that maps the piped array to the remaining suffix.
*
* @example
* import { dropWhile, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 1], dropWhile(value => value < 3));
* // => [3, 1]
*/
declare function dropWhile<T>(predicate: (item: T, index: number) => boolean): (array: readonly T[]) => T[];
//#endregion
export { dropWhile };

View file

@ -0,0 +1,36 @@
const require_dropWhile = require("../../array/dropWhile.js");
const require_lazy = require("../_internal/lazy.js");
//#region src/fp/array/dropWhile.ts
/**
* Creates a function that removes leading values while a predicate returns true.
*
* Once the predicate returns false, that value and all following values are
* emitted. The returned function is lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each leading value and index while values are being dropped.
* @returns A function that maps the piped array to the remaining suffix.
*
* @example
* import { dropWhile, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 1], dropWhile(value => value < 3));
* // => [3, 1]
*/
function dropWhile(predicate) {
function dropWhileEager(array) {
return require_dropWhile.dropWhile(array, (item, index) => predicate(item, index));
}
const dropWhileLazy = (emit) => {
let dropping = true;
let index = 0;
return (value) => {
if (dropping && predicate(value, index++)) return true;
dropping = false;
return emit(value);
};
};
return require_lazy.combineEagerAndLazyFunctions(dropWhileEager, dropWhileLazy);
}
//#endregion
exports.dropWhile = dropWhile;

View file

@ -0,0 +1,36 @@
import { dropWhile as dropWhile$1 } from "../../array/dropWhile.mjs";
import { combineEagerAndLazyFunctions } from "../_internal/lazy.mjs";
//#region src/fp/array/dropWhile.ts
/**
* Creates a function that removes leading values while a predicate returns true.
*
* Once the predicate returns false, that value and all following values are
* emitted. The returned function is lazy-capable inside {@link pipe}.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each leading value and index while values are being dropped.
* @returns A function that maps the piped array to the remaining suffix.
*
* @example
* import { dropWhile, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 1], dropWhile(value => value < 3));
* // => [3, 1]
*/
function dropWhile(predicate) {
function dropWhileEager(array) {
return dropWhile$1(array, (item, index) => predicate(item, index));
}
const dropWhileLazy = (emit) => {
let dropping = true;
let index = 0;
return (value) => {
if (dropping && predicate(value, index++)) return true;
dropping = false;
return emit(value);
};
};
return combineEagerAndLazyFunctions(dropWhileEager, dropWhileLazy);
}
//#endregion
export { dropWhile };

View file

@ -0,0 +1,45 @@
//#region src/fp/array/filter.d.ts
/**
* Creates a function that keeps only the elements for which `predicate` returns
* a truthy value, equivalent to `Array.prototype.filter`. A type predicate
* narrows the element type of the result. Use it with {@link pipe}.
*
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
* with adjacent lazy functions and runs element-by-element.
*
* @template T - The type of elements in the input array.
* @template S - The narrowed element type when `predicate` is a type guard.
* @param predicate - Called with `(value, index)` for each element; return
* `true` to keep the element.
* @returns A function that maps a `readonly T[]` to a filtered array.
*
* @example
* import { pipe, filter } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], filter(x => x % 2 === 0)); // => [2, 4]
*
* @example
* // A type guard narrows the result type to `string[]`.
* pipe([1, 'a', 2, 'b'], filter((x): x is string => typeof x === 'string')); // => ['a', 'b']
*/
declare function filter<T, S extends T>(predicate: (value: T, index: number) => value is S): (array: readonly T[]) => S[];
/**
* Creates a function that keeps only the elements for which `predicate` returns
* a truthy value, equivalent to `Array.prototype.filter`. Use it with {@link pipe}.
*
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
* with adjacent lazy functions and runs element-by-element.
*
* @template T - The type of elements in the input array.
* @param predicate - Called with `(value, index)` for each element; return
* `true` to keep the element.
* @returns A function that maps a `readonly T[]` to a filtered array.
*
* @example
* import { pipe, filter } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], filter(x => x % 2 === 0)); // => [2, 4]
*/
declare function filter<T>(predicate: (value: T, index: number) => boolean): (array: readonly T[]) => T[];
//#endregion
export { filter };

View file

@ -0,0 +1,45 @@
//#region src/fp/array/filter.d.ts
/**
* Creates a function that keeps only the elements for which `predicate` returns
* a truthy value, equivalent to `Array.prototype.filter`. A type predicate
* narrows the element type of the result. Use it with {@link pipe}.
*
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
* with adjacent lazy functions and runs element-by-element.
*
* @template T - The type of elements in the input array.
* @template S - The narrowed element type when `predicate` is a type guard.
* @param predicate - Called with `(value, index)` for each element; return
* `true` to keep the element.
* @returns A function that maps a `readonly T[]` to a filtered array.
*
* @example
* import { pipe, filter } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], filter(x => x % 2 === 0)); // => [2, 4]
*
* @example
* // A type guard narrows the result type to `string[]`.
* pipe([1, 'a', 2, 'b'], filter((x): x is string => typeof x === 'string')); // => ['a', 'b']
*/
declare function filter<T, S extends T>(predicate: (value: T, index: number) => value is S): (array: readonly T[]) => S[];
/**
* Creates a function that keeps only the elements for which `predicate` returns
* a truthy value, equivalent to `Array.prototype.filter`. Use it with {@link pipe}.
*
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
* with adjacent lazy functions and runs element-by-element.
*
* @template T - The type of elements in the input array.
* @param predicate - Called with `(value, index)` for each element; return
* `true` to keep the element.
* @returns A function that maps a `readonly T[]` to a filtered array.
*
* @example
* import { pipe, filter } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 4], filter(x => x % 2 === 0)); // => [2, 4]
*/
declare function filter<T>(predicate: (value: T, index: number) => boolean): (array: readonly T[]) => T[];
//#endregion
export { filter };

View file

@ -0,0 +1,13 @@
const require_lazy = require("../_internal/lazy.js");
//#region src/fp/array/filter.ts
function filter(predicate) {
function filterEager(array) {
return array.filter(predicate);
}
const filterLazy = require_lazy.createLazyFunction((value, index, emit) => {
if (predicate(value, index)) emit(value);
});
return require_lazy.combineEagerAndLazyFunctions(filterEager, filterLazy);
}
//#endregion
exports.filter = filter;

View file

@ -0,0 +1,12 @@
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
//#region src/fp/array/filter.ts
function filter(predicate) {
function filterEager(array) {
return array.filter(predicate);
}
return combineEagerAndLazyFunctions(filterEager, createLazyFunction((value, index, emit) => {
if (predicate(value, index)) emit(value);
}));
}
//#endregion
export { filter };

View file

@ -0,0 +1,39 @@
//#region src/fp/array/find.d.ts
/**
* Creates a function that returns the first value accepted by a type guard.
*
* The predicate receives the value, index, and full input array. The returned
* function returns undefined when no value matches.
*
* @template T - The type of elements in the array.
* @template S - The narrowed element type accepted by the type guard.
* @param predicate - Type guard called with each value, index, and array until it returns true.
* @returns A function that maps a readonly array to the first matching value, or undefined.
*
* @example
* import { find, pipe } from 'es-toolkit/fp';
*
* const isString = (value: string | number): value is string => typeof value === 'string';
* pipe([1, 'a', 2], find(isString));
* // => 'a'
*/
declare function find<T, S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S): (array: readonly T[]) => S | undefined;
/**
* Creates a function that returns the first value matching a predicate.
*
* The predicate receives the value, index, and full input array. The returned
* function returns undefined when no value matches.
*
* @template T - The type of elements in the array.
* @param predicate - Predicate called with each value, index, and array until it returns true.
* @returns A function that maps a readonly array to the first matching value, or undefined.
*
* @example
* import { find, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }], find(item => item.id === 2));
* // => { id: 2 }
*/
declare function find<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => T | undefined;
//#endregion
export { find };

View file

@ -0,0 +1,39 @@
//#region src/fp/array/find.d.ts
/**
* Creates a function that returns the first value accepted by a type guard.
*
* The predicate receives the value, index, and full input array. The returned
* function returns undefined when no value matches.
*
* @template T - The type of elements in the array.
* @template S - The narrowed element type accepted by the type guard.
* @param predicate - Type guard called with each value, index, and array until it returns true.
* @returns A function that maps a readonly array to the first matching value, or undefined.
*
* @example
* import { find, pipe } from 'es-toolkit/fp';
*
* const isString = (value: string | number): value is string => typeof value === 'string';
* pipe([1, 'a', 2], find(isString));
* // => 'a'
*/
declare function find<T, S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S): (array: readonly T[]) => S | undefined;
/**
* Creates a function that returns the first value matching a predicate.
*
* The predicate receives the value, index, and full input array. The returned
* function returns undefined when no value matches.
*
* @template T - The type of elements in the array.
* @param predicate - Predicate called with each value, index, and array until it returns true.
* @returns A function that maps a readonly array to the first matching value, or undefined.
*
* @example
* import { find, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }], find(item => item.id === 2));
* // => { id: 2 }
*/
declare function find<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => T | undefined;
//#endregion
export { find };

View file

@ -0,0 +1,8 @@
//#region src/fp/array/find.ts
function find(predicate) {
return function(array) {
return array.find(predicate);
};
}
//#endregion
exports.find = find;

View file

@ -0,0 +1,8 @@
//#region src/fp/array/find.ts
function find(predicate) {
return function(array) {
return array.find(predicate);
};
}
//#endregion
export { find };

View file

@ -0,0 +1,20 @@
//#region src/fp/array/findIndex.d.ts
/**
* Creates a function that returns the index of the first value matching a predicate.
*
* The predicate receives the value, index, and full input array. The returned function
* returns -1 when no value matches, matching Array.prototype.findIndex.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each value, index, and array until it returns true.
* @returns A function that maps a readonly array to the first matching index, or -1.
*
* @example
* import { findIndex, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }], findIndex(item => item.id === 2));
* // => 1
*/
declare function findIndex<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => number;
//#endregion
export { findIndex };

View file

@ -0,0 +1,20 @@
//#region src/fp/array/findIndex.d.ts
/**
* Creates a function that returns the index of the first value matching a predicate.
*
* The predicate receives the value, index, and full input array. The returned function
* returns -1 when no value matches, matching Array.prototype.findIndex.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each value, index, and array until it returns true.
* @returns A function that maps a readonly array to the first matching index, or -1.
*
* @example
* import { findIndex, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }], findIndex(item => item.id === 2));
* // => 1
*/
declare function findIndex<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => number;
//#endregion
export { findIndex };

View file

@ -0,0 +1,24 @@
//#region src/fp/array/findIndex.ts
/**
* Creates a function that returns the index of the first value matching a predicate.
*
* The predicate receives the value, index, and full input array. The returned function
* returns -1 when no value matches, matching Array.prototype.findIndex.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each value, index, and array until it returns true.
* @returns A function that maps a readonly array to the first matching index, or -1.
*
* @example
* import { findIndex, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }], findIndex(item => item.id === 2));
* // => 1
*/
function findIndex(predicate) {
return function(array) {
return array.findIndex(predicate);
};
}
//#endregion
exports.findIndex = findIndex;

View file

@ -0,0 +1,24 @@
//#region src/fp/array/findIndex.ts
/**
* Creates a function that returns the index of the first value matching a predicate.
*
* The predicate receives the value, index, and full input array. The returned function
* returns -1 when no value matches, matching Array.prototype.findIndex.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each value, index, and array until it returns true.
* @returns A function that maps a readonly array to the first matching index, or -1.
*
* @example
* import { findIndex, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }], findIndex(item => item.id === 2));
* // => 1
*/
function findIndex(predicate) {
return function(array) {
return array.findIndex(predicate);
};
}
//#endregion
export { findIndex };

View file

@ -0,0 +1,39 @@
//#region src/fp/array/findLast.d.ts
/**
* Creates a function that returns the last value accepted by a type guard.
*
* The predicate receives the value, index, and full input array while scanning
* from right to left. The returned function returns undefined when no value matches.
*
* @template T - The type of elements in the array.
* @template S - The narrowed element type accepted by the type guard.
* @param predicate - Type guard called with each value, index, and array from right to left.
* @returns A function that maps a readonly array to the last matching value, or undefined.
*
* @example
* import { findLast, pipe } from 'es-toolkit/fp';
*
* const isString = (value: string | number): value is string => typeof value === 'string';
* pipe([1, 'a', 2, 'b'], findLast(isString));
* // => 'b'
*/
declare function findLast<T, S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S): (array: readonly T[]) => S | undefined;
/**
* Creates a function that returns the last value matching a predicate.
*
* The predicate receives the value, index, and full input array while scanning
* from right to left. The returned function returns undefined when no value matches.
*
* @template T - The type of elements in the array.
* @param predicate - Predicate called with each value, index, and array from right to left.
* @returns A function that maps a readonly array to the last matching value, or undefined.
*
* @example
* import { findLast, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }, { id: 1 }], findLast(item => item.id === 1));
* // => { id: 1 }
*/
declare function findLast<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => T | undefined;
//#endregion
export { findLast };

View file

@ -0,0 +1,39 @@
//#region src/fp/array/findLast.d.ts
/**
* Creates a function that returns the last value accepted by a type guard.
*
* The predicate receives the value, index, and full input array while scanning
* from right to left. The returned function returns undefined when no value matches.
*
* @template T - The type of elements in the array.
* @template S - The narrowed element type accepted by the type guard.
* @param predicate - Type guard called with each value, index, and array from right to left.
* @returns A function that maps a readonly array to the last matching value, or undefined.
*
* @example
* import { findLast, pipe } from 'es-toolkit/fp';
*
* const isString = (value: string | number): value is string => typeof value === 'string';
* pipe([1, 'a', 2, 'b'], findLast(isString));
* // => 'b'
*/
declare function findLast<T, S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S): (array: readonly T[]) => S | undefined;
/**
* Creates a function that returns the last value matching a predicate.
*
* The predicate receives the value, index, and full input array while scanning
* from right to left. The returned function returns undefined when no value matches.
*
* @template T - The type of elements in the array.
* @param predicate - Predicate called with each value, index, and array from right to left.
* @returns A function that maps a readonly array to the last matching value, or undefined.
*
* @example
* import { findLast, pipe } from 'es-toolkit/fp';
*
* pipe([{ id: 1 }, { id: 2 }, { id: 1 }], findLast(item => item.id === 1));
* // => { id: 1 }
*/
declare function findLast<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => T | undefined;
//#endregion
export { findLast };

View file

@ -0,0 +1,11 @@
//#region src/fp/array/findLast.ts
function findLast(predicate) {
return function(array) {
for (let index = array.length - 1; index >= 0; index--) {
const value = array[index];
if (predicate(value, index, array)) return value;
}
};
}
//#endregion
exports.findLast = findLast;

View file

@ -0,0 +1,11 @@
//#region src/fp/array/findLast.ts
function findLast(predicate) {
return function(array) {
for (let index = array.length - 1; index >= 0; index--) {
const value = array[index];
if (predicate(value, index, array)) return value;
}
};
}
//#endregion
export { findLast };

View file

@ -0,0 +1,20 @@
//#region src/fp/array/findLastIndex.d.ts
/**
* Creates a function that returns the index of the last value matching a predicate.
*
* The predicate receives the value, index, and full input array while scanning from right
* to left. The returned function returns -1 when no value matches.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each value, index, and array from right to left until it returns true.
* @returns A function that maps a readonly array to the last matching index, or -1.
*
* @example
* import { findLastIndex, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 2], findLastIndex(value => value === 2));
* // => 3
*/
declare function findLastIndex<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => number;
//#endregion
export { findLastIndex };

View file

@ -0,0 +1,20 @@
//#region src/fp/array/findLastIndex.d.ts
/**
* Creates a function that returns the index of the last value matching a predicate.
*
* The predicate receives the value, index, and full input array while scanning from right
* to left. The returned function returns -1 when no value matches.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each value, index, and array from right to left until it returns true.
* @returns A function that maps a readonly array to the last matching index, or -1.
*
* @example
* import { findLastIndex, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 2], findLastIndex(value => value === 2));
* // => 3
*/
declare function findLastIndex<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => number;
//#endregion
export { findLastIndex };

View file

@ -0,0 +1,25 @@
//#region src/fp/array/findLastIndex.ts
/**
* Creates a function that returns the index of the last value matching a predicate.
*
* The predicate receives the value, index, and full input array while scanning from right
* to left. The returned function returns -1 when no value matches.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each value, index, and array from right to left until it returns true.
* @returns A function that maps a readonly array to the last matching index, or -1.
*
* @example
* import { findLastIndex, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 2], findLastIndex(value => value === 2));
* // => 3
*/
function findLastIndex(predicate) {
return function(array) {
for (let index = array.length - 1; index >= 0; index--) if (predicate(array[index], index, array)) return index;
return -1;
};
}
//#endregion
exports.findLastIndex = findLastIndex;

View file

@ -0,0 +1,25 @@
//#region src/fp/array/findLastIndex.ts
/**
* Creates a function that returns the index of the last value matching a predicate.
*
* The predicate receives the value, index, and full input array while scanning from right
* to left. The returned function returns -1 when no value matches.
*
* @template T - The type of elements in the array.
* @param predicate - Called with each value, index, and array from right to left until it returns true.
* @returns A function that maps a readonly array to the last matching index, or -1.
*
* @example
* import { findLastIndex, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3, 2], findLastIndex(value => value === 2));
* // => 3
*/
function findLastIndex(predicate) {
return function(array) {
for (let index = array.length - 1; index >= 0; index--) if (predicate(array[index], index, array)) return index;
return -1;
};
}
//#endregion
export { findLastIndex };

View file

@ -0,0 +1,28 @@
//#region src/fp/array/flatMap.d.ts
/**
* Creates a function that maps every element to an array with `callback` and
* concatenates the results, equivalent to `Array.prototype.flatMap`. Use it
* with {@link pipe}.
*
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
* with adjacent lazy functions and runs element-by-element, so a trailing
* `take` can terminate the walk early without expanding the rest of the input.
*
* @template T - The type of elements in the input array.
* @template U - The type of elements in the output array.
* @param callback - Called with `(value, index)` for each element; returns an
* array whose elements are flattened into the output.
* @returns A function that maps a `readonly T[]` to a new `U[]`.
*
* @example
* import { pipe, flatMap } from 'es-toolkit/fp';
*
* pipe([1, 2, 3], flatMap(x => [x, x * 10])); // => [1, 10, 2, 20, 3, 30]
*
* @example
* // Returning an empty array drops the element.
* pipe([1, 2, 3, 4], flatMap(x => (x % 2 === 0 ? [x] : []))); // => [2, 4]
*/
declare function flatMap<T, U>(callback: (value: T, index: number) => U[]): (array: readonly T[]) => U[];
//#endregion
export { flatMap };

View file

@ -0,0 +1,28 @@
//#region src/fp/array/flatMap.d.ts
/**
* Creates a function that maps every element to an array with `callback` and
* concatenates the results, equivalent to `Array.prototype.flatMap`. Use it
* with {@link pipe}.
*
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
* with adjacent lazy functions and runs element-by-element, so a trailing
* `take` can terminate the walk early without expanding the rest of the input.
*
* @template T - The type of elements in the input array.
* @template U - The type of elements in the output array.
* @param callback - Called with `(value, index)` for each element; returns an
* array whose elements are flattened into the output.
* @returns A function that maps a `readonly T[]` to a new `U[]`.
*
* @example
* import { pipe, flatMap } from 'es-toolkit/fp';
*
* pipe([1, 2, 3], flatMap(x => [x, x * 10])); // => [1, 10, 2, 20, 3, 30]
*
* @example
* // Returning an empty array drops the element.
* pipe([1, 2, 3, 4], flatMap(x => (x % 2 === 0 ? [x] : []))); // => [2, 4]
*/
declare function flatMap<T, U>(callback: (value: T, index: number) => U[]): (array: readonly T[]) => U[];
//#endregion
export { flatMap };

View file

@ -0,0 +1,39 @@
const require_flatMap = require("../../array/flatMap.js");
const require_lazy = require("../_internal/lazy.js");
//#region src/fp/array/flatMap.ts
/**
* Creates a function that maps every element to an array with `callback` and
* concatenates the results, equivalent to `Array.prototype.flatMap`. Use it
* with {@link pipe}.
*
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
* with adjacent lazy functions and runs element-by-element, so a trailing
* `take` can terminate the walk early without expanding the rest of the input.
*
* @template T - The type of elements in the input array.
* @template U - The type of elements in the output array.
* @param callback - Called with `(value, index)` for each element; returns an
* array whose elements are flattened into the output.
* @returns A function that maps a `readonly T[]` to a new `U[]`.
*
* @example
* import { pipe, flatMap } from 'es-toolkit/fp';
*
* pipe([1, 2, 3], flatMap(x => [x, x * 10])); // => [1, 10, 2, 20, 3, 30]
*
* @example
* // Returning an empty array drops the element.
* pipe([1, 2, 3, 4], flatMap(x => (x % 2 === 0 ? [x] : []))); // => [2, 4]
*/
function flatMap(callback) {
function flatMapEager(array) {
return require_flatMap.flatMap(array, callback);
}
const flatMapLazy = require_lazy.createLazyFunction((value, index, emit) => {
const items = callback(value, index);
for (let i = 0; i < items.length; i++) emit(items[i]);
});
return require_lazy.combineEagerAndLazyFunctions(flatMapEager, flatMapLazy);
}
//#endregion
exports.flatMap = flatMap;

View file

@ -0,0 +1,38 @@
import { flatMap as flatMap$1 } from "../../array/flatMap.mjs";
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
//#region src/fp/array/flatMap.ts
/**
* Creates a function that maps every element to an array with `callback` and
* concatenates the results, equivalent to `Array.prototype.flatMap`. Use it
* with {@link pipe}.
*
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
* with adjacent lazy functions and runs element-by-element, so a trailing
* `take` can terminate the walk early without expanding the rest of the input.
*
* @template T - The type of elements in the input array.
* @template U - The type of elements in the output array.
* @param callback - Called with `(value, index)` for each element; returns an
* array whose elements are flattened into the output.
* @returns A function that maps a `readonly T[]` to a new `U[]`.
*
* @example
* import { pipe, flatMap } from 'es-toolkit/fp';
*
* pipe([1, 2, 3], flatMap(x => [x, x * 10])); // => [1, 10, 2, 20, 3, 30]
*
* @example
* // Returning an empty array drops the element.
* pipe([1, 2, 3, 4], flatMap(x => (x % 2 === 0 ? [x] : []))); // => [2, 4]
*/
function flatMap(callback) {
function flatMapEager(array) {
return flatMap$1(array, callback);
}
return combineEagerAndLazyFunctions(flatMapEager, createLazyFunction((value, index, emit) => {
const items = callback(value, index);
for (let i = 0; i < items.length; i++) emit(items[i]);
}));
}
//#endregion
export { flatMap };

View file

@ -0,0 +1,23 @@
import { ExtractNestedArrayType } from "../../array/flattenDeep.mjs";
//#region src/fp/array/flatMapDeep.d.ts
/**
* Creates a function that maps each element and recursively flattens the mapped values.
*
* The iteratee receives each value and index. The returned function is lazy-capable inside
* {@link pipe}; a trailing short-circuiting operator can stop before later input values are mapped.
*
* @template T - The type of elements in the input array.
* @template U - The type returned by the iteratee before recursive flattening.
* @param iteratee - Called with each value and index to produce values to flatten.
* @returns A function that maps a readonly array to a deeply flattened array.
*
* @example
* import { flatMapDeep, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2], flatMapDeep(value => [[value, value * 10]]));
* // => [1, 10, 2, 20]
*/
declare function flatMapDeep<T, U>(iteratee: (item: T, index: number) => U): (array: readonly T[]) => Array<ExtractNestedArrayType<U>>;
//#endregion
export { flatMapDeep };

View file

@ -0,0 +1,23 @@
import { ExtractNestedArrayType } from "../../array/flattenDeep.js";
//#region src/fp/array/flatMapDeep.d.ts
/**
* Creates a function that maps each element and recursively flattens the mapped values.
*
* The iteratee receives each value and index. The returned function is lazy-capable inside
* {@link pipe}; a trailing short-circuiting operator can stop before later input values are mapped.
*
* @template T - The type of elements in the input array.
* @template U - The type returned by the iteratee before recursive flattening.
* @param iteratee - Called with each value and index to produce values to flatten.
* @returns A function that maps a readonly array to a deeply flattened array.
*
* @example
* import { flatMapDeep, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2], flatMapDeep(value => [[value, value * 10]]));
* // => [1, 10, 2, 20]
*/
declare function flatMapDeep<T, U>(iteratee: (item: T, index: number) => U): (array: readonly T[]) => Array<ExtractNestedArrayType<U>>;
//#endregion
export { flatMapDeep };

View file

@ -0,0 +1,38 @@
const require_flatMapDeep = require("../../array/flatMapDeep.js");
const require_lazy = require("../_internal/lazy.js");
//#region src/fp/array/flatMapDeep.ts
/**
* Creates a function that maps each element and recursively flattens the mapped values.
*
* The iteratee receives each value and index. The returned function is lazy-capable inside
* {@link pipe}; a trailing short-circuiting operator can stop before later input values are mapped.
*
* @template T - The type of elements in the input array.
* @template U - The type returned by the iteratee before recursive flattening.
* @param iteratee - Called with each value and index to produce values to flatten.
* @returns A function that maps a readonly array to a deeply flattened array.
*
* @example
* import { flatMapDeep, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2], flatMapDeep(value => [[value, value * 10]]));
* // => [1, 10, 2, 20]
*/
function flatMapDeep(iteratee) {
function flatMapDeepEager(array) {
return require_flatMapDeep.flatMapDeep(array, (item, index) => iteratee(item, index));
}
const flatMapDeepLazy = require_lazy.createLazyFunction((value, index, emit) => {
emitDeep(iteratee(value, index), emit);
});
return require_lazy.combineEagerAndLazyFunctions(flatMapDeepEager, flatMapDeepLazy);
}
function emitDeep(value, emit) {
if (Array.isArray(value)) {
for (let index = 0; index < value.length; index++) emitDeep(value[index], emit);
return;
}
emit(value);
}
//#endregion
exports.flatMapDeep = flatMapDeep;

View file

@ -0,0 +1,37 @@
import { flatMapDeep as flatMapDeep$1 } from "../../array/flatMapDeep.mjs";
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
//#region src/fp/array/flatMapDeep.ts
/**
* Creates a function that maps each element and recursively flattens the mapped values.
*
* The iteratee receives each value and index. The returned function is lazy-capable inside
* {@link pipe}; a trailing short-circuiting operator can stop before later input values are mapped.
*
* @template T - The type of elements in the input array.
* @template U - The type returned by the iteratee before recursive flattening.
* @param iteratee - Called with each value and index to produce values to flatten.
* @returns A function that maps a readonly array to a deeply flattened array.
*
* @example
* import { flatMapDeep, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2], flatMapDeep(value => [[value, value * 10]]));
* // => [1, 10, 2, 20]
*/
function flatMapDeep(iteratee) {
function flatMapDeepEager(array) {
return flatMapDeep$1(array, (item, index) => iteratee(item, index));
}
return combineEagerAndLazyFunctions(flatMapDeepEager, createLazyFunction((value, index, emit) => {
emitDeep(iteratee(value, index), emit);
}));
}
function emitDeep(value, emit) {
if (Array.isArray(value)) {
for (let index = 0; index < value.length; index++) emitDeep(value[index], emit);
return;
}
emit(value);
}
//#endregion
export { flatMapDeep };

View file

@ -0,0 +1,21 @@
//#region src/fp/array/flatten.d.ts
/**
* Creates a function that flattens an array up to the specified depth.
*
* The returned function is lazy-capable inside {@link pipe}. A trailing
* short-circuiting operator can stop before later nested values are visited.
*
* @template T - The type of elements in the array.
* @template D - The depth to which nested arrays should be flattened.
* @param depth - The flattening depth. Defaults to 1.
* @returns A function that maps the piped array to a flattened array.
*
* @example
* import { flatten, pipe } from 'es-toolkit/fp';
*
* pipe([1, [2, [3]]], flatten(2));
* // => [1, 2, 3]
*/
declare function flatten<T, D extends number = 1>(depth?: D): (array: readonly T[]) => Array<FlatArray<T[], D>>;
//#endregion
export { flatten };

View file

@ -0,0 +1,21 @@
//#region src/fp/array/flatten.d.ts
/**
* Creates a function that flattens an array up to the specified depth.
*
* The returned function is lazy-capable inside {@link pipe}. A trailing
* short-circuiting operator can stop before later nested values are visited.
*
* @template T - The type of elements in the array.
* @template D - The depth to which nested arrays should be flattened.
* @param depth - The flattening depth. Defaults to 1.
* @returns A function that maps the piped array to a flattened array.
*
* @example
* import { flatten, pipe } from 'es-toolkit/fp';
*
* pipe([1, [2, [3]]], flatten(2));
* // => [1, 2, 3]
*/
declare function flatten<T, D extends number = 1>(depth?: D): (array: readonly T[]) => Array<FlatArray<T[], D>>;
//#endregion
export { flatten };

View file

@ -0,0 +1,39 @@
const require_flatten = require("../../array/flatten.js");
const require_lazy = require("../_internal/lazy.js");
//#region src/fp/array/flatten.ts
/**
* Creates a function that flattens an array up to the specified depth.
*
* The returned function is lazy-capable inside {@link pipe}. A trailing
* short-circuiting operator can stop before later nested values are visited.
*
* @template T - The type of elements in the array.
* @template D - The depth to which nested arrays should be flattened.
* @param depth - The flattening depth. Defaults to 1.
* @returns A function that maps the piped array to a flattened array.
*
* @example
* import { flatten, pipe } from 'es-toolkit/fp';
*
* pipe([1, [2, [3]]], flatten(2));
* // => [1, 2, 3]
*/
function flatten(depth = 1) {
const flooredDepth = Math.floor(depth);
function flattenEager(array) {
return require_flatten.flatten(array, depth);
}
const flattenLazy = require_lazy.createLazyFunction((value, _index, emit) => {
emitFlattened(value, 0, flooredDepth, emit);
});
return require_lazy.combineEagerAndLazyFunctions(flattenEager, flattenLazy);
}
function emitFlattened(value, currentDepth, maxDepth, emit) {
if (Array.isArray(value) && currentDepth < maxDepth) {
for (let index = 0; index < value.length; index++) emitFlattened(value[index], currentDepth + 1, maxDepth, emit);
return;
}
emit(value);
}
//#endregion
exports.flatten = flatten;

View file

@ -0,0 +1,38 @@
import { flatten as flatten$1 } from "../../array/flatten.mjs";
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
//#region src/fp/array/flatten.ts
/**
* Creates a function that flattens an array up to the specified depth.
*
* The returned function is lazy-capable inside {@link pipe}. A trailing
* short-circuiting operator can stop before later nested values are visited.
*
* @template T - The type of elements in the array.
* @template D - The depth to which nested arrays should be flattened.
* @param depth - The flattening depth. Defaults to 1.
* @returns A function that maps the piped array to a flattened array.
*
* @example
* import { flatten, pipe } from 'es-toolkit/fp';
*
* pipe([1, [2, [3]]], flatten(2));
* // => [1, 2, 3]
*/
function flatten(depth = 1) {
const flooredDepth = Math.floor(depth);
function flattenEager(array) {
return flatten$1(array, depth);
}
return combineEagerAndLazyFunctions(flattenEager, createLazyFunction((value, _index, emit) => {
emitFlattened(value, 0, flooredDepth, emit);
}));
}
function emitFlattened(value, currentDepth, maxDepth, emit) {
if (Array.isArray(value) && currentDepth < maxDepth) {
for (let index = 0; index < value.length; index++) emitFlattened(value[index], currentDepth + 1, maxDepth, emit);
return;
}
emit(value);
}
//#endregion
export { flatten };

View file

@ -0,0 +1,21 @@
import { ExtractNestedArrayType } from "../../array/flattenDeep.mjs";
//#region src/fp/array/flattenDeep.d.ts
/**
* Creates a function that recursively flattens an array.
*
* The returned function is lazy-capable inside {@link pipe}. A trailing
* short-circuiting operator can stop before later nested values are visited.
*
* @template T - The type of elements in the array.
* @returns A function that maps the piped array to a deeply flattened array.
*
* @example
* import { flattenDeep, pipe } from 'es-toolkit/fp';
*
* pipe([1, [2, [3]]], flattenDeep());
* // => [1, 2, 3]
*/
declare function flattenDeep<T>(): (array: readonly T[]) => Array<ExtractNestedArrayType<T>>;
//#endregion
export { flattenDeep };

View file

@ -0,0 +1,21 @@
import { ExtractNestedArrayType } from "../../array/flattenDeep.js";
//#region src/fp/array/flattenDeep.d.ts
/**
* Creates a function that recursively flattens an array.
*
* The returned function is lazy-capable inside {@link pipe}. A trailing
* short-circuiting operator can stop before later nested values are visited.
*
* @template T - The type of elements in the array.
* @returns A function that maps the piped array to a deeply flattened array.
*
* @example
* import { flattenDeep, pipe } from 'es-toolkit/fp';
*
* pipe([1, [2, [3]]], flattenDeep());
* // => [1, 2, 3]
*/
declare function flattenDeep<T>(): (array: readonly T[]) => Array<ExtractNestedArrayType<T>>;
//#endregion
export { flattenDeep };

View file

@ -0,0 +1,36 @@
const require_flattenDeep = require("../../array/flattenDeep.js");
const require_lazy = require("../_internal/lazy.js");
//#region src/fp/array/flattenDeep.ts
/**
* Creates a function that recursively flattens an array.
*
* The returned function is lazy-capable inside {@link pipe}. A trailing
* short-circuiting operator can stop before later nested values are visited.
*
* @template T - The type of elements in the array.
* @returns A function that maps the piped array to a deeply flattened array.
*
* @example
* import { flattenDeep, pipe } from 'es-toolkit/fp';
*
* pipe([1, [2, [3]]], flattenDeep());
* // => [1, 2, 3]
*/
function flattenDeep() {
function flattenDeepEager(array) {
return require_flattenDeep.flattenDeep(array);
}
const flattenDeepLazy = require_lazy.createLazyFunction((value, _index, emit) => {
emitDeep(value, emit);
});
return require_lazy.combineEagerAndLazyFunctions(flattenDeepEager, flattenDeepLazy);
}
function emitDeep(value, emit) {
if (Array.isArray(value)) {
for (let index = 0; index < value.length; index++) emitDeep(value[index], emit);
return;
}
emit(value);
}
//#endregion
exports.flattenDeep = flattenDeep;

View file

@ -0,0 +1,35 @@
import { flattenDeep as flattenDeep$1 } from "../../array/flattenDeep.mjs";
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
//#region src/fp/array/flattenDeep.ts
/**
* Creates a function that recursively flattens an array.
*
* The returned function is lazy-capable inside {@link pipe}. A trailing
* short-circuiting operator can stop before later nested values are visited.
*
* @template T - The type of elements in the array.
* @returns A function that maps the piped array to a deeply flattened array.
*
* @example
* import { flattenDeep, pipe } from 'es-toolkit/fp';
*
* pipe([1, [2, [3]]], flattenDeep());
* // => [1, 2, 3]
*/
function flattenDeep() {
function flattenDeepEager(array) {
return flattenDeep$1(array);
}
return combineEagerAndLazyFunctions(flattenDeepEager, createLazyFunction((value, _index, emit) => {
emitDeep(value, emit);
}));
}
function emitDeep(value, emit) {
if (Array.isArray(value)) {
for (let index = 0; index < value.length; index++) emitDeep(value[index], emit);
return;
}
emit(value);
}
//#endregion
export { flattenDeep };

View file

@ -0,0 +1,22 @@
//#region src/fp/array/forEach.d.ts
/**
* Creates a function that runs a callback for every element and returns the original array.
*
* This mirrors Remeda's pipeline-friendly `forEach` behavior: the side effect
* runs, then the input continues through the pipeline by reference. The returned
* function is lazy-capable inside {@link pipe}; when followed by a
* short-circuiting operator, the callback only runs for consumed values.
*
* @template T - The type of elements in the array.
* @param callback - Called with each value and index.
* @returns A function that performs the side effect and returns the original array.
*
* @example
* import { forEach, map, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3], forEach(value => console.log(value)), map(value => value * 2));
* // => [2, 4, 6]
*/
declare function forEach<T>(callback: (value: T, index: number) => void): (array: readonly T[]) => readonly T[];
//#endregion
export { forEach };

View file

@ -0,0 +1,22 @@
//#region src/fp/array/forEach.d.ts
/**
* Creates a function that runs a callback for every element and returns the original array.
*
* This mirrors Remeda's pipeline-friendly `forEach` behavior: the side effect
* runs, then the input continues through the pipeline by reference. The returned
* function is lazy-capable inside {@link pipe}; when followed by a
* short-circuiting operator, the callback only runs for consumed values.
*
* @template T - The type of elements in the array.
* @param callback - Called with each value and index.
* @returns A function that performs the side effect and returns the original array.
*
* @example
* import { forEach, map, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3], forEach(value => console.log(value)), map(value => value * 2));
* // => [2, 4, 6]
*/
declare function forEach<T>(callback: (value: T, index: number) => void): (array: readonly T[]) => readonly T[];
//#endregion
export { forEach };

View file

@ -0,0 +1,33 @@
const require_lazy = require("../_internal/lazy.js");
//#region src/fp/array/forEach.ts
/**
* Creates a function that runs a callback for every element and returns the original array.
*
* This mirrors Remeda's pipeline-friendly `forEach` behavior: the side effect
* runs, then the input continues through the pipeline by reference. The returned
* function is lazy-capable inside {@link pipe}; when followed by a
* short-circuiting operator, the callback only runs for consumed values.
*
* @template T - The type of elements in the array.
* @param callback - Called with each value and index.
* @returns A function that performs the side effect and returns the original array.
*
* @example
* import { forEach, map, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3], forEach(value => console.log(value)), map(value => value * 2));
* // => [2, 4, 6]
*/
function forEach(callback) {
function forEachEager(array) {
array.forEach(callback);
return array;
}
const forEachLazy = require_lazy.createLazyFunction((value, index, emit) => {
callback(value, index);
emit(value);
});
return require_lazy.combineEagerAndLazyFunctions(forEachEager, forEachLazy);
}
//#endregion
exports.forEach = forEach;

View file

@ -0,0 +1,32 @@
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
//#region src/fp/array/forEach.ts
/**
* Creates a function that runs a callback for every element and returns the original array.
*
* This mirrors Remeda's pipeline-friendly `forEach` behavior: the side effect
* runs, then the input continues through the pipeline by reference. The returned
* function is lazy-capable inside {@link pipe}; when followed by a
* short-circuiting operator, the callback only runs for consumed values.
*
* @template T - The type of elements in the array.
* @param callback - Called with each value and index.
* @returns A function that performs the side effect and returns the original array.
*
* @example
* import { forEach, map, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3], forEach(value => console.log(value)), map(value => value * 2));
* // => [2, 4, 6]
*/
function forEach(callback) {
function forEachEager(array) {
array.forEach(callback);
return array;
}
return combineEagerAndLazyFunctions(forEachEager, createLazyFunction((value, index, emit) => {
callback(value, index);
emit(value);
}));
}
//#endregion
export { forEach };

View file

@ -0,0 +1,21 @@
//#region src/fp/array/groupBy.d.ts
/**
* Creates a function that groups values by a derived key.
*
* The key selector receives each value, index, and full input array. Values that produce
* the same key are collected in insertion order.
*
* @template T - The type of elements in the array.
* @template K - The property-key type produced by the selector.
* @param getKey - Called with each value, index, and array to produce a group key.
* @returns A function that maps a readonly array to grouped values.
*
* @example
* import { groupBy, pipe } from 'es-toolkit/fp';
*
* pipe(['ant', 'bear', 'cat'], groupBy(word => word.length));
* // => { 3: ['ant', 'cat'], 4: ['bear'] }
*/
declare function groupBy<T, K extends PropertyKey>(getKey: (item: T, index: number, array: readonly T[]) => K): (array: readonly T[]) => Record<K, T[]>;
//#endregion
export { groupBy };

View file

@ -0,0 +1,21 @@
//#region src/fp/array/groupBy.d.ts
/**
* Creates a function that groups values by a derived key.
*
* The key selector receives each value, index, and full input array. Values that produce
* the same key are collected in insertion order.
*
* @template T - The type of elements in the array.
* @template K - The property-key type produced by the selector.
* @param getKey - Called with each value, index, and array to produce a group key.
* @returns A function that maps a readonly array to grouped values.
*
* @example
* import { groupBy, pipe } from 'es-toolkit/fp';
*
* pipe(['ant', 'bear', 'cat'], groupBy(word => word.length));
* // => { 3: ['ant', 'cat'], 4: ['bear'] }
*/
declare function groupBy<T, K extends PropertyKey>(getKey: (item: T, index: number, array: readonly T[]) => K): (array: readonly T[]) => Record<K, T[]>;
//#endregion
export { groupBy };

View file

@ -0,0 +1,26 @@
const require_groupBy = require("../../array/groupBy.js");
//#region src/fp/array/groupBy.ts
/**
* Creates a function that groups values by a derived key.
*
* The key selector receives each value, index, and full input array. Values that produce
* the same key are collected in insertion order.
*
* @template T - The type of elements in the array.
* @template K - The property-key type produced by the selector.
* @param getKey - Called with each value, index, and array to produce a group key.
* @returns A function that maps a readonly array to grouped values.
*
* @example
* import { groupBy, pipe } from 'es-toolkit/fp';
*
* pipe(['ant', 'bear', 'cat'], groupBy(word => word.length));
* // => { 3: ['ant', 'cat'], 4: ['bear'] }
*/
function groupBy(getKey) {
return function(array) {
return require_groupBy.groupBy(array, getKey);
};
}
//#endregion
exports.groupBy = groupBy;

View file

@ -0,0 +1,26 @@
import { groupBy as groupBy$1 } from "../../array/groupBy.mjs";
//#region src/fp/array/groupBy.ts
/**
* Creates a function that groups values by a derived key.
*
* The key selector receives each value, index, and full input array. Values that produce
* the same key are collected in insertion order.
*
* @template T - The type of elements in the array.
* @template K - The property-key type produced by the selector.
* @param getKey - Called with each value, index, and array to produce a group key.
* @returns A function that maps a readonly array to grouped values.
*
* @example
* import { groupBy, pipe } from 'es-toolkit/fp';
*
* pipe(['ant', 'bear', 'cat'], groupBy(word => word.length));
* // => { 3: ['ant', 'cat'], 4: ['bear'] }
*/
function groupBy(getKey) {
return function(array) {
return groupBy$1(array, getKey);
};
}
//#endregion
export { groupBy };

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