es-toolkit 1.48.1-dev.1890 → 1.48.1-dev.1894
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array/chunkBy.d.mts +32 -0
- package/dist/array/chunkBy.d.ts +32 -0
- package/dist/array/chunkBy.js +42 -0
- package/dist/array/chunkBy.mjs +42 -0
- package/dist/array/index.d.mts +2 -1
- package/dist/array/index.d.ts +2 -1
- package/dist/array/index.js +2 -0
- package/dist/array/index.mjs +2 -1
- package/dist/array/take.d.mts +1 -7
- package/dist/array/take.d.ts +1 -7
- package/dist/array/take.js +1 -9
- package/dist/array/take.mjs +1 -9
- package/dist/array/takeRight.d.mts +2 -2
- package/dist/array/takeRight.d.ts +2 -2
- package/dist/array/takeRight.js +2 -4
- package/dist/array/takeRight.mjs +2 -4
- package/dist/array/windowed.d.mts +1 -1
- package/dist/array/windowed.d.ts +1 -1
- package/dist/browser.global.js +3 -3
- package/dist/compat/array/drop.js +1 -1
- package/dist/compat/array/drop.mjs +1 -1
- package/dist/compat/array/dropRight.js +1 -1
- package/dist/compat/array/dropRight.mjs +1 -1
- package/dist/compat/array/findLast.js +1 -1
- package/dist/compat/array/findLast.mjs +1 -1
- package/dist/compat/array/includes.js +1 -1
- package/dist/compat/array/includes.mjs +1 -1
- package/dist/compat/array/nth.js +1 -1
- package/dist/compat/array/nth.mjs +1 -1
- package/dist/compat/array/slice.js +1 -1
- package/dist/compat/array/slice.mjs +1 -1
- package/dist/compat/array/sortedIndexBy.js +1 -1
- package/dist/compat/array/sortedIndexBy.mjs +1 -1
- package/dist/compat/array/take.js +2 -2
- package/dist/compat/array/take.mjs +2 -2
- package/dist/compat/array/takeRight.js +1 -1
- package/dist/compat/array/takeRight.mjs +1 -1
- package/dist/compat/compat.js +4 -4
- package/dist/compat/compat.mjs +4 -4
- package/dist/compat/index.js +4 -4
- package/dist/compat/index.mjs +4 -4
- package/dist/compat/math/add.js +1 -1
- package/dist/compat/math/add.mjs +1 -1
- package/dist/compat/math/divide.js +1 -1
- package/dist/compat/math/divide.mjs +1 -1
- package/dist/compat/math/multiply.js +1 -1
- package/dist/compat/math/multiply.mjs +1 -1
- package/dist/compat/math/subtract.js +1 -1
- package/dist/compat/math/subtract.mjs +1 -1
- package/dist/compat/object/omitBy.js +1 -1
- package/dist/compat/object/omitBy.mjs +1 -1
- package/dist/compat/object/pickBy.js +1 -1
- package/dist/compat/object/pickBy.mjs +1 -1
- package/dist/compat/string/repeat.js +1 -1
- package/dist/compat/string/repeat.mjs +1 -1
- package/dist/fp/_internal/lazy.js +58 -0
- package/dist/fp/_internal/lazy.mjs +57 -0
- package/dist/fp/array/at.d.mts +20 -0
- package/dist/fp/array/at.d.ts +20 -0
- package/dist/fp/array/at.js +25 -0
- package/dist/fp/array/at.mjs +25 -0
- package/dist/fp/array/cartesianProduct.d.mts +61 -0
- package/dist/fp/array/cartesianProduct.d.ts +61 -0
- package/dist/fp/array/cartesianProduct.js +9 -0
- package/dist/fp/array/cartesianProduct.mjs +9 -0
- package/dist/fp/array/chunk.d.mts +19 -0
- package/dist/fp/array/chunk.d.ts +19 -0
- package/dist/fp/array/chunk.js +24 -0
- package/dist/fp/array/chunk.mjs +24 -0
- package/dist/fp/array/chunkBy.d.mts +20 -0
- package/dist/fp/array/chunkBy.d.ts +20 -0
- package/dist/fp/array/chunkBy.js +25 -0
- package/dist/fp/array/chunkBy.mjs +25 -0
- package/dist/fp/array/combinations.d.mts +21 -0
- package/dist/fp/array/combinations.d.ts +21 -0
- package/dist/fp/array/combinations.js +26 -0
- package/dist/fp/array/combinations.mjs +26 -0
- package/dist/fp/array/compact.d.mts +22 -0
- package/dist/fp/array/compact.d.ts +22 -0
- package/dist/fp/array/compact.js +31 -0
- package/dist/fp/array/compact.mjs +30 -0
- package/dist/fp/array/countBy.d.mts +21 -0
- package/dist/fp/array/countBy.d.ts +21 -0
- package/dist/fp/array/countBy.js +26 -0
- package/dist/fp/array/countBy.mjs +26 -0
- package/dist/fp/array/difference.d.mts +21 -0
- package/dist/fp/array/difference.d.ts +21 -0
- package/dist/fp/array/difference.js +32 -0
- package/dist/fp/array/difference.mjs +31 -0
- package/dist/fp/array/differenceBy.d.mts +22 -0
- package/dist/fp/array/differenceBy.d.ts +22 -0
- package/dist/fp/array/differenceBy.js +33 -0
- package/dist/fp/array/differenceBy.mjs +32 -0
- package/dist/fp/array/differenceWith.d.mts +22 -0
- package/dist/fp/array/differenceWith.d.ts +22 -0
- package/dist/fp/array/differenceWith.js +32 -0
- package/dist/fp/array/differenceWith.mjs +31 -0
- package/dist/fp/array/drop.d.mts +20 -0
- package/dist/fp/array/drop.d.ts +20 -0
- package/dist/fp/array/drop.js +31 -0
- package/dist/fp/array/drop.mjs +30 -0
- package/dist/fp/array/dropRight.d.mts +20 -0
- package/dist/fp/array/dropRight.d.ts +20 -0
- package/dist/fp/array/dropRight.js +25 -0
- package/dist/fp/array/dropRight.mjs +25 -0
- package/dist/fp/array/dropRightWhile.d.mts +20 -0
- package/dist/fp/array/dropRightWhile.d.ts +20 -0
- package/dist/fp/array/dropRightWhile.js +25 -0
- package/dist/fp/array/dropRightWhile.mjs +25 -0
- package/dist/fp/array/dropWhile.d.mts +20 -0
- package/dist/fp/array/dropWhile.d.ts +20 -0
- package/dist/fp/array/dropWhile.js +36 -0
- package/dist/fp/array/dropWhile.mjs +36 -0
- package/dist/fp/array/filter.d.mts +45 -0
- package/dist/fp/array/filter.d.ts +45 -0
- package/dist/fp/array/filter.js +13 -0
- package/dist/fp/array/filter.mjs +12 -0
- package/dist/fp/array/find.d.mts +39 -0
- package/dist/fp/array/find.d.ts +39 -0
- package/dist/fp/array/find.js +8 -0
- package/dist/fp/array/find.mjs +8 -0
- package/dist/fp/array/findIndex.d.mts +20 -0
- package/dist/fp/array/findIndex.d.ts +20 -0
- package/dist/fp/array/findIndex.js +24 -0
- package/dist/fp/array/findIndex.mjs +24 -0
- package/dist/fp/array/findLast.d.mts +39 -0
- package/dist/fp/array/findLast.d.ts +39 -0
- package/dist/fp/array/findLast.js +11 -0
- package/dist/fp/array/findLast.mjs +11 -0
- package/dist/fp/array/findLastIndex.d.mts +20 -0
- package/dist/fp/array/findLastIndex.d.ts +20 -0
- package/dist/fp/array/findLastIndex.js +25 -0
- package/dist/fp/array/findLastIndex.mjs +25 -0
- package/dist/fp/array/flatMap.d.mts +28 -0
- package/dist/fp/array/flatMap.d.ts +28 -0
- package/dist/fp/array/flatMap.js +39 -0
- package/dist/fp/array/flatMap.mjs +38 -0
- package/dist/fp/array/flatMapDeep.d.mts +23 -0
- package/dist/fp/array/flatMapDeep.d.ts +23 -0
- package/dist/fp/array/flatMapDeep.js +38 -0
- package/dist/fp/array/flatMapDeep.mjs +37 -0
- package/dist/fp/array/flatten.d.mts +21 -0
- package/dist/fp/array/flatten.d.ts +21 -0
- package/dist/fp/array/flatten.js +39 -0
- package/dist/fp/array/flatten.mjs +38 -0
- package/dist/fp/array/flattenDeep.d.mts +21 -0
- package/dist/fp/array/flattenDeep.d.ts +21 -0
- package/dist/fp/array/flattenDeep.js +36 -0
- package/dist/fp/array/flattenDeep.mjs +35 -0
- package/dist/fp/array/forEach.d.mts +22 -0
- package/dist/fp/array/forEach.d.ts +22 -0
- package/dist/fp/array/forEach.js +33 -0
- package/dist/fp/array/forEach.mjs +32 -0
- package/dist/fp/array/groupBy.d.mts +21 -0
- package/dist/fp/array/groupBy.d.ts +21 -0
- package/dist/fp/array/groupBy.js +26 -0
- package/dist/fp/array/groupBy.mjs +26 -0
- package/dist/fp/array/head.d.mts +35 -0
- package/dist/fp/array/head.d.ts +35 -0
- package/dist/fp/array/head.js +9 -0
- package/dist/fp/array/head.mjs +9 -0
- package/dist/fp/array/index.d.mts +69 -0
- package/dist/fp/array/index.d.ts +69 -0
- package/dist/fp/array/index.js +68 -0
- package/dist/fp/array/index.mjs +68 -0
- package/dist/fp/array/initial.d.mts +19 -0
- package/dist/fp/array/initial.d.ts +19 -0
- package/dist/fp/array/initial.js +24 -0
- package/dist/fp/array/initial.mjs +24 -0
- package/dist/fp/array/intersection.d.mts +21 -0
- package/dist/fp/array/intersection.d.ts +21 -0
- package/dist/fp/array/intersection.js +32 -0
- package/dist/fp/array/intersection.mjs +31 -0
- package/dist/fp/array/intersectionBy.d.mts +22 -0
- package/dist/fp/array/intersectionBy.d.ts +22 -0
- package/dist/fp/array/intersectionBy.js +33 -0
- package/dist/fp/array/intersectionBy.mjs +32 -0
- package/dist/fp/array/intersectionWith.d.mts +22 -0
- package/dist/fp/array/intersectionWith.d.ts +22 -0
- package/dist/fp/array/intersectionWith.js +32 -0
- package/dist/fp/array/intersectionWith.mjs +31 -0
- package/dist/fp/array/isSubset.d.mts +20 -0
- package/dist/fp/array/isSubset.d.ts +20 -0
- package/dist/fp/array/isSubset.js +25 -0
- package/dist/fp/array/isSubset.mjs +25 -0
- package/dist/fp/array/isSubsetWith.d.mts +21 -0
- package/dist/fp/array/isSubsetWith.d.ts +21 -0
- package/dist/fp/array/isSubsetWith.js +26 -0
- package/dist/fp/array/isSubsetWith.mjs +26 -0
- package/dist/fp/array/join.d.mts +20 -0
- package/dist/fp/array/join.d.ts +20 -0
- package/dist/fp/array/join.js +24 -0
- package/dist/fp/array/join.mjs +24 -0
- package/dist/fp/array/keyBy.d.mts +21 -0
- package/dist/fp/array/keyBy.d.ts +21 -0
- package/dist/fp/array/keyBy.js +26 -0
- package/dist/fp/array/keyBy.mjs +26 -0
- package/dist/fp/array/last.d.mts +35 -0
- package/dist/fp/array/last.d.ts +35 -0
- package/dist/fp/array/last.js +9 -0
- package/dist/fp/array/last.mjs +9 -0
- package/dist/fp/array/length.d.mts +18 -0
- package/dist/fp/array/length.d.ts +18 -0
- package/dist/fp/array/length.js +22 -0
- package/dist/fp/array/length.mjs +22 -0
- package/dist/fp/array/map.d.mts +27 -0
- package/dist/fp/array/map.d.ts +27 -0
- package/dist/fp/array/map.js +36 -0
- package/dist/fp/array/map.mjs +35 -0
- package/dist/fp/array/maxBy.d.mts +37 -0
- package/dist/fp/array/maxBy.d.ts +37 -0
- package/dist/fp/array/maxBy.js +9 -0
- package/dist/fp/array/maxBy.mjs +9 -0
- package/dist/fp/array/minBy.d.mts +37 -0
- package/dist/fp/array/minBy.d.ts +37 -0
- package/dist/fp/array/minBy.js +9 -0
- package/dist/fp/array/minBy.mjs +9 -0
- package/dist/fp/array/orderBy.d.mts +21 -0
- package/dist/fp/array/orderBy.d.ts +21 -0
- package/dist/fp/array/orderBy.js +26 -0
- package/dist/fp/array/orderBy.mjs +26 -0
- package/dist/fp/array/partition.d.mts +39 -0
- package/dist/fp/array/partition.d.ts +39 -0
- package/dist/fp/array/partition.js +9 -0
- package/dist/fp/array/partition.mjs +9 -0
- package/dist/fp/array/reverse.d.mts +19 -0
- package/dist/fp/array/reverse.d.ts +19 -0
- package/dist/fp/array/reverse.js +23 -0
- package/dist/fp/array/reverse.mjs +23 -0
- package/dist/fp/array/sample.d.mts +18 -0
- package/dist/fp/array/sample.d.ts +18 -0
- package/dist/fp/array/sample.js +23 -0
- package/dist/fp/array/sample.mjs +23 -0
- package/dist/fp/array/sampleSize.d.mts +20 -0
- package/dist/fp/array/sampleSize.d.ts +20 -0
- package/dist/fp/array/sampleSize.js +25 -0
- package/dist/fp/array/sampleSize.mjs +25 -0
- package/dist/fp/array/shuffle.d.mts +19 -0
- package/dist/fp/array/shuffle.d.ts +19 -0
- package/dist/fp/array/shuffle.js +24 -0
- package/dist/fp/array/shuffle.mjs +24 -0
- package/dist/fp/array/sortBy.d.mts +26 -0
- package/dist/fp/array/sortBy.d.ts +26 -0
- package/dist/fp/array/sortBy.js +31 -0
- package/dist/fp/array/sortBy.mjs +31 -0
- package/dist/fp/array/tail.d.mts +19 -0
- package/dist/fp/array/tail.d.ts +19 -0
- package/dist/fp/array/tail.js +24 -0
- package/dist/fp/array/tail.mjs +24 -0
- package/dist/fp/array/take.d.mts +26 -0
- package/dist/fp/array/take.d.ts +26 -0
- package/dist/fp/array/take.js +39 -0
- package/dist/fp/array/take.mjs +38 -0
- package/dist/fp/array/takeRight.d.mts +20 -0
- package/dist/fp/array/takeRight.d.ts +20 -0
- package/dist/fp/array/takeRight.js +25 -0
- package/dist/fp/array/takeRight.mjs +25 -0
- package/dist/fp/array/takeRightWhile.d.mts +20 -0
- package/dist/fp/array/takeRightWhile.d.ts +20 -0
- package/dist/fp/array/takeRightWhile.js +25 -0
- package/dist/fp/array/takeRightWhile.mjs +25 -0
- package/dist/fp/array/takeWhile.d.mts +21 -0
- package/dist/fp/array/takeWhile.d.ts +21 -0
- package/dist/fp/array/takeWhile.js +32 -0
- package/dist/fp/array/takeWhile.mjs +31 -0
- package/dist/fp/array/toFilled.d.mts +23 -0
- package/dist/fp/array/toFilled.d.ts +23 -0
- package/dist/fp/array/toFilled.js +30 -0
- package/dist/fp/array/toFilled.mjs +30 -0
- package/dist/fp/array/union.d.mts +20 -0
- package/dist/fp/array/union.d.ts +20 -0
- package/dist/fp/array/union.js +25 -0
- package/dist/fp/array/union.mjs +25 -0
- package/dist/fp/array/unionBy.d.mts +22 -0
- package/dist/fp/array/unionBy.d.ts +22 -0
- package/dist/fp/array/unionBy.js +27 -0
- package/dist/fp/array/unionBy.mjs +27 -0
- package/dist/fp/array/unionWith.d.mts +21 -0
- package/dist/fp/array/unionWith.d.ts +21 -0
- package/dist/fp/array/unionWith.js +26 -0
- package/dist/fp/array/unionWith.mjs +26 -0
- package/dist/fp/array/uniq.d.mts +21 -0
- package/dist/fp/array/uniq.d.ts +21 -0
- package/dist/fp/array/uniq.js +36 -0
- package/dist/fp/array/uniq.mjs +36 -0
- package/dist/fp/array/uniqBy.d.mts +21 -0
- package/dist/fp/array/uniqBy.d.ts +21 -0
- package/dist/fp/array/uniqBy.js +38 -0
- package/dist/fp/array/uniqBy.mjs +38 -0
- package/dist/fp/array/uniqWith.d.mts +20 -0
- package/dist/fp/array/uniqWith.d.ts +20 -0
- package/dist/fp/array/uniqWith.js +35 -0
- package/dist/fp/array/uniqWith.mjs +35 -0
- package/dist/fp/array/unzip.d.mts +20 -0
- package/dist/fp/array/unzip.d.ts +20 -0
- package/dist/fp/array/unzip.js +24 -0
- package/dist/fp/array/unzip.mjs +24 -0
- package/dist/fp/array/unzipWith.d.mts +21 -0
- package/dist/fp/array/unzipWith.d.ts +21 -0
- package/dist/fp/array/unzipWith.js +26 -0
- package/dist/fp/array/unzipWith.mjs +26 -0
- package/dist/fp/array/windowed.d.mts +25 -0
- package/dist/fp/array/windowed.d.ts +25 -0
- package/dist/fp/array/windowed.js +50 -0
- package/dist/fp/array/windowed.mjs +50 -0
- package/dist/fp/array/without.d.mts +19 -0
- package/dist/fp/array/without.d.ts +19 -0
- package/dist/fp/array/without.js +30 -0
- package/dist/fp/array/without.mjs +29 -0
- package/dist/fp/array/xor.d.mts +20 -0
- package/dist/fp/array/xor.d.ts +20 -0
- package/dist/fp/array/xor.js +25 -0
- package/dist/fp/array/xor.mjs +25 -0
- package/dist/fp/array/xorBy.d.mts +22 -0
- package/dist/fp/array/xorBy.d.ts +22 -0
- package/dist/fp/array/xorBy.js +27 -0
- package/dist/fp/array/xorBy.mjs +27 -0
- package/dist/fp/array/xorWith.d.mts +21 -0
- package/dist/fp/array/xorWith.d.ts +21 -0
- package/dist/fp/array/xorWith.js +26 -0
- package/dist/fp/array/xorWith.mjs +26 -0
- package/dist/fp/array/zip.d.mts +61 -0
- package/dist/fp/array/zip.d.ts +61 -0
- package/dist/fp/array/zip.js +9 -0
- package/dist/fp/array/zip.mjs +9 -0
- package/dist/fp/array/zipObject.d.mts +21 -0
- package/dist/fp/array/zipObject.d.ts +21 -0
- package/dist/fp/array/zipObject.js +26 -0
- package/dist/fp/array/zipObject.mjs +26 -0
- package/dist/fp/array/zipWith.d.mts +57 -0
- package/dist/fp/array/zipWith.d.ts +57 -0
- package/dist/fp/array/zipWith.js +9 -0
- package/dist/fp/array/zipWith.mjs +9 -0
- package/dist/fp/index.d.mts +75 -0
- package/dist/fp/index.d.ts +75 -0
- package/dist/fp/index.js +150 -0
- package/dist/fp/index.mjs +77 -0
- package/dist/fp/math/add.d.mts +17 -0
- package/dist/fp/math/add.d.ts +17 -0
- package/dist/fp/math/add.js +21 -0
- package/dist/fp/math/add.mjs +21 -0
- package/dist/fp/math/index.d.mts +2 -0
- package/dist/fp/math/index.d.ts +2 -0
- package/dist/fp/math/index.js +2 -0
- package/dist/fp/math/index.mjs +2 -0
- package/dist/fp/math/multiply.d.mts +17 -0
- package/dist/fp/math/multiply.d.ts +17 -0
- package/dist/fp/math/multiply.js +21 -0
- package/dist/fp/math/multiply.mjs +21 -0
- package/dist/fp/object/index.d.mts +2 -0
- package/dist/fp/object/index.d.ts +2 -0
- package/dist/fp/object/index.js +2 -0
- package/dist/fp/object/index.mjs +2 -0
- package/dist/fp/object/omit.d.mts +18 -0
- package/dist/fp/object/omit.d.ts +18 -0
- package/dist/fp/object/omit.js +23 -0
- package/dist/fp/object/omit.mjs +23 -0
- package/dist/fp/object/pick.d.mts +19 -0
- package/dist/fp/object/pick.d.ts +19 -0
- package/dist/fp/object/pick.js +24 -0
- package/dist/fp/object/pick.mjs +24 -0
- package/dist/fp/pipe.d.mts +235 -0
- package/dist/fp/pipe.d.ts +235 -0
- package/dist/fp/pipe.js +116 -0
- package/dist/fp/pipe.mjs +116 -0
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -0
- package/dist/index.mjs +3 -1
- package/dist/predicate/index.d.mts +2 -1
- package/dist/predicate/index.d.ts +2 -1
- package/dist/predicate/index.js +2 -0
- package/dist/predicate/index.mjs +2 -1
- package/dist/predicate/isIterable.d.mts +26 -0
- package/dist/predicate/isIterable.d.ts +26 -0
- package/dist/predicate/isIterable.js +28 -0
- package/dist/predicate/isIterable.mjs +28 -0
- package/fp.d.ts +1 -0
- package/fp.js +1 -0
- package/package.json +22 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const require_flatten = require("../../array/flatten.js");
|
|
2
|
+
const require_lazy = require("../_internal/lazy.js");
|
|
3
|
+
//#region src/fp/array/flatten.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a function that flattens an array up to the specified depth.
|
|
6
|
+
*
|
|
7
|
+
* The returned function is lazy-capable inside {@link pipe}. A trailing
|
|
8
|
+
* short-circuiting operator can stop before later nested values are visited.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of elements in the array.
|
|
11
|
+
* @template D - The depth to which nested arrays should be flattened.
|
|
12
|
+
* @param depth - The flattening depth. Defaults to 1.
|
|
13
|
+
* @returns A function that maps the piped array to a flattened array.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* import { flatten, pipe } from 'es-toolkit/fp';
|
|
17
|
+
*
|
|
18
|
+
* pipe([1, [2, [3]]], flatten(2));
|
|
19
|
+
* // => [1, 2, 3]
|
|
20
|
+
*/
|
|
21
|
+
function flatten(depth = 1) {
|
|
22
|
+
const flooredDepth = Math.floor(depth);
|
|
23
|
+
function flattenEager(array) {
|
|
24
|
+
return require_flatten.flatten(array, depth);
|
|
25
|
+
}
|
|
26
|
+
const flattenLazy = require_lazy.createLazyFunction((value, _index, emit) => {
|
|
27
|
+
emitFlattened(value, 0, flooredDepth, emit);
|
|
28
|
+
});
|
|
29
|
+
return require_lazy.combineEagerAndLazyFunctions(flattenEager, flattenLazy);
|
|
30
|
+
}
|
|
31
|
+
function emitFlattened(value, currentDepth, maxDepth, emit) {
|
|
32
|
+
if (Array.isArray(value) && currentDepth < maxDepth) {
|
|
33
|
+
for (let index = 0; index < value.length; index++) emitFlattened(value[index], currentDepth + 1, maxDepth, emit);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
emit(value);
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.flatten = flatten;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { flatten as flatten$1 } from "../../array/flatten.mjs";
|
|
2
|
+
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
|
|
3
|
+
//#region src/fp/array/flatten.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a function that flattens an array up to the specified depth.
|
|
6
|
+
*
|
|
7
|
+
* The returned function is lazy-capable inside {@link pipe}. A trailing
|
|
8
|
+
* short-circuiting operator can stop before later nested values are visited.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of elements in the array.
|
|
11
|
+
* @template D - The depth to which nested arrays should be flattened.
|
|
12
|
+
* @param depth - The flattening depth. Defaults to 1.
|
|
13
|
+
* @returns A function that maps the piped array to a flattened array.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* import { flatten, pipe } from 'es-toolkit/fp';
|
|
17
|
+
*
|
|
18
|
+
* pipe([1, [2, [3]]], flatten(2));
|
|
19
|
+
* // => [1, 2, 3]
|
|
20
|
+
*/
|
|
21
|
+
function flatten(depth = 1) {
|
|
22
|
+
const flooredDepth = Math.floor(depth);
|
|
23
|
+
function flattenEager(array) {
|
|
24
|
+
return flatten$1(array, depth);
|
|
25
|
+
}
|
|
26
|
+
return combineEagerAndLazyFunctions(flattenEager, createLazyFunction((value, _index, emit) => {
|
|
27
|
+
emitFlattened(value, 0, flooredDepth, emit);
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
function emitFlattened(value, currentDepth, maxDepth, emit) {
|
|
31
|
+
if (Array.isArray(value) && currentDepth < maxDepth) {
|
|
32
|
+
for (let index = 0; index < value.length; index++) emitFlattened(value[index], currentDepth + 1, maxDepth, emit);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
emit(value);
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { flatten };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ExtractNestedArrayType } from "../../array/flattenDeep.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/fp/array/flattenDeep.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a function that recursively flattens an array.
|
|
6
|
+
*
|
|
7
|
+
* The returned function is lazy-capable inside {@link pipe}. A trailing
|
|
8
|
+
* short-circuiting operator can stop before later nested values are visited.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of elements in the array.
|
|
11
|
+
* @returns A function that maps the piped array to a deeply flattened array.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { flattenDeep, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([1, [2, [3]]], flattenDeep());
|
|
17
|
+
* // => [1, 2, 3]
|
|
18
|
+
*/
|
|
19
|
+
declare function flattenDeep<T>(): (array: readonly T[]) => Array<ExtractNestedArrayType<T>>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { flattenDeep };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ExtractNestedArrayType } from "../../array/flattenDeep.js";
|
|
2
|
+
|
|
3
|
+
//#region src/fp/array/flattenDeep.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a function that recursively flattens an array.
|
|
6
|
+
*
|
|
7
|
+
* The returned function is lazy-capable inside {@link pipe}. A trailing
|
|
8
|
+
* short-circuiting operator can stop before later nested values are visited.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of elements in the array.
|
|
11
|
+
* @returns A function that maps the piped array to a deeply flattened array.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { flattenDeep, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([1, [2, [3]]], flattenDeep());
|
|
17
|
+
* // => [1, 2, 3]
|
|
18
|
+
*/
|
|
19
|
+
declare function flattenDeep<T>(): (array: readonly T[]) => Array<ExtractNestedArrayType<T>>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { flattenDeep };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const require_flattenDeep = require("../../array/flattenDeep.js");
|
|
2
|
+
const require_lazy = require("../_internal/lazy.js");
|
|
3
|
+
//#region src/fp/array/flattenDeep.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a function that recursively flattens an array.
|
|
6
|
+
*
|
|
7
|
+
* The returned function is lazy-capable inside {@link pipe}. A trailing
|
|
8
|
+
* short-circuiting operator can stop before later nested values are visited.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of elements in the array.
|
|
11
|
+
* @returns A function that maps the piped array to a deeply flattened array.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { flattenDeep, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([1, [2, [3]]], flattenDeep());
|
|
17
|
+
* // => [1, 2, 3]
|
|
18
|
+
*/
|
|
19
|
+
function flattenDeep() {
|
|
20
|
+
function flattenDeepEager(array) {
|
|
21
|
+
return require_flattenDeep.flattenDeep(array);
|
|
22
|
+
}
|
|
23
|
+
const flattenDeepLazy = require_lazy.createLazyFunction((value, _index, emit) => {
|
|
24
|
+
emitDeep(value, emit);
|
|
25
|
+
});
|
|
26
|
+
return require_lazy.combineEagerAndLazyFunctions(flattenDeepEager, flattenDeepLazy);
|
|
27
|
+
}
|
|
28
|
+
function emitDeep(value, emit) {
|
|
29
|
+
if (Array.isArray(value)) {
|
|
30
|
+
for (let index = 0; index < value.length; index++) emitDeep(value[index], emit);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
emit(value);
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.flattenDeep = flattenDeep;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { flattenDeep as flattenDeep$1 } from "../../array/flattenDeep.mjs";
|
|
2
|
+
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
|
|
3
|
+
//#region src/fp/array/flattenDeep.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a function that recursively flattens an array.
|
|
6
|
+
*
|
|
7
|
+
* The returned function is lazy-capable inside {@link pipe}. A trailing
|
|
8
|
+
* short-circuiting operator can stop before later nested values are visited.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of elements in the array.
|
|
11
|
+
* @returns A function that maps the piped array to a deeply flattened array.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { flattenDeep, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([1, [2, [3]]], flattenDeep());
|
|
17
|
+
* // => [1, 2, 3]
|
|
18
|
+
*/
|
|
19
|
+
function flattenDeep() {
|
|
20
|
+
function flattenDeepEager(array) {
|
|
21
|
+
return flattenDeep$1(array);
|
|
22
|
+
}
|
|
23
|
+
return combineEagerAndLazyFunctions(flattenDeepEager, createLazyFunction((value, _index, emit) => {
|
|
24
|
+
emitDeep(value, emit);
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
function emitDeep(value, emit) {
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
for (let index = 0; index < value.length; index++) emitDeep(value[index], emit);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
emit(value);
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { flattenDeep };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/fp/array/forEach.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that runs a callback for every element and returns the original array.
|
|
4
|
+
*
|
|
5
|
+
* This mirrors Remeda's pipeline-friendly `forEach` behavior: the side effect
|
|
6
|
+
* runs, then the input continues through the pipeline by reference. The returned
|
|
7
|
+
* function is lazy-capable inside {@link pipe}; when followed by a
|
|
8
|
+
* short-circuiting operator, the callback only runs for consumed values.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of elements in the array.
|
|
11
|
+
* @param callback - Called with each value and index.
|
|
12
|
+
* @returns A function that performs the side effect and returns the original array.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { forEach, map, pipe } from 'es-toolkit/fp';
|
|
16
|
+
*
|
|
17
|
+
* pipe([1, 2, 3], forEach(value => console.log(value)), map(value => value * 2));
|
|
18
|
+
* // => [2, 4, 6]
|
|
19
|
+
*/
|
|
20
|
+
declare function forEach<T>(callback: (value: T, index: number) => void): (array: readonly T[]) => readonly T[];
|
|
21
|
+
//#endregion
|
|
22
|
+
export { forEach };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/fp/array/forEach.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that runs a callback for every element and returns the original array.
|
|
4
|
+
*
|
|
5
|
+
* This mirrors Remeda's pipeline-friendly `forEach` behavior: the side effect
|
|
6
|
+
* runs, then the input continues through the pipeline by reference. The returned
|
|
7
|
+
* function is lazy-capable inside {@link pipe}; when followed by a
|
|
8
|
+
* short-circuiting operator, the callback only runs for consumed values.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of elements in the array.
|
|
11
|
+
* @param callback - Called with each value and index.
|
|
12
|
+
* @returns A function that performs the side effect and returns the original array.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { forEach, map, pipe } from 'es-toolkit/fp';
|
|
16
|
+
*
|
|
17
|
+
* pipe([1, 2, 3], forEach(value => console.log(value)), map(value => value * 2));
|
|
18
|
+
* // => [2, 4, 6]
|
|
19
|
+
*/
|
|
20
|
+
declare function forEach<T>(callback: (value: T, index: number) => void): (array: readonly T[]) => readonly T[];
|
|
21
|
+
//#endregion
|
|
22
|
+
export { forEach };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const require_lazy = require("../_internal/lazy.js");
|
|
2
|
+
//#region src/fp/array/forEach.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that runs a callback for every element and returns the original array.
|
|
5
|
+
*
|
|
6
|
+
* This mirrors Remeda's pipeline-friendly `forEach` behavior: the side effect
|
|
7
|
+
* runs, then the input continues through the pipeline by reference. The returned
|
|
8
|
+
* function is lazy-capable inside {@link pipe}; when followed by a
|
|
9
|
+
* short-circuiting operator, the callback only runs for consumed values.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The type of elements in the array.
|
|
12
|
+
* @param callback - Called with each value and index.
|
|
13
|
+
* @returns A function that performs the side effect and returns the original array.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* import { forEach, map, pipe } from 'es-toolkit/fp';
|
|
17
|
+
*
|
|
18
|
+
* pipe([1, 2, 3], forEach(value => console.log(value)), map(value => value * 2));
|
|
19
|
+
* // => [2, 4, 6]
|
|
20
|
+
*/
|
|
21
|
+
function forEach(callback) {
|
|
22
|
+
function forEachEager(array) {
|
|
23
|
+
array.forEach(callback);
|
|
24
|
+
return array;
|
|
25
|
+
}
|
|
26
|
+
const forEachLazy = require_lazy.createLazyFunction((value, index, emit) => {
|
|
27
|
+
callback(value, index);
|
|
28
|
+
emit(value);
|
|
29
|
+
});
|
|
30
|
+
return require_lazy.combineEagerAndLazyFunctions(forEachEager, forEachLazy);
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
exports.forEach = forEach;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
|
|
2
|
+
//#region src/fp/array/forEach.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that runs a callback for every element and returns the original array.
|
|
5
|
+
*
|
|
6
|
+
* This mirrors Remeda's pipeline-friendly `forEach` behavior: the side effect
|
|
7
|
+
* runs, then the input continues through the pipeline by reference. The returned
|
|
8
|
+
* function is lazy-capable inside {@link pipe}; when followed by a
|
|
9
|
+
* short-circuiting operator, the callback only runs for consumed values.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The type of elements in the array.
|
|
12
|
+
* @param callback - Called with each value and index.
|
|
13
|
+
* @returns A function that performs the side effect and returns the original array.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* import { forEach, map, pipe } from 'es-toolkit/fp';
|
|
17
|
+
*
|
|
18
|
+
* pipe([1, 2, 3], forEach(value => console.log(value)), map(value => value * 2));
|
|
19
|
+
* // => [2, 4, 6]
|
|
20
|
+
*/
|
|
21
|
+
function forEach(callback) {
|
|
22
|
+
function forEachEager(array) {
|
|
23
|
+
array.forEach(callback);
|
|
24
|
+
return array;
|
|
25
|
+
}
|
|
26
|
+
return combineEagerAndLazyFunctions(forEachEager, createLazyFunction((value, index, emit) => {
|
|
27
|
+
callback(value, index);
|
|
28
|
+
emit(value);
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { forEach };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/fp/array/groupBy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that groups values by a derived key.
|
|
4
|
+
*
|
|
5
|
+
* The key selector receives each value, index, and full input array. Values that produce
|
|
6
|
+
* the same key are collected in insertion order.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @template K - The property-key type produced by the selector.
|
|
10
|
+
* @param getKey - Called with each value, index, and array to produce a group key.
|
|
11
|
+
* @returns A function that maps a readonly array to grouped values.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { groupBy, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe(['ant', 'bear', 'cat'], groupBy(word => word.length));
|
|
17
|
+
* // => { 3: ['ant', 'cat'], 4: ['bear'] }
|
|
18
|
+
*/
|
|
19
|
+
declare function groupBy<T, K extends PropertyKey>(getKey: (item: T, index: number, array: readonly T[]) => K): (array: readonly T[]) => Record<K, T[]>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { groupBy };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/fp/array/groupBy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that groups values by a derived key.
|
|
4
|
+
*
|
|
5
|
+
* The key selector receives each value, index, and full input array. Values that produce
|
|
6
|
+
* the same key are collected in insertion order.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @template K - The property-key type produced by the selector.
|
|
10
|
+
* @param getKey - Called with each value, index, and array to produce a group key.
|
|
11
|
+
* @returns A function that maps a readonly array to grouped values.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { groupBy, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe(['ant', 'bear', 'cat'], groupBy(word => word.length));
|
|
17
|
+
* // => { 3: ['ant', 'cat'], 4: ['bear'] }
|
|
18
|
+
*/
|
|
19
|
+
declare function groupBy<T, K extends PropertyKey>(getKey: (item: T, index: number, array: readonly T[]) => K): (array: readonly T[]) => Record<K, T[]>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { groupBy };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const require_groupBy = require("../../array/groupBy.js");
|
|
2
|
+
//#region src/fp/array/groupBy.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that groups values by a derived key.
|
|
5
|
+
*
|
|
6
|
+
* The key selector receives each value, index, and full input array. Values that produce
|
|
7
|
+
* the same key are collected in insertion order.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @template K - The property-key type produced by the selector.
|
|
11
|
+
* @param getKey - Called with each value, index, and array to produce a group key.
|
|
12
|
+
* @returns A function that maps a readonly array to grouped values.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { groupBy, pipe } from 'es-toolkit/fp';
|
|
16
|
+
*
|
|
17
|
+
* pipe(['ant', 'bear', 'cat'], groupBy(word => word.length));
|
|
18
|
+
* // => { 3: ['ant', 'cat'], 4: ['bear'] }
|
|
19
|
+
*/
|
|
20
|
+
function groupBy(getKey) {
|
|
21
|
+
return function(array) {
|
|
22
|
+
return require_groupBy.groupBy(array, getKey);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.groupBy = groupBy;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { groupBy as groupBy$1 } from "../../array/groupBy.mjs";
|
|
2
|
+
//#region src/fp/array/groupBy.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that groups values by a derived key.
|
|
5
|
+
*
|
|
6
|
+
* The key selector receives each value, index, and full input array. Values that produce
|
|
7
|
+
* the same key are collected in insertion order.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @template K - The property-key type produced by the selector.
|
|
11
|
+
* @param getKey - Called with each value, index, and array to produce a group key.
|
|
12
|
+
* @returns A function that maps a readonly array to grouped values.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { groupBy, pipe } from 'es-toolkit/fp';
|
|
16
|
+
*
|
|
17
|
+
* pipe(['ant', 'bear', 'cat'], groupBy(word => word.length));
|
|
18
|
+
* // => { 3: ['ant', 'cat'], 4: ['bear'] }
|
|
19
|
+
*/
|
|
20
|
+
function groupBy(getKey) {
|
|
21
|
+
return function(array) {
|
|
22
|
+
return groupBy$1(array, getKey);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { groupBy };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/fp/array/head.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the first element of a non-empty array.
|
|
4
|
+
*
|
|
5
|
+
* This overload preserves the non-empty tuple guarantee: the returned function
|
|
6
|
+
* always returns T when the piped array has at least one element.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @returns A function that maps a non-empty readonly array to its first element.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import { head, pipe } from 'es-toolkit/fp';
|
|
13
|
+
*
|
|
14
|
+
* pipe([1, 2, 3] as const, head());
|
|
15
|
+
* // => 1
|
|
16
|
+
*/
|
|
17
|
+
declare function head<T>(): (array: readonly [T, ...T[]]) => T;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a function that returns the first element of an array, or undefined.
|
|
20
|
+
*
|
|
21
|
+
* Empty arrays return undefined, matching the main {@link head} behavior. Use
|
|
22
|
+
* the returned function with {@link pipe}.
|
|
23
|
+
*
|
|
24
|
+
* @template T - The type of elements in the array.
|
|
25
|
+
* @returns A function that maps a readonly array to its first element, or undefined.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* import { head, pipe } from 'es-toolkit/fp';
|
|
29
|
+
*
|
|
30
|
+
* pipe([] as number[], head());
|
|
31
|
+
* // => undefined
|
|
32
|
+
*/
|
|
33
|
+
declare function head<T>(): (array: readonly T[]) => T | undefined;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { head };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/fp/array/head.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the first element of a non-empty array.
|
|
4
|
+
*
|
|
5
|
+
* This overload preserves the non-empty tuple guarantee: the returned function
|
|
6
|
+
* always returns T when the piped array has at least one element.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @returns A function that maps a non-empty readonly array to its first element.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import { head, pipe } from 'es-toolkit/fp';
|
|
13
|
+
*
|
|
14
|
+
* pipe([1, 2, 3] as const, head());
|
|
15
|
+
* // => 1
|
|
16
|
+
*/
|
|
17
|
+
declare function head<T>(): (array: readonly [T, ...T[]]) => T;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a function that returns the first element of an array, or undefined.
|
|
20
|
+
*
|
|
21
|
+
* Empty arrays return undefined, matching the main {@link head} behavior. Use
|
|
22
|
+
* the returned function with {@link pipe}.
|
|
23
|
+
*
|
|
24
|
+
* @template T - The type of elements in the array.
|
|
25
|
+
* @returns A function that maps a readonly array to its first element, or undefined.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* import { head, pipe } from 'es-toolkit/fp';
|
|
29
|
+
*
|
|
30
|
+
* pipe([] as number[], head());
|
|
31
|
+
* // => undefined
|
|
32
|
+
*/
|
|
33
|
+
declare function head<T>(): (array: readonly T[]) => T | undefined;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { head };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { WindowedOptions } from "../../array/windowed.mjs";
|
|
2
|
+
import { at } from "./at.mjs";
|
|
3
|
+
import { cartesianProduct } from "./cartesianProduct.mjs";
|
|
4
|
+
import { chunk } from "./chunk.mjs";
|
|
5
|
+
import { chunkBy } from "./chunkBy.mjs";
|
|
6
|
+
import { combinations } from "./combinations.mjs";
|
|
7
|
+
import { compact } from "./compact.mjs";
|
|
8
|
+
import { countBy } from "./countBy.mjs";
|
|
9
|
+
import { difference } from "./difference.mjs";
|
|
10
|
+
import { differenceBy } from "./differenceBy.mjs";
|
|
11
|
+
import { differenceWith } from "./differenceWith.mjs";
|
|
12
|
+
import { drop } from "./drop.mjs";
|
|
13
|
+
import { dropRight } from "./dropRight.mjs";
|
|
14
|
+
import { dropRightWhile } from "./dropRightWhile.mjs";
|
|
15
|
+
import { dropWhile } from "./dropWhile.mjs";
|
|
16
|
+
import { filter } from "./filter.mjs";
|
|
17
|
+
import { find } from "./find.mjs";
|
|
18
|
+
import { findIndex } from "./findIndex.mjs";
|
|
19
|
+
import { findLast } from "./findLast.mjs";
|
|
20
|
+
import { findLastIndex } from "./findLastIndex.mjs";
|
|
21
|
+
import { flatMap } from "./flatMap.mjs";
|
|
22
|
+
import { flatMapDeep } from "./flatMapDeep.mjs";
|
|
23
|
+
import { flatten } from "./flatten.mjs";
|
|
24
|
+
import { flattenDeep } from "./flattenDeep.mjs";
|
|
25
|
+
import { forEach } from "./forEach.mjs";
|
|
26
|
+
import { groupBy } from "./groupBy.mjs";
|
|
27
|
+
import { head } from "./head.mjs";
|
|
28
|
+
import { initial } from "./initial.mjs";
|
|
29
|
+
import { intersection } from "./intersection.mjs";
|
|
30
|
+
import { intersectionBy } from "./intersectionBy.mjs";
|
|
31
|
+
import { intersectionWith } from "./intersectionWith.mjs";
|
|
32
|
+
import { isSubset } from "./isSubset.mjs";
|
|
33
|
+
import { isSubsetWith } from "./isSubsetWith.mjs";
|
|
34
|
+
import { join } from "./join.mjs";
|
|
35
|
+
import { keyBy } from "./keyBy.mjs";
|
|
36
|
+
import { last } from "./last.mjs";
|
|
37
|
+
import { length } from "./length.mjs";
|
|
38
|
+
import { map } from "./map.mjs";
|
|
39
|
+
import { maxBy } from "./maxBy.mjs";
|
|
40
|
+
import { minBy } from "./minBy.mjs";
|
|
41
|
+
import { orderBy } from "./orderBy.mjs";
|
|
42
|
+
import { partition } from "./partition.mjs";
|
|
43
|
+
import { reverse } from "./reverse.mjs";
|
|
44
|
+
import { sample } from "./sample.mjs";
|
|
45
|
+
import { sampleSize } from "./sampleSize.mjs";
|
|
46
|
+
import { shuffle } from "./shuffle.mjs";
|
|
47
|
+
import { sortBy } from "./sortBy.mjs";
|
|
48
|
+
import { tail } from "./tail.mjs";
|
|
49
|
+
import { take } from "./take.mjs";
|
|
50
|
+
import { takeRight } from "./takeRight.mjs";
|
|
51
|
+
import { takeRightWhile } from "./takeRightWhile.mjs";
|
|
52
|
+
import { takeWhile } from "./takeWhile.mjs";
|
|
53
|
+
import { toFilled } from "./toFilled.mjs";
|
|
54
|
+
import { union } from "./union.mjs";
|
|
55
|
+
import { unionBy } from "./unionBy.mjs";
|
|
56
|
+
import { unionWith } from "./unionWith.mjs";
|
|
57
|
+
import { uniq } from "./uniq.mjs";
|
|
58
|
+
import { uniqBy } from "./uniqBy.mjs";
|
|
59
|
+
import { uniqWith } from "./uniqWith.mjs";
|
|
60
|
+
import { unzip } from "./unzip.mjs";
|
|
61
|
+
import { unzipWith } from "./unzipWith.mjs";
|
|
62
|
+
import { windowed } from "./windowed.mjs";
|
|
63
|
+
import { without } from "./without.mjs";
|
|
64
|
+
import { xor } from "./xor.mjs";
|
|
65
|
+
import { xorBy } from "./xorBy.mjs";
|
|
66
|
+
import { xorWith } from "./xorWith.mjs";
|
|
67
|
+
import { zip } from "./zip.mjs";
|
|
68
|
+
import { zipObject } from "./zipObject.mjs";
|
|
69
|
+
import { zipWith } from "./zipWith.mjs";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { WindowedOptions } from "../../array/windowed.js";
|
|
2
|
+
import { at } from "./at.js";
|
|
3
|
+
import { cartesianProduct } from "./cartesianProduct.js";
|
|
4
|
+
import { chunk } from "./chunk.js";
|
|
5
|
+
import { chunkBy } from "./chunkBy.js";
|
|
6
|
+
import { combinations } from "./combinations.js";
|
|
7
|
+
import { compact } from "./compact.js";
|
|
8
|
+
import { countBy } from "./countBy.js";
|
|
9
|
+
import { difference } from "./difference.js";
|
|
10
|
+
import { differenceBy } from "./differenceBy.js";
|
|
11
|
+
import { differenceWith } from "./differenceWith.js";
|
|
12
|
+
import { drop } from "./drop.js";
|
|
13
|
+
import { dropRight } from "./dropRight.js";
|
|
14
|
+
import { dropRightWhile } from "./dropRightWhile.js";
|
|
15
|
+
import { dropWhile } from "./dropWhile.js";
|
|
16
|
+
import { filter } from "./filter.js";
|
|
17
|
+
import { find } from "./find.js";
|
|
18
|
+
import { findIndex } from "./findIndex.js";
|
|
19
|
+
import { findLast } from "./findLast.js";
|
|
20
|
+
import { findLastIndex } from "./findLastIndex.js";
|
|
21
|
+
import { flatMap } from "./flatMap.js";
|
|
22
|
+
import { flatMapDeep } from "./flatMapDeep.js";
|
|
23
|
+
import { flatten } from "./flatten.js";
|
|
24
|
+
import { flattenDeep } from "./flattenDeep.js";
|
|
25
|
+
import { forEach } from "./forEach.js";
|
|
26
|
+
import { groupBy } from "./groupBy.js";
|
|
27
|
+
import { head } from "./head.js";
|
|
28
|
+
import { initial } from "./initial.js";
|
|
29
|
+
import { intersection } from "./intersection.js";
|
|
30
|
+
import { intersectionBy } from "./intersectionBy.js";
|
|
31
|
+
import { intersectionWith } from "./intersectionWith.js";
|
|
32
|
+
import { isSubset } from "./isSubset.js";
|
|
33
|
+
import { isSubsetWith } from "./isSubsetWith.js";
|
|
34
|
+
import { join } from "./join.js";
|
|
35
|
+
import { keyBy } from "./keyBy.js";
|
|
36
|
+
import { last } from "./last.js";
|
|
37
|
+
import { length } from "./length.js";
|
|
38
|
+
import { map } from "./map.js";
|
|
39
|
+
import { maxBy } from "./maxBy.js";
|
|
40
|
+
import { minBy } from "./minBy.js";
|
|
41
|
+
import { orderBy } from "./orderBy.js";
|
|
42
|
+
import { partition } from "./partition.js";
|
|
43
|
+
import { reverse } from "./reverse.js";
|
|
44
|
+
import { sample } from "./sample.js";
|
|
45
|
+
import { sampleSize } from "./sampleSize.js";
|
|
46
|
+
import { shuffle } from "./shuffle.js";
|
|
47
|
+
import { sortBy } from "./sortBy.js";
|
|
48
|
+
import { tail } from "./tail.js";
|
|
49
|
+
import { take } from "./take.js";
|
|
50
|
+
import { takeRight } from "./takeRight.js";
|
|
51
|
+
import { takeRightWhile } from "./takeRightWhile.js";
|
|
52
|
+
import { takeWhile } from "./takeWhile.js";
|
|
53
|
+
import { toFilled } from "./toFilled.js";
|
|
54
|
+
import { union } from "./union.js";
|
|
55
|
+
import { unionBy } from "./unionBy.js";
|
|
56
|
+
import { unionWith } from "./unionWith.js";
|
|
57
|
+
import { uniq } from "./uniq.js";
|
|
58
|
+
import { uniqBy } from "./uniqBy.js";
|
|
59
|
+
import { uniqWith } from "./uniqWith.js";
|
|
60
|
+
import { unzip } from "./unzip.js";
|
|
61
|
+
import { unzipWith } from "./unzipWith.js";
|
|
62
|
+
import { windowed } from "./windowed.js";
|
|
63
|
+
import { without } from "./without.js";
|
|
64
|
+
import { xor } from "./xor.js";
|
|
65
|
+
import { xorBy } from "./xorBy.js";
|
|
66
|
+
import { xorWith } from "./xorWith.js";
|
|
67
|
+
import { zip } from "./zip.js";
|
|
68
|
+
import { zipObject } from "./zipObject.js";
|
|
69
|
+
import { zipWith } from "./zipWith.js";
|