es-toolkit 1.48.1 → 1.49.0
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/CHANGELOG.md +23 -0
- 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/chunk.js +4 -2
- package/dist/compat/array/chunk.mjs +4 -2
- package/dist/compat/array/differenceBy.js +5 -5
- package/dist/compat/array/differenceBy.mjs +5 -5
- package/dist/compat/array/drop.d.mts +2 -3
- package/dist/compat/array/drop.d.ts +2 -3
- package/dist/compat/array/drop.js +4 -4
- package/dist/compat/array/drop.mjs +4 -4
- package/dist/compat/array/dropRight.js +1 -1
- package/dist/compat/array/dropRight.mjs +1 -1
- package/dist/compat/array/dropRightWhile.d.mts +1 -1
- package/dist/compat/array/dropRightWhile.d.ts +1 -1
- package/dist/compat/array/dropRightWhile.js +5 -4
- package/dist/compat/array/dropRightWhile.mjs +5 -4
- package/dist/compat/array/dropWhile.d.mts +2 -2
- package/dist/compat/array/dropWhile.d.ts +2 -2
- package/dist/compat/array/dropWhile.js +4 -4
- package/dist/compat/array/dropWhile.mjs +4 -4
- 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/random.js +3 -1
- package/dist/compat/math/random.mjs +3 -1
- package/dist/compat/math/subtract.js +1 -1
- package/dist/compat/math/subtract.mjs +1 -1
- package/dist/compat/object/get.js +1 -1
- package/dist/compat/object/get.mjs +1 -1
- package/dist/compat/object/omitBy.js +1 -1
- package/dist/compat/object/omitBy.mjs +1 -1
- package/dist/compat/object/pick.js +1 -1
- package/dist/compat/object/pick.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/dist/string/trimStart.js +1 -0
- package/dist/string/trimStart.mjs +1 -0
- package/fp.d.ts +1 -0
- package/fp.js +1 -0
- package/package.json +22 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/fp/array/dropRight.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that removes a number of values from the end of an array.
|
|
4
|
+
*
|
|
5
|
+
* The returned function follows the main {@link dropRight} behavior and returns a new array.
|
|
6
|
+
* Use it with {@link pipe}.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param count - The number of values to drop from the end.
|
|
10
|
+
* @returns A function that maps a readonly array to the remaining prefix.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { dropRight, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([1, 2, 3, 4], dropRight(2));
|
|
16
|
+
* // => [1, 2]
|
|
17
|
+
*/
|
|
18
|
+
declare function dropRight<T>(count: number): (array: readonly T[]) => T[];
|
|
19
|
+
//#endregion
|
|
20
|
+
export { dropRight };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const require_dropRight = require("../../array/dropRight.js");
|
|
2
|
+
//#region src/fp/array/dropRight.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that removes a number of values from the end of an array.
|
|
5
|
+
*
|
|
6
|
+
* The returned function follows the main {@link dropRight} behavior and returns a new array.
|
|
7
|
+
* Use it with {@link pipe}.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @param count - The number of values to drop from the end.
|
|
11
|
+
* @returns A function that maps a readonly array to the remaining prefix.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { dropRight, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([1, 2, 3, 4], dropRight(2));
|
|
17
|
+
* // => [1, 2]
|
|
18
|
+
*/
|
|
19
|
+
function dropRight(count) {
|
|
20
|
+
return function(array) {
|
|
21
|
+
return require_dropRight.dropRight(array, count);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.dropRight = dropRight;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { dropRight as dropRight$1 } from "../../array/dropRight.mjs";
|
|
2
|
+
//#region src/fp/array/dropRight.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that removes a number of values from the end of an array.
|
|
5
|
+
*
|
|
6
|
+
* The returned function follows the main {@link dropRight} behavior and returns a new array.
|
|
7
|
+
* Use it with {@link pipe}.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @param count - The number of values to drop from the end.
|
|
11
|
+
* @returns A function that maps a readonly array to the remaining prefix.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { dropRight, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([1, 2, 3, 4], dropRight(2));
|
|
17
|
+
* // => [1, 2]
|
|
18
|
+
*/
|
|
19
|
+
function dropRight(count) {
|
|
20
|
+
return function(array) {
|
|
21
|
+
return dropRight$1(array, count);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { dropRight };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/fp/array/dropRightWhile.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that drops trailing values while a predicate returns true.
|
|
4
|
+
*
|
|
5
|
+
* The predicate is evaluated from right to left and receives the value, index, and full
|
|
6
|
+
* input array. Use the returned function with {@link pipe}.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param predicate - Called with each value, index, and array while dropping from the end.
|
|
10
|
+
* @returns A function that maps a readonly array to the remaining prefix.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { dropRightWhile, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([1, 2, 3, 4], dropRightWhile(value => value > 2));
|
|
16
|
+
* // => [1, 2]
|
|
17
|
+
*/
|
|
18
|
+
declare function dropRightWhile<T>(predicate: (item: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => T[];
|
|
19
|
+
//#endregion
|
|
20
|
+
export { dropRightWhile };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/fp/array/dropRightWhile.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that drops trailing values while a predicate returns true.
|
|
4
|
+
*
|
|
5
|
+
* The predicate is evaluated from right to left and receives the value, index, and full
|
|
6
|
+
* input array. Use the returned function with {@link pipe}.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param predicate - Called with each value, index, and array while dropping from the end.
|
|
10
|
+
* @returns A function that maps a readonly array to the remaining prefix.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { dropRightWhile, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([1, 2, 3, 4], dropRightWhile(value => value > 2));
|
|
16
|
+
* // => [1, 2]
|
|
17
|
+
*/
|
|
18
|
+
declare function dropRightWhile<T>(predicate: (item: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => T[];
|
|
19
|
+
//#endregion
|
|
20
|
+
export { dropRightWhile };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const require_dropRightWhile = require("../../array/dropRightWhile.js");
|
|
2
|
+
//#region src/fp/array/dropRightWhile.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that drops trailing values while a predicate returns true.
|
|
5
|
+
*
|
|
6
|
+
* The predicate is evaluated from right to left and receives the value, index, and full
|
|
7
|
+
* input array. Use the returned function with {@link pipe}.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @param predicate - Called with each value, index, and array while dropping from the end.
|
|
11
|
+
* @returns A function that maps a readonly array to the remaining prefix.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { dropRightWhile, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([1, 2, 3, 4], dropRightWhile(value => value > 2));
|
|
17
|
+
* // => [1, 2]
|
|
18
|
+
*/
|
|
19
|
+
function dropRightWhile(predicate) {
|
|
20
|
+
return function(array) {
|
|
21
|
+
return require_dropRightWhile.dropRightWhile(array, predicate);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.dropRightWhile = dropRightWhile;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { dropRightWhile as dropRightWhile$1 } from "../../array/dropRightWhile.mjs";
|
|
2
|
+
//#region src/fp/array/dropRightWhile.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that drops trailing values while a predicate returns true.
|
|
5
|
+
*
|
|
6
|
+
* The predicate is evaluated from right to left and receives the value, index, and full
|
|
7
|
+
* input array. Use the returned function with {@link pipe}.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @param predicate - Called with each value, index, and array while dropping from the end.
|
|
11
|
+
* @returns A function that maps a readonly array to the remaining prefix.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { dropRightWhile, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([1, 2, 3, 4], dropRightWhile(value => value > 2));
|
|
17
|
+
* // => [1, 2]
|
|
18
|
+
*/
|
|
19
|
+
function dropRightWhile(predicate) {
|
|
20
|
+
return function(array) {
|
|
21
|
+
return dropRightWhile$1(array, predicate);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { dropRightWhile };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/fp/array/dropWhile.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that removes leading values while a predicate returns true.
|
|
4
|
+
*
|
|
5
|
+
* Once the predicate returns false, that value and all following values are
|
|
6
|
+
* emitted. The returned function is lazy-capable inside {@link pipe}.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param predicate - Called with each leading value and index while values are being dropped.
|
|
10
|
+
* @returns A function that maps the piped array to the remaining suffix.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { dropWhile, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([1, 2, 3, 1], dropWhile(value => value < 3));
|
|
16
|
+
* // => [3, 1]
|
|
17
|
+
*/
|
|
18
|
+
declare function dropWhile<T>(predicate: (item: T, index: number) => boolean): (array: readonly T[]) => T[];
|
|
19
|
+
//#endregion
|
|
20
|
+
export { dropWhile };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/fp/array/dropWhile.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that removes leading values while a predicate returns true.
|
|
4
|
+
*
|
|
5
|
+
* Once the predicate returns false, that value and all following values are
|
|
6
|
+
* emitted. The returned function is lazy-capable inside {@link pipe}.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param predicate - Called with each leading value and index while values are being dropped.
|
|
10
|
+
* @returns A function that maps the piped array to the remaining suffix.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { dropWhile, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([1, 2, 3, 1], dropWhile(value => value < 3));
|
|
16
|
+
* // => [3, 1]
|
|
17
|
+
*/
|
|
18
|
+
declare function dropWhile<T>(predicate: (item: T, index: number) => boolean): (array: readonly T[]) => T[];
|
|
19
|
+
//#endregion
|
|
20
|
+
export { dropWhile };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const require_dropWhile = require("../../array/dropWhile.js");
|
|
2
|
+
const require_lazy = require("../_internal/lazy.js");
|
|
3
|
+
//#region src/fp/array/dropWhile.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a function that removes leading values while a predicate returns true.
|
|
6
|
+
*
|
|
7
|
+
* Once the predicate returns false, that value and all following values are
|
|
8
|
+
* emitted. The returned function is lazy-capable inside {@link pipe}.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of elements in the array.
|
|
11
|
+
* @param predicate - Called with each leading value and index while values are being dropped.
|
|
12
|
+
* @returns A function that maps the piped array to the remaining suffix.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { dropWhile, pipe } from 'es-toolkit/fp';
|
|
16
|
+
*
|
|
17
|
+
* pipe([1, 2, 3, 1], dropWhile(value => value < 3));
|
|
18
|
+
* // => [3, 1]
|
|
19
|
+
*/
|
|
20
|
+
function dropWhile(predicate) {
|
|
21
|
+
function dropWhileEager(array) {
|
|
22
|
+
return require_dropWhile.dropWhile(array, (item, index) => predicate(item, index));
|
|
23
|
+
}
|
|
24
|
+
const dropWhileLazy = (emit) => {
|
|
25
|
+
let dropping = true;
|
|
26
|
+
let index = 0;
|
|
27
|
+
return (value) => {
|
|
28
|
+
if (dropping && predicate(value, index++)) return true;
|
|
29
|
+
dropping = false;
|
|
30
|
+
return emit(value);
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
return require_lazy.combineEagerAndLazyFunctions(dropWhileEager, dropWhileLazy);
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.dropWhile = dropWhile;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { dropWhile as dropWhile$1 } from "../../array/dropWhile.mjs";
|
|
2
|
+
import { combineEagerAndLazyFunctions } from "../_internal/lazy.mjs";
|
|
3
|
+
//#region src/fp/array/dropWhile.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a function that removes leading values while a predicate returns true.
|
|
6
|
+
*
|
|
7
|
+
* Once the predicate returns false, that value and all following values are
|
|
8
|
+
* emitted. The returned function is lazy-capable inside {@link pipe}.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of elements in the array.
|
|
11
|
+
* @param predicate - Called with each leading value and index while values are being dropped.
|
|
12
|
+
* @returns A function that maps the piped array to the remaining suffix.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { dropWhile, pipe } from 'es-toolkit/fp';
|
|
16
|
+
*
|
|
17
|
+
* pipe([1, 2, 3, 1], dropWhile(value => value < 3));
|
|
18
|
+
* // => [3, 1]
|
|
19
|
+
*/
|
|
20
|
+
function dropWhile(predicate) {
|
|
21
|
+
function dropWhileEager(array) {
|
|
22
|
+
return dropWhile$1(array, (item, index) => predicate(item, index));
|
|
23
|
+
}
|
|
24
|
+
const dropWhileLazy = (emit) => {
|
|
25
|
+
let dropping = true;
|
|
26
|
+
let index = 0;
|
|
27
|
+
return (value) => {
|
|
28
|
+
if (dropping && predicate(value, index++)) return true;
|
|
29
|
+
dropping = false;
|
|
30
|
+
return emit(value);
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
return combineEagerAndLazyFunctions(dropWhileEager, dropWhileLazy);
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { dropWhile };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/fp/array/filter.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that keeps only the elements for which `predicate` returns
|
|
4
|
+
* a truthy value, equivalent to `Array.prototype.filter`. A type predicate
|
|
5
|
+
* narrows the element type of the result. Use it with {@link pipe}.
|
|
6
|
+
*
|
|
7
|
+
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
|
|
8
|
+
* with adjacent lazy functions and runs element-by-element.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of elements in the input array.
|
|
11
|
+
* @template S - The narrowed element type when `predicate` is a type guard.
|
|
12
|
+
* @param predicate - Called with `(value, index)` for each element; return
|
|
13
|
+
* `true` to keep the element.
|
|
14
|
+
* @returns A function that maps a `readonly T[]` to a filtered array.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* import { pipe, filter } from 'es-toolkit/fp';
|
|
18
|
+
*
|
|
19
|
+
* pipe([1, 2, 3, 4], filter(x => x % 2 === 0)); // => [2, 4]
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // A type guard narrows the result type to `string[]`.
|
|
23
|
+
* pipe([1, 'a', 2, 'b'], filter((x): x is string => typeof x === 'string')); // => ['a', 'b']
|
|
24
|
+
*/
|
|
25
|
+
declare function filter<T, S extends T>(predicate: (value: T, index: number) => value is S): (array: readonly T[]) => S[];
|
|
26
|
+
/**
|
|
27
|
+
* Creates a function that keeps only the elements for which `predicate` returns
|
|
28
|
+
* a truthy value, equivalent to `Array.prototype.filter`. Use it with {@link pipe}.
|
|
29
|
+
*
|
|
30
|
+
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
|
|
31
|
+
* with adjacent lazy functions and runs element-by-element.
|
|
32
|
+
*
|
|
33
|
+
* @template T - The type of elements in the input array.
|
|
34
|
+
* @param predicate - Called with `(value, index)` for each element; return
|
|
35
|
+
* `true` to keep the element.
|
|
36
|
+
* @returns A function that maps a `readonly T[]` to a filtered array.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* import { pipe, filter } from 'es-toolkit/fp';
|
|
40
|
+
*
|
|
41
|
+
* pipe([1, 2, 3, 4], filter(x => x % 2 === 0)); // => [2, 4]
|
|
42
|
+
*/
|
|
43
|
+
declare function filter<T>(predicate: (value: T, index: number) => boolean): (array: readonly T[]) => T[];
|
|
44
|
+
//#endregion
|
|
45
|
+
export { filter };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/fp/array/filter.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that keeps only the elements for which `predicate` returns
|
|
4
|
+
* a truthy value, equivalent to `Array.prototype.filter`. A type predicate
|
|
5
|
+
* narrows the element type of the result. Use it with {@link pipe}.
|
|
6
|
+
*
|
|
7
|
+
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
|
|
8
|
+
* with adjacent lazy functions and runs element-by-element.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of elements in the input array.
|
|
11
|
+
* @template S - The narrowed element type when `predicate` is a type guard.
|
|
12
|
+
* @param predicate - Called with `(value, index)` for each element; return
|
|
13
|
+
* `true` to keep the element.
|
|
14
|
+
* @returns A function that maps a `readonly T[]` to a filtered array.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* import { pipe, filter } from 'es-toolkit/fp';
|
|
18
|
+
*
|
|
19
|
+
* pipe([1, 2, 3, 4], filter(x => x % 2 === 0)); // => [2, 4]
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // A type guard narrows the result type to `string[]`.
|
|
23
|
+
* pipe([1, 'a', 2, 'b'], filter((x): x is string => typeof x === 'string')); // => ['a', 'b']
|
|
24
|
+
*/
|
|
25
|
+
declare function filter<T, S extends T>(predicate: (value: T, index: number) => value is S): (array: readonly T[]) => S[];
|
|
26
|
+
/**
|
|
27
|
+
* Creates a function that keeps only the elements for which `predicate` returns
|
|
28
|
+
* a truthy value, equivalent to `Array.prototype.filter`. Use it with {@link pipe}.
|
|
29
|
+
*
|
|
30
|
+
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
|
|
31
|
+
* with adjacent lazy functions and runs element-by-element.
|
|
32
|
+
*
|
|
33
|
+
* @template T - The type of elements in the input array.
|
|
34
|
+
* @param predicate - Called with `(value, index)` for each element; return
|
|
35
|
+
* `true` to keep the element.
|
|
36
|
+
* @returns A function that maps a `readonly T[]` to a filtered array.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* import { pipe, filter } from 'es-toolkit/fp';
|
|
40
|
+
*
|
|
41
|
+
* pipe([1, 2, 3, 4], filter(x => x % 2 === 0)); // => [2, 4]
|
|
42
|
+
*/
|
|
43
|
+
declare function filter<T>(predicate: (value: T, index: number) => boolean): (array: readonly T[]) => T[];
|
|
44
|
+
//#endregion
|
|
45
|
+
export { filter };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const require_lazy = require("../_internal/lazy.js");
|
|
2
|
+
//#region src/fp/array/filter.ts
|
|
3
|
+
function filter(predicate) {
|
|
4
|
+
function filterEager(array) {
|
|
5
|
+
return array.filter(predicate);
|
|
6
|
+
}
|
|
7
|
+
const filterLazy = require_lazy.createLazyFunction((value, index, emit) => {
|
|
8
|
+
if (predicate(value, index)) emit(value);
|
|
9
|
+
});
|
|
10
|
+
return require_lazy.combineEagerAndLazyFunctions(filterEager, filterLazy);
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.filter = filter;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
|
|
2
|
+
//#region src/fp/array/filter.ts
|
|
3
|
+
function filter(predicate) {
|
|
4
|
+
function filterEager(array) {
|
|
5
|
+
return array.filter(predicate);
|
|
6
|
+
}
|
|
7
|
+
return combineEagerAndLazyFunctions(filterEager, createLazyFunction((value, index, emit) => {
|
|
8
|
+
if (predicate(value, index)) emit(value);
|
|
9
|
+
}));
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { filter };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/fp/array/find.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the first value accepted by a type guard.
|
|
4
|
+
*
|
|
5
|
+
* The predicate receives the value, index, and full input array. The returned
|
|
6
|
+
* function returns undefined when no value matches.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @template S - The narrowed element type accepted by the type guard.
|
|
10
|
+
* @param predicate - Type guard called with each value, index, and array until it returns true.
|
|
11
|
+
* @returns A function that maps a readonly array to the first matching value, or undefined.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { find, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* const isString = (value: string | number): value is string => typeof value === 'string';
|
|
17
|
+
* pipe([1, 'a', 2], find(isString));
|
|
18
|
+
* // => 'a'
|
|
19
|
+
*/
|
|
20
|
+
declare function find<T, S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S): (array: readonly T[]) => S | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a function that returns the first value matching a predicate.
|
|
23
|
+
*
|
|
24
|
+
* The predicate receives the value, index, and full input array. The returned
|
|
25
|
+
* function returns undefined when no value matches.
|
|
26
|
+
*
|
|
27
|
+
* @template T - The type of elements in the array.
|
|
28
|
+
* @param predicate - Predicate called with each value, index, and array until it returns true.
|
|
29
|
+
* @returns A function that maps a readonly array to the first matching value, or undefined.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* import { find, pipe } from 'es-toolkit/fp';
|
|
33
|
+
*
|
|
34
|
+
* pipe([{ id: 1 }, { id: 2 }], find(item => item.id === 2));
|
|
35
|
+
* // => { id: 2 }
|
|
36
|
+
*/
|
|
37
|
+
declare function find<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => T | undefined;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { find };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/fp/array/find.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the first value accepted by a type guard.
|
|
4
|
+
*
|
|
5
|
+
* The predicate receives the value, index, and full input array. The returned
|
|
6
|
+
* function returns undefined when no value matches.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @template S - The narrowed element type accepted by the type guard.
|
|
10
|
+
* @param predicate - Type guard called with each value, index, and array until it returns true.
|
|
11
|
+
* @returns A function that maps a readonly array to the first matching value, or undefined.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { find, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* const isString = (value: string | number): value is string => typeof value === 'string';
|
|
17
|
+
* pipe([1, 'a', 2], find(isString));
|
|
18
|
+
* // => 'a'
|
|
19
|
+
*/
|
|
20
|
+
declare function find<T, S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S): (array: readonly T[]) => S | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a function that returns the first value matching a predicate.
|
|
23
|
+
*
|
|
24
|
+
* The predicate receives the value, index, and full input array. The returned
|
|
25
|
+
* function returns undefined when no value matches.
|
|
26
|
+
*
|
|
27
|
+
* @template T - The type of elements in the array.
|
|
28
|
+
* @param predicate - Predicate called with each value, index, and array until it returns true.
|
|
29
|
+
* @returns A function that maps a readonly array to the first matching value, or undefined.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* import { find, pipe } from 'es-toolkit/fp';
|
|
33
|
+
*
|
|
34
|
+
* pipe([{ id: 1 }, { id: 2 }], find(item => item.id === 2));
|
|
35
|
+
* // => { id: 2 }
|
|
36
|
+
*/
|
|
37
|
+
declare function find<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => T | undefined;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { find };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/fp/array/findIndex.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the index of the first value matching a predicate.
|
|
4
|
+
*
|
|
5
|
+
* The predicate receives the value, index, and full input array. The returned function
|
|
6
|
+
* returns -1 when no value matches, matching Array.prototype.findIndex.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param predicate - Called with each value, index, and array until it returns true.
|
|
10
|
+
* @returns A function that maps a readonly array to the first matching index, or -1.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { findIndex, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([{ id: 1 }, { id: 2 }], findIndex(item => item.id === 2));
|
|
16
|
+
* // => 1
|
|
17
|
+
*/
|
|
18
|
+
declare function findIndex<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => number;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { findIndex };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/fp/array/findIndex.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the index of the first value matching a predicate.
|
|
4
|
+
*
|
|
5
|
+
* The predicate receives the value, index, and full input array. The returned function
|
|
6
|
+
* returns -1 when no value matches, matching Array.prototype.findIndex.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param predicate - Called with each value, index, and array until it returns true.
|
|
10
|
+
* @returns A function that maps a readonly array to the first matching index, or -1.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { findIndex, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([{ id: 1 }, { id: 2 }], findIndex(item => item.id === 2));
|
|
16
|
+
* // => 1
|
|
17
|
+
*/
|
|
18
|
+
declare function findIndex<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => number;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { findIndex };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/fp/array/findIndex.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the index of the first value matching a predicate.
|
|
4
|
+
*
|
|
5
|
+
* The predicate receives the value, index, and full input array. The returned function
|
|
6
|
+
* returns -1 when no value matches, matching Array.prototype.findIndex.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param predicate - Called with each value, index, and array until it returns true.
|
|
10
|
+
* @returns A function that maps a readonly array to the first matching index, or -1.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { findIndex, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([{ id: 1 }, { id: 2 }], findIndex(item => item.id === 2));
|
|
16
|
+
* // => 1
|
|
17
|
+
*/
|
|
18
|
+
function findIndex(predicate) {
|
|
19
|
+
return function(array) {
|
|
20
|
+
return array.findIndex(predicate);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.findIndex = findIndex;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/fp/array/findIndex.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the index of the first value matching a predicate.
|
|
4
|
+
*
|
|
5
|
+
* The predicate receives the value, index, and full input array. The returned function
|
|
6
|
+
* returns -1 when no value matches, matching Array.prototype.findIndex.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param predicate - Called with each value, index, and array until it returns true.
|
|
10
|
+
* @returns A function that maps a readonly array to the first matching index, or -1.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { findIndex, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([{ id: 1 }, { id: 2 }], findIndex(item => item.id === 2));
|
|
16
|
+
* // => 1
|
|
17
|
+
*/
|
|
18
|
+
function findIndex(predicate) {
|
|
19
|
+
return function(array) {
|
|
20
|
+
return array.findIndex(predicate);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { findIndex };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/fp/array/findLast.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the last value accepted by a type guard.
|
|
4
|
+
*
|
|
5
|
+
* The predicate receives the value, index, and full input array while scanning
|
|
6
|
+
* from right to left. The returned function returns undefined when no value matches.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @template S - The narrowed element type accepted by the type guard.
|
|
10
|
+
* @param predicate - Type guard called with each value, index, and array from right to left.
|
|
11
|
+
* @returns A function that maps a readonly array to the last matching value, or undefined.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { findLast, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* const isString = (value: string | number): value is string => typeof value === 'string';
|
|
17
|
+
* pipe([1, 'a', 2, 'b'], findLast(isString));
|
|
18
|
+
* // => 'b'
|
|
19
|
+
*/
|
|
20
|
+
declare function findLast<T, S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S): (array: readonly T[]) => S | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a function that returns the last value matching a predicate.
|
|
23
|
+
*
|
|
24
|
+
* The predicate receives the value, index, and full input array while scanning
|
|
25
|
+
* from right to left. The returned function returns undefined when no value matches.
|
|
26
|
+
*
|
|
27
|
+
* @template T - The type of elements in the array.
|
|
28
|
+
* @param predicate - Predicate called with each value, index, and array from right to left.
|
|
29
|
+
* @returns A function that maps a readonly array to the last matching value, or undefined.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* import { findLast, pipe } from 'es-toolkit/fp';
|
|
33
|
+
*
|
|
34
|
+
* pipe([{ id: 1 }, { id: 2 }, { id: 1 }], findLast(item => item.id === 1));
|
|
35
|
+
* // => { id: 1 }
|
|
36
|
+
*/
|
|
37
|
+
declare function findLast<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => T | undefined;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { findLast };
|