@daiso-tech/core 0.1.0 → 0.1.2
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/cjs/_module.js +19 -0
- package/dist/cjs/_module.js.map +1 -0
- package/dist/cjs/collection/_module.js +21 -0
- package/dist/cjs/collection/_module.js.map +1 -0
- package/dist/cjs/collection/_shared.js +28 -0
- package/dist/cjs/collection/_shared.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/_module.js +18 -0
- package/dist/cjs/collection/async-iterable-collection/_module.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-collection.js +669 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-collection.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/_module.js +52 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/_module.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-abort-iterable.js +25 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-abort-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-chunk-iterable.js +43 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-chunk-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-chunk-whilte-iterable.js +43 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-chunk-whilte-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-collapse-iterable.js +32 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-collapse-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-count-by-iterable.js +39 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-count-by-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-cross-join-iterable.js +43 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-cross-join-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-delay-iterable.js +25 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-delay-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-entries-iterable.js +24 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-entries-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-filter-iterable.js +32 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-filter-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-flat-map-iterable.js +30 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-flat-map-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-group-by-iterable.js +30 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-group-by-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-insert-after-iterable.js +43 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-insert-after-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-insert-before-iterable.js +43 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-insert-before-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-map-iterable.js +30 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-map-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-merge-iterable.js +27 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-merge-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-pad-end-iterable.js +34 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-pad-end-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-pad-start-iterable.js +34 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-pad-start-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-partion-iterable.js +45 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-partion-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-repeat-iterable.js +32 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-repeat-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-reverse-iterable.js +28 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-reverse-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-shuffle-iterable.js +25 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-shuffle-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-skip-iterable.js +33 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-skip-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-skip-until-iterable.js +41 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-skip-until-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-slice-iterable.js +36 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-slice-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-sliding-iterable.js +45 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-sliding-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-sort-iterable.js +16 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-sort-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-split-iterable.js +49 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-split-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-take-iterable.js +33 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-take-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-take-until-iterable.js +33 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-take-until-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-tap-iterable.js +27 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-tap-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-timeout-iterable.js +21 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-timeout-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-unique-iterable.js +35 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-unique-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-update-iterable.js +37 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-update-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-when-iterable.js +32 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-when-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-zip-iterable.js +37 -0
- package/dist/cjs/collection/async-iterable-collection/async-iterable-helpers/async-zip-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/_module.js +18 -0
- package/dist/cjs/collection/iterable-collection/_module.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-collection.js +749 -0
- package/dist/cjs/collection/iterable-collection/iterable-collection.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/_module.js +49 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/_module.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/chunk-iterable.js +43 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/chunk-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/chunk-whilte-iterable.js +43 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/chunk-whilte-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/collapse-iterable.js +32 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/collapse-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/count-by-iterable.js +39 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/count-by-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/cross-join-iterable.js +43 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/cross-join-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/entries-iterable.js +34 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/entries-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/filter-iterable.js +32 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/filter-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/flat-map-iterable.js +30 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/flat-map-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/group-by-iterable.js +40 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/group-by-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/insert-after-iterable.js +37 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/insert-after-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/insert-before-iterable.js +37 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/insert-before-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/map-iterable.js +30 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/map-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/merge-iterable.js +27 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/merge-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/pad-end-iterable.js +44 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/pad-end-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/pad-start-iterable.js +44 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/pad-start-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/partion-iterable.js +40 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/partion-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/repeat-iterable.js +32 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/repeat-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/reverse-iterable.js +38 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/reverse-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/shuffle-iterable.js +35 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/shuffle-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/skip-iterable.js +32 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/skip-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/skip-until-iterable.js +36 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/skip-until-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/slice-iterable.js +46 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/slice-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/sliding-iterable.js +45 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/sliding-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/sort-iterable.js +26 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/sort-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/split-iterable.js +49 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/split-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/take-iterable.js +32 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/take-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/take-until-iterable.js +33 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/take-until-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/tap-iterable.js +27 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/tap-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/unique-iterable.js +35 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/unique-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/update-iterable.js +37 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/update-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/when-iterable.js +32 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/when-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/zip-iterable.js +33 -0
- package/dist/cjs/collection/iterable-collection/iterable-helpers/zip-iterable.js.map +1 -0
- package/dist/cjs/collection/list-collection/_module.js +18 -0
- package/dist/cjs/collection/list-collection/_module.js.map +1 -0
- package/dist/cjs/collection/list-collection/list-collection.js +1264 -0
- package/dist/cjs/collection/list-collection/list-collection.js.map +1 -0
- package/dist/cjs/contracts/_module.js +18 -0
- package/dist/cjs/contracts/_module.js.map +1 -0
- package/dist/cjs/contracts/collection/_module.js +20 -0
- package/dist/cjs/contracts/collection/_module.js.map +1 -0
- package/dist/cjs/contracts/collection/_shared.js +39 -0
- package/dist/cjs/contracts/collection/_shared.js.map +1 -0
- package/dist/cjs/contracts/collection/async-collection.contract.js +3 -0
- package/dist/cjs/contracts/collection/async-collection.contract.js.map +1 -0
- package/dist/cjs/contracts/collection/collection.contract.js +3 -0
- package/dist/cjs/contracts/collection/collection.contract.js.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/_module.js +3 -0
- package/dist/esm/_module.js.map +1 -0
- package/dist/esm/collection/_module.js +5 -0
- package/dist/esm/collection/_module.js.map +1 -0
- package/dist/esm/collection/_shared.js +23 -0
- package/dist/esm/collection/_shared.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/_module.js +2 -0
- package/dist/esm/collection/async-iterable-collection/_module.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-collection.js +665 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-collection.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/_module.js +36 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/_module.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-abort-iterable.js +21 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-abort-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-chunk-iterable.js +39 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-chunk-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-chunk-whilte-iterable.js +39 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-chunk-whilte-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-collapse-iterable.js +28 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-collapse-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-count-by-iterable.js +35 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-count-by-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-cross-join-iterable.js +39 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-cross-join-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-delay-iterable.js +21 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-delay-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-entries-iterable.js +20 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-entries-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-filter-iterable.js +28 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-filter-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-flat-map-iterable.js +26 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-flat-map-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-group-by-iterable.js +26 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-group-by-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-insert-after-iterable.js +39 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-insert-after-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-insert-before-iterable.js +39 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-insert-before-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-map-iterable.js +26 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-map-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-merge-iterable.js +23 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-merge-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-pad-end-iterable.js +30 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-pad-end-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-pad-start-iterable.js +30 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-pad-start-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-partion-iterable.js +41 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-partion-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-repeat-iterable.js +28 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-repeat-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-reverse-iterable.js +24 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-reverse-iterable.js.map +1 -0
- package/{src/collection/async-iterable-collection/async-iterable-helpers/async-shuffle-iterable.ts → dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-shuffle-iterable.js} +7 -9
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-shuffle-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-skip-iterable.js +29 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-skip-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-skip-until-iterable.js +37 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-skip-until-iterable.js.map +1 -0
- package/{src/collection/async-iterable-collection/async-iterable-helpers/async-slice-iterable.ts → dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-slice-iterable.js} +13 -14
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-slice-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-sliding-iterable.js +41 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-sliding-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-sort-iterable.js +12 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-sort-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-split-iterable.js +45 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-split-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-take-iterable.js +29 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-take-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-take-until-iterable.js +29 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-take-until-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-tap-iterable.js +23 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-tap-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-timeout-iterable.js +17 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-timeout-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-unique-iterable.js +31 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-unique-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-update-iterable.js +33 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-update-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-when-iterable.js +28 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-when-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-zip-iterable.js +33 -0
- package/dist/esm/collection/async-iterable-collection/async-iterable-helpers/async-zip-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/_module.js +2 -0
- package/dist/esm/collection/iterable-collection/_module.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-collection.js +745 -0
- package/dist/esm/collection/iterable-collection/iterable-collection.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/_module.js +33 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/_module.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/chunk-iterable.js +39 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/chunk-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/chunk-whilte-iterable.js +39 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/chunk-whilte-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/collapse-iterable.js +28 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/collapse-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/count-by-iterable.js +35 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/count-by-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/cross-join-iterable.js +39 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/cross-join-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/entries-iterable.js +30 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/entries-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/filter-iterable.js +28 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/filter-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/flat-map-iterable.js +26 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/flat-map-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/group-by-iterable.js +36 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/group-by-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/insert-after-iterable.js +33 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/insert-after-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/insert-before-iterable.js +33 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/insert-before-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/map-iterable.js +26 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/map-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/merge-iterable.js +23 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/merge-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/pad-end-iterable.js +40 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/pad-end-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/pad-start-iterable.js +40 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/pad-start-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/partion-iterable.js +36 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/partion-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/repeat-iterable.js +28 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/repeat-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/reverse-iterable.js +34 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/reverse-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/shuffle-iterable.js +31 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/shuffle-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/skip-iterable.js +28 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/skip-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/skip-until-iterable.js +32 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/skip-until-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/slice-iterable.js +42 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/slice-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/sliding-iterable.js +41 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/sliding-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/sort-iterable.js +22 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/sort-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/split-iterable.js +45 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/split-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/take-iterable.js +28 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/take-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/take-until-iterable.js +29 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/take-until-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/tap-iterable.js +23 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/tap-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/unique-iterable.js +31 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/unique-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/update-iterable.js +33 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/update-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/when-iterable.js +28 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/when-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/zip-iterable.js +29 -0
- package/dist/esm/collection/iterable-collection/iterable-helpers/zip-iterable.js.map +1 -0
- package/dist/esm/collection/list-collection/_module.js +2 -0
- package/dist/esm/collection/list-collection/_module.js.map +1 -0
- package/dist/esm/collection/list-collection/list-collection.js +1260 -0
- package/dist/esm/collection/list-collection/list-collection.js.map +1 -0
- package/dist/esm/contracts/_module.js +2 -0
- package/dist/esm/contracts/_module.js.map +1 -0
- package/dist/esm/contracts/collection/_module.js +4 -0
- package/dist/esm/contracts/collection/_module.js.map +1 -0
- package/dist/esm/contracts/collection/_shared.js +31 -0
- package/dist/esm/contracts/collection/_shared.js.map +1 -0
- package/dist/esm/contracts/collection/async-collection.contract.js +1 -0
- package/dist/esm/contracts/collection/async-collection.contract.js.map +1 -0
- package/dist/esm/contracts/collection/collection.contract.js +1 -0
- package/dist/esm/contracts/collection/collection.contract.js.map +1 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/types/_module.d.ts +2 -0
- package/dist/types/collection/_module.d.ts +4 -0
- package/dist/types/collection/_shared.d.ts +16 -0
- package/dist/types/collection/async-iterable-collection/_module.d.ts +1 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-collection.d.ts +92 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/_module.d.ts +35 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-abort-iterable.d.ts +10 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-chunk-iterable.d.ts +11 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-chunk-whilte-iterable.d.ts +12 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-collapse-iterable.d.ts +9 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-count-by-iterable.d.ts +11 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-cross-join-iterable.d.ts +11 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-delay-iterable.d.ts +10 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-entries-iterable.d.ts +11 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-filter-iterable.d.ts +11 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-flat-map-iterable.d.ts +11 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-group-by-iterable.d.ts +12 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-insert-after-iterable.d.ts +12 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-insert-before-iterable.d.ts +12 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-map-iterable.d.ts +11 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-merge-iterable.d.ts +10 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-pad-end-iterable.d.ts +12 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-pad-start-iterable.d.ts +12 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-partion-iterable.d.ts +12 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-repeat-iterable.d.ts +11 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-reverse-iterable.d.ts +12 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-shuffle-iterable.d.ts +9 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-skip-iterable.d.ts +11 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-skip-until-iterable.d.ts +11 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-slice-iterable.d.ts +12 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-sliding-iterable.d.ts +12 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-sort-iterable.d.ts +10 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-split-iterable.d.ts +12 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-take-iterable.d.ts +11 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-take-until-iterable.d.ts +11 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-tap-iterable.d.ts +10 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-timeout-iterable.d.ts +10 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-unique-iterable.d.ts +11 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-update-iterable.d.ts +12 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-when-iterable.d.ts +11 -0
- package/dist/types/collection/async-iterable-collection/async-iterable-helpers/async-zip-iterable.d.ts +10 -0
- package/dist/types/collection/iterable-collection/_module.d.ts +1 -0
- package/dist/types/collection/iterable-collection/iterable-collection.d.ts +89 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/_module.d.ts +32 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/chunk-iterable.d.ts +8 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/chunk-whilte-iterable.d.ts +9 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/collapse-iterable.d.ts +6 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/count-by-iterable.d.ts +8 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/cross-join-iterable.d.ts +8 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/entries-iterable.d.ts +7 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/filter-iterable.d.ts +8 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/flat-map-iterable.d.ts +8 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/group-by-iterable.d.ts +9 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/insert-after-iterable.d.ts +9 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/insert-before-iterable.d.ts +9 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/map-iterable.d.ts +8 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/merge-iterable.d.ts +6 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/pad-end-iterable.d.ts +9 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/pad-start-iterable.d.ts +9 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/partion-iterable.d.ts +9 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/repeat-iterable.d.ts +8 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/reverse-iterable.d.ts +9 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/shuffle-iterable.d.ts +5 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/skip-iterable.d.ts +8 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/skip-until-iterable.d.ts +8 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/slice-iterable.d.ts +9 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/sliding-iterable.d.ts +9 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/sort-iterable.d.ts +7 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/split-iterable.d.ts +9 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/take-iterable.d.ts +8 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/take-until-iterable.d.ts +8 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/tap-iterable.d.ts +7 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/unique-iterable.d.ts +8 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/update-iterable.d.ts +9 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/when-iterable.d.ts +8 -0
- package/dist/types/collection/iterable-collection/iterable-helpers/zip-iterable.d.ts +7 -0
- package/dist/types/collection/list-collection/_module.d.ts +1 -0
- package/dist/types/collection/list-collection/list-collection.d.ts +86 -0
- package/dist/types/contracts/_module.d.ts +1 -0
- package/dist/types/contracts/collection/_module.d.ts +3 -0
- package/{src/contracts/collection/_shared.ts → dist/types/contracts/collection/_shared.d.ts} +31 -118
- package/{src/contracts/collection/async-collection.contract.ts → dist/types/contracts/collection/async-collection.contract.d.ts} +84 -356
- package/{src/contracts/collection/collection.contract.ts → dist/types/contracts/collection/collection.contract.d.ts} +54 -311
- package/dist/types/types.d.ts +1 -0
- package/package.json +5 -2
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -50
- package/.gitattributes +0 -6
- package/.github/workflows/main.yaml +0 -54
- package/.github/workflows/release.yaml +0 -31
- package/.prettierignore +0 -4
- package/.prettierrc.json +0 -4
- package/.vscode/settings.json +0 -46
- package/CHANGELOG.md +0 -7
- package/docs-api/.nojekyll +0 -1
- package/docs-api/assets/highlight.css +0 -92
- package/docs-api/assets/icons.js +0 -18
- package/docs-api/assets/icons.svg +0 -1
- package/docs-api/assets/main.js +0 -60
- package/docs-api/assets/navigation.js +0 -1
- package/docs-api/assets/search.js +0 -1
- package/docs-api/assets/style.css +0 -1448
- package/docs-api/classes/AsyncIterableCollection.html +0 -437
- package/docs-api/classes/CollectionError.html +0 -12
- package/docs-api/classes/IndexOverflowError.html +0 -12
- package/docs-api/classes/ItemNotFoundError.html +0 -12
- package/docs-api/classes/IterableCollection.html +0 -434
- package/docs-api/classes/ListCollection.html +0 -434
- package/docs-api/classes/MultipleItemsFoundError.html +0 -12
- package/docs-api/classes/UnexpectedCollectionError.html +0 -12
- package/docs-api/functions/isAsyncIterable.html +0 -1
- package/docs-api/functions/isIterable.html +0 -1
- package/docs-api/functions/range.html +0 -4
- package/docs-api/hierarchy.html +0 -1
- package/docs-api/index.html +0 -1
- package/docs-api/modules.html +0 -60
- package/docs-api/types/AsyncCollapse.html +0 -1
- package/docs-api/types/AsyncFilter.html +0 -1
- package/docs-api/types/AsyncFilter_.html +0 -1
- package/docs-api/types/AsyncFindOrSettings.html +0 -1
- package/docs-api/types/AsyncFindSettings.html +0 -1
- package/docs-api/types/AsyncForEach.html +0 -1
- package/docs-api/types/AsyncForEach_.html +0 -1
- package/docs-api/types/AsyncGroupBySettings.html +0 -1
- package/docs-api/types/AsyncIterableValue.html +0 -1
- package/docs-api/types/AsyncLazyable.html +0 -1
- package/docs-api/types/AsyncLazyable_.html +0 -1
- package/docs-api/types/AsyncMap.html +0 -1
- package/docs-api/types/AsyncMap_.html +0 -1
- package/docs-api/types/AsyncModifier.html +0 -1
- package/docs-api/types/AsyncModifier_.html +0 -1
- package/docs-api/types/AsyncReduce.html +0 -1
- package/docs-api/types/AsyncReduceSettings.html +0 -1
- package/docs-api/types/AsyncReduce_.html +0 -1
- package/docs-api/types/AsyncTap.html +0 -1
- package/docs-api/types/AsyncTap_.html +0 -1
- package/docs-api/types/AsyncTransform.html +0 -1
- package/docs-api/types/AsyncTransform_.html +0 -1
- package/docs-api/types/Collapse.html +0 -1
- package/docs-api/types/Comparator.html +0 -1
- package/docs-api/types/EnsureType.html +0 -1
- package/docs-api/types/Filter.html +0 -1
- package/docs-api/types/FilterGuard.html +0 -1
- package/docs-api/types/Filter_.html +0 -1
- package/docs-api/types/FindOrSettings.html +0 -1
- package/docs-api/types/FindSettings.html +0 -1
- package/docs-api/types/ForEach.html +0 -1
- package/docs-api/types/GroupBySettings.html +0 -1
- package/docs-api/types/IAsyncCollection.html +0 -357
- package/docs-api/types/ICollection.html +0 -357
- package/docs-api/types/JoinSettings.html +0 -1
- package/docs-api/types/Lazyable.html +0 -1
- package/docs-api/types/Map.html +0 -1
- package/docs-api/types/Modifier.html +0 -1
- package/docs-api/types/PageSettings.html +0 -1
- package/docs-api/types/RecordItem.html +0 -1
- package/docs-api/types/Reduce.html +0 -1
- package/docs-api/types/ReduceSettings.html +0 -1
- package/docs-api/types/ReverseSettings.html +0 -1
- package/docs-api/types/SliceSettings.html +0 -1
- package/docs-api/types/SlidingSettings.html +0 -1
- package/docs-api/types/Tap.html +0 -1
- package/docs-api/types/Transform.html +0 -1
- package/docs-api/types/UpdatedItem.html +0 -1
- package/src/_module.ts +0 -2
- package/src/collection/_module.ts +0 -4
- package/src/collection/_shared.ts +0 -45
- package/src/collection/async-iterable-collection/_module.ts +0 -1
- package/src/collection/async-iterable-collection/async-iterable-collection.test.ts +0 -3195
- package/src/collection/async-iterable-collection/async-iterable-collection.ts +0 -1276
- package/src/collection/async-iterable-collection/async-iterable-helpers/_module.ts +0 -35
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-abort-iterable.ts +0 -25
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-chunk-iterable.ts +0 -57
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-chunk-whilte-iterable.ts +0 -54
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-collapse-iterable.ts +0 -40
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-count-by-iterable.ts +0 -58
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-cross-join-iterable.ts +0 -69
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-delay-iterable.ts +0 -19
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-entries-iterable.ts +0 -28
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-filter-iterable.ts +0 -42
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-flat-map-iterable.ts +0 -44
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-group-by-iterable.ts +0 -48
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-insert-after-iterable.ts +0 -57
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-insert-before-iterable.ts +0 -57
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-map-iterable.ts +0 -40
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-merge-iterable.ts +0 -35
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-pad-end-iterable.ts +0 -41
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-pad-start-iterable.ts +0 -41
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-partion-iterable.ts +0 -63
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-repeat-iterable.ts +0 -40
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-reverse-iterable.ts +0 -35
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-skip-iterable.ts +0 -41
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-skip-until-iterable.ts +0 -55
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-sliding-iterable.ts +0 -54
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-sort-iterable.ts +0 -18
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-split-iterable.ts +0 -64
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-take-iterable.ts +0 -41
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-take-until-iterable.ts +0 -41
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-tap-iterable.ts +0 -34
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-timeout-iterable.ts +0 -20
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-unique-iterable.ts +0 -49
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-update-iterable.ts +0 -64
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-when-iterable.ts +0 -43
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-zip-iterable.ts +0 -45
- package/src/collection/iterable-collection/_module.ts +0 -1
- package/src/collection/iterable-collection/iterable-collection.test.ts +0 -2379
- package/src/collection/iterable-collection/iterable-collection.ts +0 -1317
- package/src/collection/iterable-collection/iterable-helpers/_module.ts +0 -32
- package/src/collection/iterable-collection/iterable-helpers/chunk-iterable.ts +0 -49
- package/src/collection/iterable-collection/iterable-helpers/chunk-whilte-iterable.ts +0 -51
- package/src/collection/iterable-collection/iterable-helpers/collapse-iterable.ts +0 -35
- package/src/collection/iterable-collection/iterable-helpers/count-by-iterable.ts +0 -49
- package/src/collection/iterable-collection/iterable-helpers/cross-join-iterable.ts +0 -57
- package/src/collection/iterable-collection/iterable-helpers/entries-iterable.ts +0 -42
- package/src/collection/iterable-collection/iterable-helpers/filter-iterable.ts +0 -39
- package/src/collection/iterable-collection/iterable-helpers/flat-map-iterable.ts +0 -35
- package/src/collection/iterable-collection/iterable-helpers/group-by-iterable.ts +0 -52
- package/src/collection/iterable-collection/iterable-helpers/insert-after-iterable.ts +0 -43
- package/src/collection/iterable-collection/iterable-helpers/insert-before-iterable.ts +0 -43
- package/src/collection/iterable-collection/iterable-helpers/map-iterable.ts +0 -35
- package/src/collection/iterable-collection/iterable-helpers/merge-iterable.ts +0 -31
- package/src/collection/iterable-collection/iterable-helpers/pad-end-iterable.ts +0 -52
- package/src/collection/iterable-collection/iterable-helpers/pad-start-iterable.ts +0 -52
- package/src/collection/iterable-collection/iterable-helpers/partion-iterable.ts +0 -46
- package/src/collection/iterable-collection/iterable-helpers/repeat-iterable.ts +0 -36
- package/src/collection/iterable-collection/iterable-helpers/reverse-iterable.ts +0 -46
- package/src/collection/iterable-collection/iterable-helpers/shuffle-iterable.ts +0 -36
- package/src/collection/iterable-collection/iterable-helpers/skip-iterable.ts +0 -37
- package/src/collection/iterable-collection/iterable-helpers/skip-until-iterable.ts +0 -41
- package/src/collection/iterable-collection/iterable-helpers/slice-iterable.ts +0 -47
- package/src/collection/iterable-collection/iterable-helpers/sliding-iterable.ts +0 -49
- package/src/collection/iterable-collection/iterable-helpers/sort-iterable.ts +0 -29
- package/src/collection/iterable-collection/iterable-helpers/split-iterable.ts +0 -58
- package/src/collection/iterable-collection/iterable-helpers/take-iterable.ts +0 -37
- package/src/collection/iterable-collection/iterable-helpers/take-until-iterable.ts +0 -38
- package/src/collection/iterable-collection/iterable-helpers/tap-iterable.ts +0 -31
- package/src/collection/iterable-collection/iterable-helpers/unique-iterable.ts +0 -43
- package/src/collection/iterable-collection/iterable-helpers/update-iterable.ts +0 -50
- package/src/collection/iterable-collection/iterable-helpers/when-iterable.ts +0 -37
- package/src/collection/iterable-collection/iterable-helpers/zip-iterable.ts +0 -41
- package/src/collection/list-collection/_module.ts +0 -1
- package/src/collection/list-collection/list-collection.test.ts +0 -2280
- package/src/collection/list-collection/list-collection.ts +0 -1883
- package/src/contracts/_module.ts +0 -1
- package/src/contracts/collection/_module.ts +0 -3
- package/src/types.ts +0 -2
- package/tsconfig.base.json +0 -31
- package/tsconfig.cjs.json +0 -12
- package/tsconfig.esm.json +0 -12
- package/tsconfig.json +0 -10
- package/tsconfig.types.json +0 -12
- package/vite.config.ts +0 -6
|
@@ -1,3195 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
CollectionError,
|
|
5
|
-
ItemNotFoundError,
|
|
6
|
-
MultipleItemsFoundError,
|
|
7
|
-
RecordItem,
|
|
8
|
-
} from "@/contracts/collection/_module";
|
|
9
|
-
import { AsyncIterableCollection } from "@/collection/async-iterable-collection/_module";
|
|
10
|
-
|
|
11
|
-
describe("class: AsyncIterableCollection", () => {
|
|
12
|
-
describe("method: filter", () => {
|
|
13
|
-
test(`Should filter out all "a" of ["a", "bc", "c", "a", "d", "a"]`, async () => {
|
|
14
|
-
const arr = ["a", "bc", "c", "a", "d", "a"],
|
|
15
|
-
collection = new AsyncIterableCollection(arr),
|
|
16
|
-
filterFunction = (item: string): boolean => item === "a",
|
|
17
|
-
newCollection = collection.filter(filterFunction);
|
|
18
|
-
expect(await newCollection.toArray()).toEqual(
|
|
19
|
-
arr.filter(filterFunction),
|
|
20
|
-
);
|
|
21
|
-
});
|
|
22
|
-
test("Should input correct indexes to filter function", async () => {
|
|
23
|
-
const collection = new AsyncIterableCollection([
|
|
24
|
-
"a",
|
|
25
|
-
"bc",
|
|
26
|
-
"c",
|
|
27
|
-
"a",
|
|
28
|
-
"d",
|
|
29
|
-
"a",
|
|
30
|
-
]),
|
|
31
|
-
indexes: number[] = [],
|
|
32
|
-
filterFunction = (item: string, index: number): boolean => {
|
|
33
|
-
indexes.push(index);
|
|
34
|
-
return item === "a";
|
|
35
|
-
};
|
|
36
|
-
await collection.filter(filterFunction).toArray();
|
|
37
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4, 5]);
|
|
38
|
-
});
|
|
39
|
-
test("Should work with async filter function", async () => {
|
|
40
|
-
const arr = ["a", "bc", "c", "a", "d", "a"],
|
|
41
|
-
collection = new AsyncIterableCollection(arr),
|
|
42
|
-
filterFunction = (item: string): boolean => item === "a",
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
44
|
-
newCollection = collection.filter(async (item) =>
|
|
45
|
-
filterFunction(item),
|
|
46
|
-
);
|
|
47
|
-
expect(await newCollection.toArray()).toEqual(
|
|
48
|
-
arr.filter(filterFunction),
|
|
49
|
-
);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
describe("method: map", () => {
|
|
53
|
-
test("Should apply power by 2 for all items", async () => {
|
|
54
|
-
const arr = [2, 3, 4, 5],
|
|
55
|
-
collection = new AsyncIterableCollection(arr),
|
|
56
|
-
mapFunction = (item: number): number => item ** 2,
|
|
57
|
-
newCollection = collection.map(mapFunction);
|
|
58
|
-
expect(await newCollection.toArray()).toEqual(arr.map(mapFunction));
|
|
59
|
-
});
|
|
60
|
-
test("Should input correct indexes to map function", async () => {
|
|
61
|
-
const collection = new AsyncIterableCollection([2, 3, 4, 5]),
|
|
62
|
-
indexes: number[] = [],
|
|
63
|
-
mapFunction = (item: number, index: number): number => {
|
|
64
|
-
indexes.push(index);
|
|
65
|
-
return item ** 2;
|
|
66
|
-
};
|
|
67
|
-
await collection.map(mapFunction).toArray();
|
|
68
|
-
expect(indexes).toEqual([0, 1, 2, 3]);
|
|
69
|
-
});
|
|
70
|
-
test("Should work with async map function", async () => {
|
|
71
|
-
const arr = [2, 3, 4, 5],
|
|
72
|
-
collection = new AsyncIterableCollection(arr),
|
|
73
|
-
mapFunction = (item: number): number => item ** 2,
|
|
74
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
75
|
-
newCollection = collection.map(async (item) =>
|
|
76
|
-
mapFunction(item),
|
|
77
|
-
);
|
|
78
|
-
expect(await newCollection.toArray()).toEqual(arr.map(mapFunction));
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
describe("method: reduce", () => {
|
|
82
|
-
test("Should join all string items without initial values", async () => {
|
|
83
|
-
const arr = ["a", "b", "c", "d"],
|
|
84
|
-
collection = new AsyncIterableCollection(arr),
|
|
85
|
-
seperator = "_#_",
|
|
86
|
-
result = await collection.reduce({
|
|
87
|
-
reduceFn(firstItem, item) {
|
|
88
|
-
return firstItem + seperator + item;
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
expect(result).toBe(arr.join(seperator));
|
|
92
|
-
});
|
|
93
|
-
test(`Should join all string items initial value "_#_"`, async () => {
|
|
94
|
-
const arr = ["a", "b", "c", "d"],
|
|
95
|
-
collection = new AsyncIterableCollection(arr),
|
|
96
|
-
initialValue = "!",
|
|
97
|
-
result = await collection.reduce({
|
|
98
|
-
reduceFn(initialValue, item) {
|
|
99
|
-
return initialValue + item;
|
|
100
|
-
},
|
|
101
|
-
initialValue,
|
|
102
|
-
});
|
|
103
|
-
expect(result).toBe(initialValue + arr.join(""));
|
|
104
|
-
});
|
|
105
|
-
test("Should input correct indexes to reduce function", async () => {
|
|
106
|
-
const arr = ["a", "b", "c", "d"],
|
|
107
|
-
collection = new AsyncIterableCollection(arr),
|
|
108
|
-
initialValue = "!",
|
|
109
|
-
indexes: number[] = [];
|
|
110
|
-
await collection.reduce({
|
|
111
|
-
reduceFn(initialValue, item, index) {
|
|
112
|
-
indexes.push(index);
|
|
113
|
-
return initialValue + item;
|
|
114
|
-
},
|
|
115
|
-
initialValue,
|
|
116
|
-
});
|
|
117
|
-
expect(indexes).toEqual([0, 1, 2, 3]);
|
|
118
|
-
});
|
|
119
|
-
test("Should throw TypeError when given an empty array without initial value", async () => {
|
|
120
|
-
const collection = new AsyncIterableCollection<string>([]);
|
|
121
|
-
await expect(async () => {
|
|
122
|
-
await collection.reduce({
|
|
123
|
-
reduceFn: (a, b) => a + b,
|
|
124
|
-
});
|
|
125
|
-
}).rejects.toThrowError(TypeError);
|
|
126
|
-
});
|
|
127
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
128
|
-
const arr = ["a", "b", "c", "d"],
|
|
129
|
-
collection = new AsyncIterableCollection(arr),
|
|
130
|
-
seperator = "_#_";
|
|
131
|
-
expect(
|
|
132
|
-
await collection.reduce({
|
|
133
|
-
reduceFn(firstItem, item) {
|
|
134
|
-
return firstItem + seperator + item;
|
|
135
|
-
},
|
|
136
|
-
}),
|
|
137
|
-
).toBe(arr.join(seperator));
|
|
138
|
-
expect(
|
|
139
|
-
await collection.reduce({
|
|
140
|
-
reduceFn(firstItem, item) {
|
|
141
|
-
return firstItem + seperator + item;
|
|
142
|
-
},
|
|
143
|
-
}),
|
|
144
|
-
).toBe(arr.join(seperator));
|
|
145
|
-
});
|
|
146
|
-
test("Should work with async reduce function", async () => {
|
|
147
|
-
const arr = ["a", "b", "c", "d"],
|
|
148
|
-
collection = new AsyncIterableCollection(arr),
|
|
149
|
-
seperator = "_#_",
|
|
150
|
-
result = await collection.reduce({
|
|
151
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
152
|
-
reduceFn: async (firstItem, item) =>
|
|
153
|
-
firstItem + seperator + item,
|
|
154
|
-
});
|
|
155
|
-
expect(result).toBe(arr.join(seperator));
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
describe("method: join", () => {
|
|
159
|
-
test(`Should join Iterable of ["a", "b", "c"] to "a,b,c"`, async () => {
|
|
160
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
161
|
-
expect(await collection.join()).toBe("a,b,c");
|
|
162
|
-
});
|
|
163
|
-
test(`Should join Iterable of ["a", "b", "c"] to "a,b,c" with seperator "_#_"`, async () => {
|
|
164
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
165
|
-
expect(
|
|
166
|
-
await collection.join({
|
|
167
|
-
seperator: "_#_",
|
|
168
|
-
}),
|
|
169
|
-
).toBe("a_#_b_#_c");
|
|
170
|
-
});
|
|
171
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
172
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
173
|
-
expect(await collection.join()).toBe("a,b,c");
|
|
174
|
-
expect(await collection.join()).toBe("a,b,c");
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
describe("method: flatMap", () => {
|
|
178
|
-
test("Should apply flatmap when given an Iterable", async () => {
|
|
179
|
-
const collection = new AsyncIterableCollection([
|
|
180
|
-
"a",
|
|
181
|
-
"ab",
|
|
182
|
-
"b",
|
|
183
|
-
"ba",
|
|
184
|
-
]),
|
|
185
|
-
newCollection = collection.flatMap((item, index) => [
|
|
186
|
-
index,
|
|
187
|
-
item,
|
|
188
|
-
item.length,
|
|
189
|
-
]);
|
|
190
|
-
expect(await newCollection.toArray()).toEqual([
|
|
191
|
-
0,
|
|
192
|
-
"a",
|
|
193
|
-
1,
|
|
194
|
-
1,
|
|
195
|
-
"ab",
|
|
196
|
-
2,
|
|
197
|
-
2,
|
|
198
|
-
"b",
|
|
199
|
-
1,
|
|
200
|
-
3,
|
|
201
|
-
"ba",
|
|
202
|
-
2,
|
|
203
|
-
]);
|
|
204
|
-
});
|
|
205
|
-
test("Should apply flatmap when given an AsyncIterable", async () => {
|
|
206
|
-
const asyncIterable: AsyncIterable<string> = {
|
|
207
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
208
|
-
async *[Symbol.asyncIterator](): AsyncIterator<string> {
|
|
209
|
-
yield "a";
|
|
210
|
-
yield "ab";
|
|
211
|
-
yield "b";
|
|
212
|
-
yield "ba";
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
const collection = new AsyncIterableCollection(asyncIterable),
|
|
216
|
-
newCollection = collection.flatMap((item, index) => [
|
|
217
|
-
index,
|
|
218
|
-
item,
|
|
219
|
-
item.length,
|
|
220
|
-
]);
|
|
221
|
-
expect(await newCollection.toArray()).toEqual([
|
|
222
|
-
0,
|
|
223
|
-
"a",
|
|
224
|
-
1,
|
|
225
|
-
1,
|
|
226
|
-
"ab",
|
|
227
|
-
2,
|
|
228
|
-
2,
|
|
229
|
-
"b",
|
|
230
|
-
1,
|
|
231
|
-
3,
|
|
232
|
-
"ba",
|
|
233
|
-
2,
|
|
234
|
-
]);
|
|
235
|
-
});
|
|
236
|
-
test("Should input correct indexes to map function", async () => {
|
|
237
|
-
const collection = new AsyncIterableCollection([
|
|
238
|
-
"a",
|
|
239
|
-
"ab",
|
|
240
|
-
"b",
|
|
241
|
-
"ba",
|
|
242
|
-
]),
|
|
243
|
-
indexes: number[] = [],
|
|
244
|
-
mapFunction = (
|
|
245
|
-
item: string,
|
|
246
|
-
index: number,
|
|
247
|
-
): [number, string, number] => {
|
|
248
|
-
indexes.push(index);
|
|
249
|
-
return [index, item, item.length];
|
|
250
|
-
};
|
|
251
|
-
await collection.flatMap(mapFunction).toArray();
|
|
252
|
-
expect(indexes).toEqual([0, 1, 2, 3]);
|
|
253
|
-
});
|
|
254
|
-
test("Should work with async flatMap function", async () => {
|
|
255
|
-
const collection = new AsyncIterableCollection([
|
|
256
|
-
"a",
|
|
257
|
-
"ab",
|
|
258
|
-
"b",
|
|
259
|
-
"ba",
|
|
260
|
-
]),
|
|
261
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
262
|
-
newCollection = collection.flatMap(async (item, index) => [
|
|
263
|
-
index,
|
|
264
|
-
item,
|
|
265
|
-
item.length,
|
|
266
|
-
]);
|
|
267
|
-
expect(await newCollection.toArray()).toEqual([
|
|
268
|
-
0,
|
|
269
|
-
"a",
|
|
270
|
-
1,
|
|
271
|
-
1,
|
|
272
|
-
"ab",
|
|
273
|
-
2,
|
|
274
|
-
2,
|
|
275
|
-
"b",
|
|
276
|
-
1,
|
|
277
|
-
3,
|
|
278
|
-
"ba",
|
|
279
|
-
2,
|
|
280
|
-
]);
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
describe("method: update", () => {
|
|
284
|
-
test("Should change all the items that match the filter function", async () => {
|
|
285
|
-
const collection = new AsyncIterableCollection([
|
|
286
|
-
"a",
|
|
287
|
-
"aa",
|
|
288
|
-
"b",
|
|
289
|
-
"bbb",
|
|
290
|
-
"c",
|
|
291
|
-
"cccc",
|
|
292
|
-
]),
|
|
293
|
-
newCollection = collection.update(
|
|
294
|
-
(item) => item.length >= 2,
|
|
295
|
-
(item) => item.slice(0, -1),
|
|
296
|
-
);
|
|
297
|
-
expect(await newCollection.toArray()).toEqual([
|
|
298
|
-
"a",
|
|
299
|
-
"a",
|
|
300
|
-
"b",
|
|
301
|
-
"bb",
|
|
302
|
-
"c",
|
|
303
|
-
"ccc",
|
|
304
|
-
]);
|
|
305
|
-
});
|
|
306
|
-
test("Should input correct indexes to filter function", async () => {
|
|
307
|
-
const collection = new AsyncIterableCollection([
|
|
308
|
-
"a",
|
|
309
|
-
"aa",
|
|
310
|
-
"b",
|
|
311
|
-
"bbb",
|
|
312
|
-
"c",
|
|
313
|
-
"cccc",
|
|
314
|
-
]),
|
|
315
|
-
indexes: number[] = [];
|
|
316
|
-
await collection
|
|
317
|
-
.update(
|
|
318
|
-
(item, index) => {
|
|
319
|
-
indexes.push(index);
|
|
320
|
-
return item.length >= 2;
|
|
321
|
-
},
|
|
322
|
-
(item) => item.slice(0, -1),
|
|
323
|
-
)
|
|
324
|
-
.toArray();
|
|
325
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4, 5]);
|
|
326
|
-
});
|
|
327
|
-
test("Should input correct indexes to map function", async () => {
|
|
328
|
-
const collection = new AsyncIterableCollection([
|
|
329
|
-
"a",
|
|
330
|
-
"aa",
|
|
331
|
-
"b",
|
|
332
|
-
"bbb",
|
|
333
|
-
"c",
|
|
334
|
-
"cccc",
|
|
335
|
-
]),
|
|
336
|
-
indexes: number[] = [];
|
|
337
|
-
await collection
|
|
338
|
-
.update(
|
|
339
|
-
(item) => item.length >= 2,
|
|
340
|
-
(item, index) => {
|
|
341
|
-
indexes.push(index);
|
|
342
|
-
return item.slice(0, -1);
|
|
343
|
-
},
|
|
344
|
-
)
|
|
345
|
-
.toArray();
|
|
346
|
-
expect(indexes).toEqual([1, 3, 5]);
|
|
347
|
-
});
|
|
348
|
-
test("Should work with async filter and map function", async () => {
|
|
349
|
-
const collection = new AsyncIterableCollection([
|
|
350
|
-
"a",
|
|
351
|
-
"aa",
|
|
352
|
-
"b",
|
|
353
|
-
"bbb",
|
|
354
|
-
"c",
|
|
355
|
-
"cccc",
|
|
356
|
-
]),
|
|
357
|
-
newCollection = collection.update(
|
|
358
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
359
|
-
async (item) => item.length >= 2,
|
|
360
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
361
|
-
async (item) => item.slice(0, -1),
|
|
362
|
-
);
|
|
363
|
-
expect(await newCollection.toArray()).toEqual([
|
|
364
|
-
"a",
|
|
365
|
-
"a",
|
|
366
|
-
"b",
|
|
367
|
-
"bb",
|
|
368
|
-
"c",
|
|
369
|
-
"ccc",
|
|
370
|
-
]);
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
describe("method: page", () => {
|
|
374
|
-
test("Should return the first 4 items when page is 1 and pageSize 4", async () => {
|
|
375
|
-
const arr = ["a", "b", "c", "d", "e", "f", "g", "h"],
|
|
376
|
-
collection = new AsyncIterableCollection(arr),
|
|
377
|
-
newCollection = collection.page({
|
|
378
|
-
page: 1,
|
|
379
|
-
pageSize: 4,
|
|
380
|
-
});
|
|
381
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(0, 4));
|
|
382
|
-
});
|
|
383
|
-
test("Should return the last 4 items when page is 2 and pageSize 4", async () => {
|
|
384
|
-
const arr = ["a", "b", "c", "d", "e", "f", "g", "h"],
|
|
385
|
-
collection = new AsyncIterableCollection(arr),
|
|
386
|
-
newCollection = collection.page({
|
|
387
|
-
page: 2,
|
|
388
|
-
pageSize: 4,
|
|
389
|
-
});
|
|
390
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(-4));
|
|
391
|
-
});
|
|
392
|
-
test("Should return the last 4 items when page is -1 and pageSize 4", async () => {
|
|
393
|
-
const arr = ["a", "b", "c", "d", "e", "f", "g", "h"],
|
|
394
|
-
collection = new AsyncIterableCollection(arr),
|
|
395
|
-
newCollection = collection.page({
|
|
396
|
-
page: -1,
|
|
397
|
-
pageSize: 4,
|
|
398
|
-
});
|
|
399
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(-4));
|
|
400
|
-
});
|
|
401
|
-
test("Should return the first 2 items when page is 1 and pageSize 2", async () => {
|
|
402
|
-
const arr = ["a", "b", "c", "d", "e", "f", "g", "h"],
|
|
403
|
-
collection = new AsyncIterableCollection(arr),
|
|
404
|
-
newCollection = collection.page({
|
|
405
|
-
page: 1,
|
|
406
|
-
pageSize: 2,
|
|
407
|
-
});
|
|
408
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(0, 2));
|
|
409
|
-
});
|
|
410
|
-
test("Should return the last 2 items when page is 4 and pageSize 2", async () => {
|
|
411
|
-
const arr = ["a", "b", "c", "d", "e", "f", "g", "h"],
|
|
412
|
-
collection = new AsyncIterableCollection(arr),
|
|
413
|
-
newCollection = collection.page({
|
|
414
|
-
page: 4,
|
|
415
|
-
pageSize: 2,
|
|
416
|
-
});
|
|
417
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(-2));
|
|
418
|
-
});
|
|
419
|
-
test("Should return the last 2 items when page is -1 and pageSize 2", async () => {
|
|
420
|
-
const arr = ["a", "b", "c", "d", "e", "f", "g", "h"],
|
|
421
|
-
collection = new AsyncIterableCollection(arr),
|
|
422
|
-
newCollection = collection.page({
|
|
423
|
-
page: -1,
|
|
424
|
-
pageSize: 2,
|
|
425
|
-
});
|
|
426
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(-2));
|
|
427
|
-
});
|
|
428
|
-
test("Should return the last 2 items when page is -4 and pageSize -2", async () => {
|
|
429
|
-
const arr = ["a", "b", "c", "d", "e", "f", "g", "h"],
|
|
430
|
-
collection = new AsyncIterableCollection(arr),
|
|
431
|
-
newCollection = collection.page({
|
|
432
|
-
page: -2,
|
|
433
|
-
pageSize: 2,
|
|
434
|
-
});
|
|
435
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(-4, -2));
|
|
436
|
-
});
|
|
437
|
-
});
|
|
438
|
-
describe("method: sum", () => {
|
|
439
|
-
test("Should calculate sum Iterable of [1, 2, 3, 4] to 10", async () => {
|
|
440
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
441
|
-
expect(await collection.sum()).toBe(10);
|
|
442
|
-
});
|
|
443
|
-
test("Should throw TypeError when containg a none number item", async () => {
|
|
444
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, "a"]);
|
|
445
|
-
await expect(async () => {
|
|
446
|
-
await collection.sum();
|
|
447
|
-
}).rejects.toThrowError(TypeError);
|
|
448
|
-
});
|
|
449
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
450
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
451
|
-
expect(await collection.sum()).toBe(10);
|
|
452
|
-
expect(await collection.sum()).toBe(10);
|
|
453
|
-
});
|
|
454
|
-
});
|
|
455
|
-
describe("method: average", () => {
|
|
456
|
-
test("Should calculate average Iterable of [1, 2, 3, 4] to 2.5", async () => {
|
|
457
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
458
|
-
expect(await collection.average()).toBe(2.5);
|
|
459
|
-
});
|
|
460
|
-
test("Should throw TypeError when containg a none number item", async () => {
|
|
461
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, "a"]);
|
|
462
|
-
await expect(async () => {
|
|
463
|
-
await collection.average();
|
|
464
|
-
}).rejects.toThrowError(TypeError);
|
|
465
|
-
});
|
|
466
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
467
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
468
|
-
expect(await collection.average()).toBe(2.5);
|
|
469
|
-
expect(await collection.average()).toBe(2.5);
|
|
470
|
-
});
|
|
471
|
-
});
|
|
472
|
-
describe("method: median", () => {
|
|
473
|
-
test("Should calculate median Iterable of [1, 2, 3, 4, 5] to 3", async () => {
|
|
474
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
475
|
-
expect(await collection.median()).toBe(3);
|
|
476
|
-
});
|
|
477
|
-
test("Should calculate median Iterable of [1, 2, 4, 5] to 3", async () => {
|
|
478
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
479
|
-
expect(await collection.median()).toBe(3);
|
|
480
|
-
});
|
|
481
|
-
test("Should throw TypeError when containg a none number item", async () => {
|
|
482
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, "a"]);
|
|
483
|
-
await expect(async () => {
|
|
484
|
-
await collection.median();
|
|
485
|
-
}).rejects.toThrowError(TypeError);
|
|
486
|
-
});
|
|
487
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
488
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
489
|
-
expect(await collection.median()).toBe(3);
|
|
490
|
-
expect(await collection.median()).toBe(3);
|
|
491
|
-
});
|
|
492
|
-
});
|
|
493
|
-
describe("method: min", () => {
|
|
494
|
-
test("Should return the smallest number", async () => {
|
|
495
|
-
const collection = new AsyncIterableCollection([2, 1, 3, -2, 4]);
|
|
496
|
-
expect(await collection.min()).toBe(-2);
|
|
497
|
-
});
|
|
498
|
-
test("Should throw TypeError when containg a none number item", async () => {
|
|
499
|
-
const collection = new AsyncIterableCollection([
|
|
500
|
-
2,
|
|
501
|
-
1,
|
|
502
|
-
3,
|
|
503
|
-
-2,
|
|
504
|
-
4,
|
|
505
|
-
"-4",
|
|
506
|
-
]);
|
|
507
|
-
await expect(async () => {
|
|
508
|
-
await collection.min();
|
|
509
|
-
}).rejects.toThrowError(TypeError);
|
|
510
|
-
});
|
|
511
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
512
|
-
const collection = new AsyncIterableCollection([2, 1, 3, -2, 4]);
|
|
513
|
-
expect(await collection.min()).toBe(-2);
|
|
514
|
-
expect(await collection.min()).toBe(-2);
|
|
515
|
-
});
|
|
516
|
-
});
|
|
517
|
-
describe("method: max", () => {
|
|
518
|
-
test("Should return the largest number", async () => {
|
|
519
|
-
const collection = new AsyncIterableCollection([2, 1, 3, -2, 4]);
|
|
520
|
-
expect(await collection.max()).toBe(4);
|
|
521
|
-
});
|
|
522
|
-
test("Should throw TypeError when containg a none number item", async () => {
|
|
523
|
-
const collection = new AsyncIterableCollection([
|
|
524
|
-
2,
|
|
525
|
-
1,
|
|
526
|
-
3,
|
|
527
|
-
-2,
|
|
528
|
-
4,
|
|
529
|
-
"-4",
|
|
530
|
-
]);
|
|
531
|
-
await expect(async () => {
|
|
532
|
-
await collection.max();
|
|
533
|
-
}).rejects.toThrowError(TypeError);
|
|
534
|
-
});
|
|
535
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
536
|
-
const collection = new AsyncIterableCollection([2, 1, 3, -2, 4]);
|
|
537
|
-
expect(await collection.max()).toBe(4);
|
|
538
|
-
expect(await collection.max()).toBe(4);
|
|
539
|
-
});
|
|
540
|
-
});
|
|
541
|
-
describe("method: percentage", () => {
|
|
542
|
-
test(`Should return 50 when filtering "a" of ["a", "b", "a", "c"]`, async () => {
|
|
543
|
-
const collection = new AsyncIterableCollection([
|
|
544
|
-
"a",
|
|
545
|
-
"b",
|
|
546
|
-
"a",
|
|
547
|
-
"b",
|
|
548
|
-
]);
|
|
549
|
-
expect(await collection.percentage((item) => item === "a")).toBe(
|
|
550
|
-
50,
|
|
551
|
-
);
|
|
552
|
-
});
|
|
553
|
-
test("Should input correct indexes to filter function", async () => {
|
|
554
|
-
const collection = new AsyncIterableCollection([
|
|
555
|
-
"a",
|
|
556
|
-
"bc",
|
|
557
|
-
"c",
|
|
558
|
-
"a",
|
|
559
|
-
"d",
|
|
560
|
-
"a",
|
|
561
|
-
]),
|
|
562
|
-
indexes: number[] = [],
|
|
563
|
-
filterFunction = (item: string, index: number): boolean => {
|
|
564
|
-
indexes.push(index);
|
|
565
|
-
return item === "a";
|
|
566
|
-
};
|
|
567
|
-
await collection.percentage(filterFunction);
|
|
568
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4, 5]);
|
|
569
|
-
});
|
|
570
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
571
|
-
const collection = new AsyncIterableCollection([
|
|
572
|
-
"a",
|
|
573
|
-
"b",
|
|
574
|
-
"a",
|
|
575
|
-
"b",
|
|
576
|
-
]);
|
|
577
|
-
expect(await collection.percentage((item) => item === "a")).toBe(
|
|
578
|
-
50,
|
|
579
|
-
);
|
|
580
|
-
expect(await collection.percentage((item) => item === "a")).toBe(
|
|
581
|
-
50,
|
|
582
|
-
);
|
|
583
|
-
});
|
|
584
|
-
test("Should work with async filter function", async () => {
|
|
585
|
-
const collection = new AsyncIterableCollection([
|
|
586
|
-
"a",
|
|
587
|
-
"b",
|
|
588
|
-
"a",
|
|
589
|
-
"b",
|
|
590
|
-
]);
|
|
591
|
-
expect(
|
|
592
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
593
|
-
await collection.percentage(async (item) => item === "a"),
|
|
594
|
-
).toBe(50);
|
|
595
|
-
});
|
|
596
|
-
});
|
|
597
|
-
describe("method: some", () => {
|
|
598
|
-
test("Should return true when at least 1 item match the filter function", async () => {
|
|
599
|
-
const collection = new AsyncIterableCollection([
|
|
600
|
-
"a",
|
|
601
|
-
"b",
|
|
602
|
-
"c",
|
|
603
|
-
"c",
|
|
604
|
-
"a",
|
|
605
|
-
]);
|
|
606
|
-
expect(await collection.some((item) => item === "b")).toBe(true);
|
|
607
|
-
});
|
|
608
|
-
test("Should return false when all of the items does not match the filter function", async () => {
|
|
609
|
-
const collection = new AsyncIterableCollection([
|
|
610
|
-
"a",
|
|
611
|
-
"b",
|
|
612
|
-
"c",
|
|
613
|
-
"c",
|
|
614
|
-
"a",
|
|
615
|
-
]);
|
|
616
|
-
expect(await collection.some((item) => item === "d")).toBe(false);
|
|
617
|
-
});
|
|
618
|
-
test("Should input correct indexes to filter function", async () => {
|
|
619
|
-
const collection = new AsyncIterableCollection([
|
|
620
|
-
"a",
|
|
621
|
-
"bc",
|
|
622
|
-
"c",
|
|
623
|
-
"a",
|
|
624
|
-
"d",
|
|
625
|
-
"a",
|
|
626
|
-
]),
|
|
627
|
-
indexes: number[] = [],
|
|
628
|
-
filterFunction = (item: string, index: number): boolean => {
|
|
629
|
-
indexes.push(index);
|
|
630
|
-
return item === "a";
|
|
631
|
-
};
|
|
632
|
-
await collection.some(filterFunction);
|
|
633
|
-
expect(indexes).toEqual([0]);
|
|
634
|
-
});
|
|
635
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
636
|
-
const collection = new AsyncIterableCollection([
|
|
637
|
-
"a",
|
|
638
|
-
"b",
|
|
639
|
-
"c",
|
|
640
|
-
"c",
|
|
641
|
-
"a",
|
|
642
|
-
]);
|
|
643
|
-
expect(await collection.some((item) => item === "b")).toBe(true);
|
|
644
|
-
expect(await collection.some((item) => item === "b")).toBe(true);
|
|
645
|
-
});
|
|
646
|
-
test("Should work with async filter function", async () => {
|
|
647
|
-
const collection = new AsyncIterableCollection([
|
|
648
|
-
"a",
|
|
649
|
-
"b",
|
|
650
|
-
"c",
|
|
651
|
-
"c",
|
|
652
|
-
"a",
|
|
653
|
-
]);
|
|
654
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
655
|
-
expect(await collection.some(async (item) => item === "b")).toBe(
|
|
656
|
-
true,
|
|
657
|
-
);
|
|
658
|
-
});
|
|
659
|
-
});
|
|
660
|
-
describe("method: every", () => {
|
|
661
|
-
test("Should return true when all items match the filter function", async () => {
|
|
662
|
-
const collection = new AsyncIterableCollection([
|
|
663
|
-
"a",
|
|
664
|
-
"b",
|
|
665
|
-
"c",
|
|
666
|
-
"c",
|
|
667
|
-
"a",
|
|
668
|
-
]);
|
|
669
|
-
expect(await collection.every((item) => item.length === 1)).toBe(
|
|
670
|
-
true,
|
|
671
|
-
);
|
|
672
|
-
});
|
|
673
|
-
test("Should return false when one item does not match the filter function", async () => {
|
|
674
|
-
const collection = new AsyncIterableCollection([
|
|
675
|
-
"a",
|
|
676
|
-
"b",
|
|
677
|
-
"c",
|
|
678
|
-
"c",
|
|
679
|
-
"aa",
|
|
680
|
-
]);
|
|
681
|
-
expect(await collection.every((item) => item.length === 1)).toBe(
|
|
682
|
-
false,
|
|
683
|
-
);
|
|
684
|
-
});
|
|
685
|
-
test("Should input correct indexes to filter function", async () => {
|
|
686
|
-
const collection = new AsyncIterableCollection([
|
|
687
|
-
"a",
|
|
688
|
-
"b",
|
|
689
|
-
"c",
|
|
690
|
-
"c",
|
|
691
|
-
"aa",
|
|
692
|
-
]),
|
|
693
|
-
indexes: number[] = [];
|
|
694
|
-
await collection.every((item, index) => {
|
|
695
|
-
indexes.push(index);
|
|
696
|
-
return item.length === 1;
|
|
697
|
-
});
|
|
698
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4]);
|
|
699
|
-
});
|
|
700
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
701
|
-
const collection = new AsyncIterableCollection([
|
|
702
|
-
"a",
|
|
703
|
-
"b",
|
|
704
|
-
"c",
|
|
705
|
-
"c",
|
|
706
|
-
"a",
|
|
707
|
-
]);
|
|
708
|
-
expect(await collection.every((item) => item.length === 1)).toBe(
|
|
709
|
-
true,
|
|
710
|
-
);
|
|
711
|
-
expect(await collection.every((item) => item.length === 1)).toBe(
|
|
712
|
-
true,
|
|
713
|
-
);
|
|
714
|
-
});
|
|
715
|
-
test("Should work with async filter function", async () => {
|
|
716
|
-
const collection = new AsyncIterableCollection([
|
|
717
|
-
"a",
|
|
718
|
-
"b",
|
|
719
|
-
"c",
|
|
720
|
-
"c",
|
|
721
|
-
"a",
|
|
722
|
-
]);
|
|
723
|
-
expect(
|
|
724
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
725
|
-
await collection.every(async (item) => item.length === 1),
|
|
726
|
-
).toBe(true);
|
|
727
|
-
});
|
|
728
|
-
});
|
|
729
|
-
describe("method: take", () => {
|
|
730
|
-
test("Should take first item when input is 1", async () => {
|
|
731
|
-
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
|
732
|
-
collection = new AsyncIterableCollection(arr),
|
|
733
|
-
newCollection = collection.take(1);
|
|
734
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(0, 1));
|
|
735
|
-
});
|
|
736
|
-
test("Should take 5 first items when input is 5", async () => {
|
|
737
|
-
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
|
738
|
-
collection = new AsyncIterableCollection(arr),
|
|
739
|
-
newCollection = collection.take(5);
|
|
740
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(0, 5));
|
|
741
|
-
});
|
|
742
|
-
test("Should take 8 first items when input is -2", async () => {
|
|
743
|
-
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
|
744
|
-
collection = new AsyncIterableCollection(arr),
|
|
745
|
-
newCollection = collection.take(-2);
|
|
746
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(0, -2));
|
|
747
|
-
});
|
|
748
|
-
});
|
|
749
|
-
describe("method: takeUntil", () => {
|
|
750
|
-
test("Should take all items until item is larger or equal to 3", async () => {
|
|
751
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]),
|
|
752
|
-
newCollection = collection.takeUntil((item) => item >= 3);
|
|
753
|
-
expect(await newCollection.toArray()).toEqual([1, 2]);
|
|
754
|
-
});
|
|
755
|
-
test("Should input correct indexes to filter function", async () => {
|
|
756
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]),
|
|
757
|
-
indexes: number[] = [];
|
|
758
|
-
await collection
|
|
759
|
-
.takeUntil((item, index) => {
|
|
760
|
-
indexes.push(index);
|
|
761
|
-
return item >= 3;
|
|
762
|
-
})
|
|
763
|
-
.toArray();
|
|
764
|
-
expect(indexes).toEqual([0, 1, 2]);
|
|
765
|
-
});
|
|
766
|
-
test("Should work with async filter function", async () => {
|
|
767
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]),
|
|
768
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
769
|
-
newCollection = collection.takeUntil(async (item) => item >= 3);
|
|
770
|
-
expect(await newCollection.toArray()).toEqual([1, 2]);
|
|
771
|
-
});
|
|
772
|
-
});
|
|
773
|
-
describe("method: takeWhile", () => {
|
|
774
|
-
test("Should take all items while item is less than 3", async () => {
|
|
775
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]),
|
|
776
|
-
newCollection = collection.takeWhile((item) => item < 3);
|
|
777
|
-
expect(await newCollection.toArray()).toEqual([1, 2]);
|
|
778
|
-
});
|
|
779
|
-
test("Should input correct indexes to filter function", async () => {
|
|
780
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]),
|
|
781
|
-
indexes: number[] = [];
|
|
782
|
-
await collection
|
|
783
|
-
.takeWhile((item, index) => {
|
|
784
|
-
indexes.push(index);
|
|
785
|
-
return item < 3;
|
|
786
|
-
})
|
|
787
|
-
.toArray();
|
|
788
|
-
expect(indexes).toEqual([0, 1, 2]);
|
|
789
|
-
});
|
|
790
|
-
test("Should work with async filter function", async () => {
|
|
791
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]),
|
|
792
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
793
|
-
newCollection = collection.takeWhile(async (item) => item < 3);
|
|
794
|
-
expect(await newCollection.toArray()).toEqual([1, 2]);
|
|
795
|
-
});
|
|
796
|
-
});
|
|
797
|
-
describe("method: skip", () => {
|
|
798
|
-
test("Should skip first item when input is 1", async () => {
|
|
799
|
-
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
|
800
|
-
collection = new AsyncIterableCollection(arr),
|
|
801
|
-
newCollection = collection.skip(1);
|
|
802
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(1));
|
|
803
|
-
});
|
|
804
|
-
test("Should skip 5 first items when input is 5", async () => {
|
|
805
|
-
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
|
806
|
-
collection = new AsyncIterableCollection(arr),
|
|
807
|
-
newCollection = collection.skip(5);
|
|
808
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(5));
|
|
809
|
-
});
|
|
810
|
-
test("Should skip 8 first items when input is -2", async () => {
|
|
811
|
-
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
|
812
|
-
collection = new AsyncIterableCollection(arr),
|
|
813
|
-
newCollection = collection.skip(-2);
|
|
814
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(-2));
|
|
815
|
-
});
|
|
816
|
-
});
|
|
817
|
-
describe("method: skipUntil", () => {
|
|
818
|
-
test("Should skip all items until item is larger or equal to 3", async () => {
|
|
819
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]),
|
|
820
|
-
newCollection = collection.skipUntil((item) => item >= 3);
|
|
821
|
-
expect(await newCollection.toArray()).toEqual([3, 4]);
|
|
822
|
-
});
|
|
823
|
-
test("Should input correct indexes to filter function", async () => {
|
|
824
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]),
|
|
825
|
-
indexes: number[] = [];
|
|
826
|
-
await collection
|
|
827
|
-
.skipUntil((item, index) => {
|
|
828
|
-
indexes.push(index);
|
|
829
|
-
return item >= 3;
|
|
830
|
-
})
|
|
831
|
-
.toArray();
|
|
832
|
-
expect(indexes).toEqual([0, 1, 2]);
|
|
833
|
-
});
|
|
834
|
-
test("Should work with async filter function", async () => {
|
|
835
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]),
|
|
836
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
837
|
-
newCollection = collection.skipUntil(async (item) => item >= 3);
|
|
838
|
-
expect(await newCollection.toArray()).toEqual([3, 4]);
|
|
839
|
-
});
|
|
840
|
-
});
|
|
841
|
-
describe("method: skipWhile", () => {
|
|
842
|
-
test("Should skipp all items while item is less than 3", async () => {
|
|
843
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]),
|
|
844
|
-
newCollection = collection.skipWhile((item) => item <= 3);
|
|
845
|
-
expect(await newCollection.toArray()).toEqual([4]);
|
|
846
|
-
});
|
|
847
|
-
test("Should input correct indexes to filter function", async () => {
|
|
848
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]),
|
|
849
|
-
indexes: number[] = [];
|
|
850
|
-
await collection
|
|
851
|
-
.skipWhile((item, index) => {
|
|
852
|
-
indexes.push(index);
|
|
853
|
-
return item <= 3;
|
|
854
|
-
})
|
|
855
|
-
.toArray();
|
|
856
|
-
expect(indexes).toEqual([0, 1, 2, 3]);
|
|
857
|
-
});
|
|
858
|
-
test("Should work with async filter function", async () => {
|
|
859
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4]),
|
|
860
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
861
|
-
newCollection = collection.skipWhile(async (item) => item <= 3);
|
|
862
|
-
expect(await newCollection.toArray()).toEqual([4]);
|
|
863
|
-
});
|
|
864
|
-
});
|
|
865
|
-
describe("method: when", () => {
|
|
866
|
-
test("Should append items when statement is true", async () => {
|
|
867
|
-
const arr1 = ["a", "b", "c"],
|
|
868
|
-
collection = new AsyncIterableCollection(arr1),
|
|
869
|
-
arr2 = [1, 2, 3],
|
|
870
|
-
newCollection = collection.when(true, (collection) =>
|
|
871
|
-
collection.append(arr2),
|
|
872
|
-
);
|
|
873
|
-
expect(await newCollection.toArray()).toEqual([...arr1, ...arr2]);
|
|
874
|
-
});
|
|
875
|
-
test("Should not append items when statement is false", async () => {
|
|
876
|
-
const arr1 = ["a", "b", "c"],
|
|
877
|
-
collection = new AsyncIterableCollection(arr1),
|
|
878
|
-
arr2 = [1, 2, 3],
|
|
879
|
-
newCollection = collection.when(false, (collection) =>
|
|
880
|
-
collection.append(arr2),
|
|
881
|
-
);
|
|
882
|
-
expect(await newCollection.toArray()).toEqual(arr1);
|
|
883
|
-
});
|
|
884
|
-
test("Should work with async modifier function", async () => {
|
|
885
|
-
const arr1 = ["a", "b", "c"],
|
|
886
|
-
collection = new AsyncIterableCollection(arr1),
|
|
887
|
-
arr2 = [1, 2, 3],
|
|
888
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
889
|
-
newCollection = collection.when(true, async (collection) =>
|
|
890
|
-
collection.append(arr2),
|
|
891
|
-
);
|
|
892
|
-
expect(await newCollection.toArray()).toEqual([...arr1, ...arr2]);
|
|
893
|
-
});
|
|
894
|
-
});
|
|
895
|
-
describe("method: whenEmpty", () => {
|
|
896
|
-
test("Should append items when empty", async () => {
|
|
897
|
-
const collection = new AsyncIterableCollection<string>([]),
|
|
898
|
-
arr2 = [1, 2, 3],
|
|
899
|
-
newCollection = collection.whenEmpty((collection) =>
|
|
900
|
-
collection.append(arr2),
|
|
901
|
-
);
|
|
902
|
-
expect(await newCollection.toArray()).toEqual(arr2);
|
|
903
|
-
});
|
|
904
|
-
test("Should not append items when not empty", async () => {
|
|
905
|
-
const arr1 = ["a", "b", "c"],
|
|
906
|
-
collection = new AsyncIterableCollection(arr1),
|
|
907
|
-
arr2 = [1, 2, 3],
|
|
908
|
-
newCollection = collection.whenEmpty((collection) =>
|
|
909
|
-
collection.append(arr2),
|
|
910
|
-
);
|
|
911
|
-
expect(await newCollection.toArray()).toEqual(arr1);
|
|
912
|
-
});
|
|
913
|
-
test("Should work with async modifier function", async () => {
|
|
914
|
-
const collection = new AsyncIterableCollection<string>([]),
|
|
915
|
-
arr2 = [1, 2, 3],
|
|
916
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
917
|
-
newCollection = collection.whenEmpty(async (collection) =>
|
|
918
|
-
collection.append(arr2),
|
|
919
|
-
);
|
|
920
|
-
expect(await newCollection.toArray()).toEqual(arr2);
|
|
921
|
-
});
|
|
922
|
-
});
|
|
923
|
-
describe("method: whenNot", () => {
|
|
924
|
-
test("Should append items when statement is false", async () => {
|
|
925
|
-
const arr1 = ["a", "b", "c"],
|
|
926
|
-
collection = new AsyncIterableCollection(arr1),
|
|
927
|
-
arr2 = [1, 2, 3],
|
|
928
|
-
newCollection = collection.whenNot(false, (collection) =>
|
|
929
|
-
collection.append(arr2),
|
|
930
|
-
);
|
|
931
|
-
expect(await newCollection.toArray()).toEqual([...arr1, ...arr2]);
|
|
932
|
-
});
|
|
933
|
-
test("Should not append items when statement is true", async () => {
|
|
934
|
-
const arr1 = ["a", "b", "c"],
|
|
935
|
-
collection = new AsyncIterableCollection(arr1),
|
|
936
|
-
arr2 = [1, 2, 3],
|
|
937
|
-
newCollection = collection.whenNot(true, (collection) =>
|
|
938
|
-
collection.append(arr2),
|
|
939
|
-
);
|
|
940
|
-
expect(await newCollection.toArray()).toEqual(arr1);
|
|
941
|
-
});
|
|
942
|
-
test("Should work with async modifier function", async () => {
|
|
943
|
-
const arr1 = ["a", "b", "c"],
|
|
944
|
-
collection = new AsyncIterableCollection(arr1),
|
|
945
|
-
arr2 = [1, 2, 3],
|
|
946
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
947
|
-
newCollection = collection.whenNot(false, async (collection) =>
|
|
948
|
-
collection.append(arr2),
|
|
949
|
-
);
|
|
950
|
-
expect(await newCollection.toArray()).toEqual([...arr1, ...arr2]);
|
|
951
|
-
});
|
|
952
|
-
});
|
|
953
|
-
describe("method: whenNotEmpty", () => {
|
|
954
|
-
test("Should append items when not empty", async () => {
|
|
955
|
-
const arr1 = ["a", "b", "c"],
|
|
956
|
-
collection = new AsyncIterableCollection(arr1),
|
|
957
|
-
arr2 = [1, 2, 3],
|
|
958
|
-
newCollection = collection.whenNotEmpty((collection) =>
|
|
959
|
-
collection.append(arr2),
|
|
960
|
-
);
|
|
961
|
-
expect(await newCollection.toArray()).toEqual([...arr1, ...arr2]);
|
|
962
|
-
});
|
|
963
|
-
test("Should not append items when empty", async () => {
|
|
964
|
-
const collection = new AsyncIterableCollection([]),
|
|
965
|
-
arr2 = [1, 2, 3],
|
|
966
|
-
newCollection = collection.whenNotEmpty((collection) =>
|
|
967
|
-
collection.append(arr2),
|
|
968
|
-
);
|
|
969
|
-
expect(await newCollection.toArray()).toEqual([]);
|
|
970
|
-
});
|
|
971
|
-
test("Should work with async modifier function", async () => {
|
|
972
|
-
const arr1 = ["a", "b", "c"],
|
|
973
|
-
collection = new AsyncIterableCollection(arr1),
|
|
974
|
-
arr2 = [1, 2, 3],
|
|
975
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
976
|
-
newCollection = collection.whenNotEmpty(async (collection) =>
|
|
977
|
-
collection.append(arr2),
|
|
978
|
-
);
|
|
979
|
-
expect(await newCollection.toArray()).toEqual([...arr1, ...arr2]);
|
|
980
|
-
});
|
|
981
|
-
});
|
|
982
|
-
describe("method: pipe", () => {
|
|
983
|
-
test("Should pipe multiple functions", async () => {
|
|
984
|
-
const collection = new AsyncIterableCollection([
|
|
985
|
-
"a",
|
|
986
|
-
"ab",
|
|
987
|
-
"abc",
|
|
988
|
-
"abcd",
|
|
989
|
-
]),
|
|
990
|
-
a = await collection
|
|
991
|
-
.pipe((collection) =>
|
|
992
|
-
collection.map((item) =>
|
|
993
|
-
new AsyncIterableCollection(item).map((char) =>
|
|
994
|
-
char.charCodeAt(0),
|
|
995
|
-
),
|
|
996
|
-
),
|
|
997
|
-
)
|
|
998
|
-
.then((collection) =>
|
|
999
|
-
collection.pipe((collection) =>
|
|
1000
|
-
collection.map((collection) => collection.sum()),
|
|
1001
|
-
),
|
|
1002
|
-
)
|
|
1003
|
-
.then((collection) =>
|
|
1004
|
-
collection.pipe((collection) => collection.sum()),
|
|
1005
|
-
);
|
|
1006
|
-
expect(a).toBeTypeOf("number");
|
|
1007
|
-
});
|
|
1008
|
-
});
|
|
1009
|
-
describe("method: tap", () => {
|
|
1010
|
-
test("Should change the original collection", async () => {
|
|
1011
|
-
const arr = ["a", "ab", "abc"],
|
|
1012
|
-
collection = new AsyncIterableCollection(arr).tap(
|
|
1013
|
-
(collection) => collection.map((item) => item.length),
|
|
1014
|
-
);
|
|
1015
|
-
expect(await collection.toArray()).toEqual(arr);
|
|
1016
|
-
});
|
|
1017
|
-
test("Should work with async tap function", async () => {
|
|
1018
|
-
const arr = ["a", "ab", "abc"],
|
|
1019
|
-
collection = new AsyncIterableCollection(arr).tap(
|
|
1020
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1021
|
-
(collection) => collection.map(async (item) => item.length),
|
|
1022
|
-
);
|
|
1023
|
-
expect(await collection.toArray()).toEqual(arr);
|
|
1024
|
-
});
|
|
1025
|
-
});
|
|
1026
|
-
describe("method: chunk", () => {
|
|
1027
|
-
test("Should group items into groups of size 1", async () => {
|
|
1028
|
-
const arr = [1, 2, 3, 4, 5, 6, 7, 8],
|
|
1029
|
-
collection = new AsyncIterableCollection(arr),
|
|
1030
|
-
newCollection = collection.chunk(1);
|
|
1031
|
-
expect(
|
|
1032
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1033
|
-
).toEqual(arr.map((item) => [item]));
|
|
1034
|
-
});
|
|
1035
|
-
test("Should group items into groups of size 4", async () => {
|
|
1036
|
-
const arr = [1, 2, 3, 4, 5, 6, 7, 8],
|
|
1037
|
-
collection = new AsyncIterableCollection(arr),
|
|
1038
|
-
newCollection = collection.chunk(4);
|
|
1039
|
-
expect(
|
|
1040
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1041
|
-
).toEqual([arr.slice(0, 4), arr.slice(4)]);
|
|
1042
|
-
});
|
|
1043
|
-
});
|
|
1044
|
-
describe("method: chunkWhile", () => {
|
|
1045
|
-
test("Should group items by checking if next item is the same as the current item", async () => {
|
|
1046
|
-
const collection = new AsyncIterableCollection(
|
|
1047
|
-
"AABBCCCD".split(""),
|
|
1048
|
-
),
|
|
1049
|
-
newCollection = collection.chunkWhile(
|
|
1050
|
-
async (value, _index, chunk) =>
|
|
1051
|
-
value === (await chunk.last()),
|
|
1052
|
-
);
|
|
1053
|
-
expect(
|
|
1054
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1055
|
-
).toEqual([["A", "A"], ["B", "B"], ["C", "C", "C"], ["D"]]);
|
|
1056
|
-
});
|
|
1057
|
-
});
|
|
1058
|
-
describe("method: split", () => {
|
|
1059
|
-
test("Should split items into 3 groups in equal size when size is 9", async () => {
|
|
1060
|
-
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9],
|
|
1061
|
-
collection = new AsyncIterableCollection(arr),
|
|
1062
|
-
newCollection = collection.split(3);
|
|
1063
|
-
expect(
|
|
1064
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1065
|
-
).toEqual([arr.slice(0, 3), arr.slice(3, 6), arr.slice(6, 9)]);
|
|
1066
|
-
});
|
|
1067
|
-
test("Should split items into 3 groups where the first group have on item more when size is 10", async () => {
|
|
1068
|
-
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
|
1069
|
-
collection = new AsyncIterableCollection(arr),
|
|
1070
|
-
newCollection = collection.split(3);
|
|
1071
|
-
expect(
|
|
1072
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1073
|
-
).toEqual([arr.slice(0, 4), arr.slice(4, 7), arr.slice(7, 10)]);
|
|
1074
|
-
});
|
|
1075
|
-
test("Should split items into 3 groups where the first and second group have on item more when size is 11", async () => {
|
|
1076
|
-
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
|
|
1077
|
-
collection = new AsyncIterableCollection(arr),
|
|
1078
|
-
newCollection = collection.split(3);
|
|
1079
|
-
expect(
|
|
1080
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1081
|
-
).toEqual([arr.slice(0, 4), arr.slice(4, 8), arr.slice(8, 11)]);
|
|
1082
|
-
});
|
|
1083
|
-
});
|
|
1084
|
-
describe("method: partition", () => {
|
|
1085
|
-
test("Should group items into strings and number", async () => {
|
|
1086
|
-
const arr = ["a", 1, "b", 2, "c", 3, "d", 4, "e", 5],
|
|
1087
|
-
collection = new AsyncIterableCollection(arr),
|
|
1088
|
-
newCollection = collection.partition(
|
|
1089
|
-
(item) => typeof item === "string",
|
|
1090
|
-
);
|
|
1091
|
-
expect(
|
|
1092
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1093
|
-
).toEqual([
|
|
1094
|
-
arr.filter((item) => typeof item === "string"),
|
|
1095
|
-
arr.filter((item) => typeof item === "number"),
|
|
1096
|
-
]);
|
|
1097
|
-
});
|
|
1098
|
-
test("Should input correct indexes to filter function", async () => {
|
|
1099
|
-
const arr = ["a", 1, "b", 2, "c", 3, "d", 4, "e", 5],
|
|
1100
|
-
collection = new AsyncIterableCollection(arr),
|
|
1101
|
-
indexes: number[] = [];
|
|
1102
|
-
await collection
|
|
1103
|
-
.partition((item, index) => {
|
|
1104
|
-
indexes.push(index);
|
|
1105
|
-
return typeof item === "string";
|
|
1106
|
-
})
|
|
1107
|
-
.toArray();
|
|
1108
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
1109
|
-
});
|
|
1110
|
-
test("Should work with async filter function", async () => {
|
|
1111
|
-
const arr = ["a", 1, "b", 2, "c", 3, "d", 4, "e", 5],
|
|
1112
|
-
collection = new AsyncIterableCollection(arr),
|
|
1113
|
-
newCollection = collection.partition(
|
|
1114
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1115
|
-
async (item) => typeof item === "string",
|
|
1116
|
-
);
|
|
1117
|
-
expect(
|
|
1118
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1119
|
-
).toEqual([
|
|
1120
|
-
arr.filter((item) => typeof item === "string"),
|
|
1121
|
-
arr.filter((item) => typeof item === "number"),
|
|
1122
|
-
]);
|
|
1123
|
-
});
|
|
1124
|
-
});
|
|
1125
|
-
describe("method: sliding", () => {
|
|
1126
|
-
test("Should group items into 7 groups when size is 2", async () => {
|
|
1127
|
-
const collection = new AsyncIterableCollection([
|
|
1128
|
-
"a",
|
|
1129
|
-
"b",
|
|
1130
|
-
"c",
|
|
1131
|
-
"d",
|
|
1132
|
-
"e",
|
|
1133
|
-
"f",
|
|
1134
|
-
"g",
|
|
1135
|
-
"h",
|
|
1136
|
-
]),
|
|
1137
|
-
newCollection = collection.sliding({ chunkSize: 2 });
|
|
1138
|
-
expect(
|
|
1139
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1140
|
-
).toEqual([
|
|
1141
|
-
["a", "b"],
|
|
1142
|
-
["b", "c"],
|
|
1143
|
-
["c", "d"],
|
|
1144
|
-
["d", "e"],
|
|
1145
|
-
["e", "f"],
|
|
1146
|
-
["f", "g"],
|
|
1147
|
-
["g", "h"],
|
|
1148
|
-
]);
|
|
1149
|
-
});
|
|
1150
|
-
test("Should group items into 4 groups when size is 3", async () => {
|
|
1151
|
-
const collection = new AsyncIterableCollection([
|
|
1152
|
-
"a",
|
|
1153
|
-
"b",
|
|
1154
|
-
"c",
|
|
1155
|
-
"d",
|
|
1156
|
-
"e",
|
|
1157
|
-
"f",
|
|
1158
|
-
"g",
|
|
1159
|
-
"h",
|
|
1160
|
-
]),
|
|
1161
|
-
newCollection = collection.sliding({ chunkSize: 3 });
|
|
1162
|
-
expect(
|
|
1163
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1164
|
-
).toEqual([
|
|
1165
|
-
["a", "b", "c"],
|
|
1166
|
-
["c", "d", "e"],
|
|
1167
|
-
["e", "f", "g"],
|
|
1168
|
-
["g", "h"],
|
|
1169
|
-
]);
|
|
1170
|
-
});
|
|
1171
|
-
test("Should group items into 6 groups when size is 3 and step is 1", async () => {
|
|
1172
|
-
const collection = new AsyncIterableCollection([
|
|
1173
|
-
"a",
|
|
1174
|
-
"b",
|
|
1175
|
-
"c",
|
|
1176
|
-
"d",
|
|
1177
|
-
"e",
|
|
1178
|
-
"f",
|
|
1179
|
-
"g",
|
|
1180
|
-
"h",
|
|
1181
|
-
]),
|
|
1182
|
-
newCollection = collection.sliding({ chunkSize: 3, step: 1 });
|
|
1183
|
-
expect(
|
|
1184
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1185
|
-
).toEqual([
|
|
1186
|
-
["a", "b", "c"],
|
|
1187
|
-
["b", "c", "d"],
|
|
1188
|
-
["c", "d", "e"],
|
|
1189
|
-
["d", "e", "f"],
|
|
1190
|
-
["e", "f", "g"],
|
|
1191
|
-
["f", "g", "h"],
|
|
1192
|
-
]);
|
|
1193
|
-
});
|
|
1194
|
-
test("Should group items into 6 groups when size is 4 and step is 2", async () => {
|
|
1195
|
-
const collection = new AsyncIterableCollection([
|
|
1196
|
-
"a",
|
|
1197
|
-
"b",
|
|
1198
|
-
"c",
|
|
1199
|
-
"d",
|
|
1200
|
-
"e",
|
|
1201
|
-
"f",
|
|
1202
|
-
"g",
|
|
1203
|
-
"h",
|
|
1204
|
-
]),
|
|
1205
|
-
newCollection = collection.sliding({ chunkSize: 4, step: 2 });
|
|
1206
|
-
expect(
|
|
1207
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1208
|
-
).toEqual([
|
|
1209
|
-
["a", "b", "c", "d"],
|
|
1210
|
-
["c", "d", "e", "f"],
|
|
1211
|
-
["e", "f", "g", "h"],
|
|
1212
|
-
]);
|
|
1213
|
-
});
|
|
1214
|
-
test("Should group items into 4 groups when size is 1 and step is 2", async () => {
|
|
1215
|
-
const collection = new AsyncIterableCollection([
|
|
1216
|
-
"a",
|
|
1217
|
-
"b",
|
|
1218
|
-
"c",
|
|
1219
|
-
"d",
|
|
1220
|
-
"e",
|
|
1221
|
-
"f",
|
|
1222
|
-
"g",
|
|
1223
|
-
"h",
|
|
1224
|
-
]),
|
|
1225
|
-
newCollection = collection.sliding({ chunkSize: 1, step: 2 });
|
|
1226
|
-
expect(
|
|
1227
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1228
|
-
).toEqual([["a"], ["c"], ["e"], ["g"]]);
|
|
1229
|
-
});
|
|
1230
|
-
test("Should group items into 3 groups when size is 1 and step is 3", async () => {
|
|
1231
|
-
const collection = new AsyncIterableCollection([
|
|
1232
|
-
"a",
|
|
1233
|
-
"b",
|
|
1234
|
-
"c",
|
|
1235
|
-
"d",
|
|
1236
|
-
"e",
|
|
1237
|
-
"f",
|
|
1238
|
-
"g",
|
|
1239
|
-
"h",
|
|
1240
|
-
]),
|
|
1241
|
-
newCollection = collection.sliding({ chunkSize: 1, step: 3 });
|
|
1242
|
-
expect(
|
|
1243
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1244
|
-
).toEqual([["a"], ["d"], ["g"]]);
|
|
1245
|
-
});
|
|
1246
|
-
test("Should group items into 2 groups when size is 1 and step is 4", async () => {
|
|
1247
|
-
const collection = new AsyncIterableCollection([
|
|
1248
|
-
"a",
|
|
1249
|
-
"b",
|
|
1250
|
-
"c",
|
|
1251
|
-
"d",
|
|
1252
|
-
"e",
|
|
1253
|
-
"f",
|
|
1254
|
-
"g",
|
|
1255
|
-
"h",
|
|
1256
|
-
]),
|
|
1257
|
-
newCollection = collection.sliding({ chunkSize: 1, step: 3 });
|
|
1258
|
-
expect(
|
|
1259
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1260
|
-
).toEqual([["a"], ["d"], ["g"]]);
|
|
1261
|
-
});
|
|
1262
|
-
test("Should group items into 1 groups when size is 2 and step is 1 and array size is 2", async () => {
|
|
1263
|
-
const collection = new AsyncIterableCollection(["a", "b"]),
|
|
1264
|
-
newCollection = collection.sliding({ chunkSize: 2, step: 1 });
|
|
1265
|
-
expect(
|
|
1266
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1267
|
-
).toEqual([["a", "b"]]);
|
|
1268
|
-
});
|
|
1269
|
-
test("Should group items into 1 groups when size is 2 and step is 2 and array size is 2", async () => {
|
|
1270
|
-
const collection = new AsyncIterableCollection(["a", "b"]),
|
|
1271
|
-
newCollection = collection.sliding({ chunkSize: 2, step: 2 });
|
|
1272
|
-
expect(
|
|
1273
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1274
|
-
).toEqual([["a", "b"]]);
|
|
1275
|
-
});
|
|
1276
|
-
test("Should group items into 1 groups when size is 3 and step is 2 and array size is 2", async () => {
|
|
1277
|
-
const collection = new AsyncIterableCollection(["a", "b"]),
|
|
1278
|
-
newCollection = collection.sliding({ chunkSize: 2, step: 3 });
|
|
1279
|
-
expect(
|
|
1280
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1281
|
-
).toEqual([["a", "b"]]);
|
|
1282
|
-
});
|
|
1283
|
-
test("Should group items into 1 groups when size is 2 and step is 3 and array size is 2", async () => {
|
|
1284
|
-
const collection = new AsyncIterableCollection(["a", "b"]),
|
|
1285
|
-
newCollection = collection.sliding({ chunkSize: 3, step: 2 });
|
|
1286
|
-
expect(
|
|
1287
|
-
await newCollection.map((item) => item.toArray()).toArray(),
|
|
1288
|
-
).toEqual([["a", "b"]]);
|
|
1289
|
-
});
|
|
1290
|
-
test("Should return empty collection when size is 1", async () => {
|
|
1291
|
-
const collection = new AsyncIterableCollection([
|
|
1292
|
-
"a",
|
|
1293
|
-
"b",
|
|
1294
|
-
"c",
|
|
1295
|
-
"d",
|
|
1296
|
-
"e",
|
|
1297
|
-
"f",
|
|
1298
|
-
"g",
|
|
1299
|
-
"h",
|
|
1300
|
-
]),
|
|
1301
|
-
newCollection = collection.sliding({ chunkSize: 1 });
|
|
1302
|
-
expect(await newCollection.toArray()).toEqual([]);
|
|
1303
|
-
});
|
|
1304
|
-
});
|
|
1305
|
-
describe("method: groupBy", () => {
|
|
1306
|
-
test("Should group by with default map function", async () => {
|
|
1307
|
-
const arr = ["a", "b", "c", "a", "b", "c", "b", "d"],
|
|
1308
|
-
collection = new AsyncIterableCollection(arr),
|
|
1309
|
-
newCollection = collection.groupBy();
|
|
1310
|
-
expect(
|
|
1311
|
-
await newCollection
|
|
1312
|
-
.map(
|
|
1313
|
-
async ([key, item]): Promise<
|
|
1314
|
-
RecordItem<string, string[]>
|
|
1315
|
-
> => [key, await item.toArray()],
|
|
1316
|
-
)
|
|
1317
|
-
.toArray(),
|
|
1318
|
-
).toEqual([
|
|
1319
|
-
["a", arr.filter((item) => item === "a")],
|
|
1320
|
-
["b", arr.filter((item) => item === "b")],
|
|
1321
|
-
["c", arr.filter((item) => item === "c")],
|
|
1322
|
-
["d", arr.filter((item) => item === "d")],
|
|
1323
|
-
]);
|
|
1324
|
-
});
|
|
1325
|
-
test("Should group by with custom map function", async () => {
|
|
1326
|
-
type Person = {
|
|
1327
|
-
name: string;
|
|
1328
|
-
age: number;
|
|
1329
|
-
};
|
|
1330
|
-
const arr: Person[] = [
|
|
1331
|
-
{
|
|
1332
|
-
name: "Abra",
|
|
1333
|
-
age: 20,
|
|
1334
|
-
},
|
|
1335
|
-
{
|
|
1336
|
-
name: "Asmail",
|
|
1337
|
-
age: 34,
|
|
1338
|
-
},
|
|
1339
|
-
{
|
|
1340
|
-
name: "Ibra",
|
|
1341
|
-
age: 50,
|
|
1342
|
-
},
|
|
1343
|
-
{
|
|
1344
|
-
name: "Asmail",
|
|
1345
|
-
age: 21,
|
|
1346
|
-
},
|
|
1347
|
-
{
|
|
1348
|
-
name: "Abra",
|
|
1349
|
-
age: 32,
|
|
1350
|
-
},
|
|
1351
|
-
{
|
|
1352
|
-
name: "Abra",
|
|
1353
|
-
age: 67,
|
|
1354
|
-
},
|
|
1355
|
-
],
|
|
1356
|
-
collection = new AsyncIterableCollection<Person>(arr),
|
|
1357
|
-
newCollection = collection.groupBy({
|
|
1358
|
-
mapFn(item) {
|
|
1359
|
-
return item.name;
|
|
1360
|
-
},
|
|
1361
|
-
});
|
|
1362
|
-
expect(
|
|
1363
|
-
await newCollection
|
|
1364
|
-
.map(
|
|
1365
|
-
async ([key, item]): Promise<
|
|
1366
|
-
RecordItem<string, Person[]>
|
|
1367
|
-
> => [key, await item.toArray()],
|
|
1368
|
-
)
|
|
1369
|
-
.toArray(),
|
|
1370
|
-
).toEqual([
|
|
1371
|
-
["Abra", arr.filter((item) => item.name === "Abra")],
|
|
1372
|
-
["Asmail", arr.filter((item) => item.name === "Asmail")],
|
|
1373
|
-
["Ibra", arr.filter((item) => item.name === "Ibra")],
|
|
1374
|
-
]);
|
|
1375
|
-
});
|
|
1376
|
-
test("Should input correct indexes to filter function", async () => {
|
|
1377
|
-
const collection = new AsyncIterableCollection([
|
|
1378
|
-
"a",
|
|
1379
|
-
"b",
|
|
1380
|
-
"c",
|
|
1381
|
-
"a",
|
|
1382
|
-
"b",
|
|
1383
|
-
"c",
|
|
1384
|
-
"b",
|
|
1385
|
-
"d",
|
|
1386
|
-
]),
|
|
1387
|
-
indexes: number[] = [];
|
|
1388
|
-
await collection
|
|
1389
|
-
.groupBy({
|
|
1390
|
-
mapFn: (item, index) => {
|
|
1391
|
-
indexes.push(index);
|
|
1392
|
-
return item;
|
|
1393
|
-
},
|
|
1394
|
-
})
|
|
1395
|
-
.toArray();
|
|
1396
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4, 5, 6, 7]);
|
|
1397
|
-
});
|
|
1398
|
-
test("Should work with async map function", async () => {
|
|
1399
|
-
type Person = {
|
|
1400
|
-
name: string;
|
|
1401
|
-
age: number;
|
|
1402
|
-
};
|
|
1403
|
-
const arr: Person[] = [
|
|
1404
|
-
{
|
|
1405
|
-
name: "Abra",
|
|
1406
|
-
age: 20,
|
|
1407
|
-
},
|
|
1408
|
-
{
|
|
1409
|
-
name: "Asmail",
|
|
1410
|
-
age: 34,
|
|
1411
|
-
},
|
|
1412
|
-
{
|
|
1413
|
-
name: "Ibra",
|
|
1414
|
-
age: 50,
|
|
1415
|
-
},
|
|
1416
|
-
{
|
|
1417
|
-
name: "Asmail",
|
|
1418
|
-
age: 21,
|
|
1419
|
-
},
|
|
1420
|
-
{
|
|
1421
|
-
name: "Abra",
|
|
1422
|
-
age: 32,
|
|
1423
|
-
},
|
|
1424
|
-
{
|
|
1425
|
-
name: "Abra",
|
|
1426
|
-
age: 67,
|
|
1427
|
-
},
|
|
1428
|
-
],
|
|
1429
|
-
collection = new AsyncIterableCollection<Person>(arr),
|
|
1430
|
-
newCollection = collection.groupBy({
|
|
1431
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1432
|
-
mapFn: async (item) => {
|
|
1433
|
-
return item.name;
|
|
1434
|
-
},
|
|
1435
|
-
});
|
|
1436
|
-
expect(
|
|
1437
|
-
await newCollection
|
|
1438
|
-
.map(
|
|
1439
|
-
async ([key, item]): Promise<
|
|
1440
|
-
RecordItem<string, Person[]>
|
|
1441
|
-
> => [key, await item.toArray()],
|
|
1442
|
-
)
|
|
1443
|
-
.toArray(),
|
|
1444
|
-
).toEqual([
|
|
1445
|
-
["Abra", arr.filter((item) => item.name === "Abra")],
|
|
1446
|
-
["Asmail", arr.filter((item) => item.name === "Asmail")],
|
|
1447
|
-
["Ibra", arr.filter((item) => item.name === "Ibra")],
|
|
1448
|
-
]);
|
|
1449
|
-
});
|
|
1450
|
-
});
|
|
1451
|
-
describe("method: countBy", () => {
|
|
1452
|
-
test("Should count by with default map function", async () => {
|
|
1453
|
-
const arr = ["a", "b", "c", "a", "b", "c", "b", "d"],
|
|
1454
|
-
collection = new AsyncIterableCollection(arr),
|
|
1455
|
-
newCollection = collection.countBy();
|
|
1456
|
-
expect(await newCollection.toArray()).toEqual([
|
|
1457
|
-
["a", arr.filter((item) => item === "a").length],
|
|
1458
|
-
["b", arr.filter((item) => item === "b").length],
|
|
1459
|
-
["c", arr.filter((item) => item === "c").length],
|
|
1460
|
-
["d", arr.filter((item) => item === "d").length],
|
|
1461
|
-
]);
|
|
1462
|
-
});
|
|
1463
|
-
test("Should count by with custom map function", async () => {
|
|
1464
|
-
type Person = {
|
|
1465
|
-
name: string;
|
|
1466
|
-
age: number;
|
|
1467
|
-
};
|
|
1468
|
-
const arr: Person[] = [
|
|
1469
|
-
{
|
|
1470
|
-
name: "Abra",
|
|
1471
|
-
age: 20,
|
|
1472
|
-
},
|
|
1473
|
-
{
|
|
1474
|
-
name: "Asmail",
|
|
1475
|
-
age: 34,
|
|
1476
|
-
},
|
|
1477
|
-
{
|
|
1478
|
-
name: "Ibra",
|
|
1479
|
-
age: 50,
|
|
1480
|
-
},
|
|
1481
|
-
{
|
|
1482
|
-
name: "Asmail",
|
|
1483
|
-
age: 21,
|
|
1484
|
-
},
|
|
1485
|
-
{
|
|
1486
|
-
name: "Abra",
|
|
1487
|
-
age: 32,
|
|
1488
|
-
},
|
|
1489
|
-
{
|
|
1490
|
-
name: "Abra",
|
|
1491
|
-
age: 67,
|
|
1492
|
-
},
|
|
1493
|
-
],
|
|
1494
|
-
collection = new AsyncIterableCollection<Person>(arr),
|
|
1495
|
-
newCollection = collection.countBy({
|
|
1496
|
-
mapFn(item) {
|
|
1497
|
-
return item.name;
|
|
1498
|
-
},
|
|
1499
|
-
});
|
|
1500
|
-
expect(await newCollection.toArray()).toEqual([
|
|
1501
|
-
["Abra", arr.filter((item) => item.name === "Abra").length],
|
|
1502
|
-
["Asmail", arr.filter((item) => item.name === "Asmail").length],
|
|
1503
|
-
["Ibra", arr.filter((item) => item.name === "Ibra").length],
|
|
1504
|
-
]);
|
|
1505
|
-
});
|
|
1506
|
-
test("Should input correct indexes to filter function", async () => {
|
|
1507
|
-
const collection = new AsyncIterableCollection([
|
|
1508
|
-
"a",
|
|
1509
|
-
"b",
|
|
1510
|
-
"c",
|
|
1511
|
-
"a",
|
|
1512
|
-
"b",
|
|
1513
|
-
"c",
|
|
1514
|
-
"b",
|
|
1515
|
-
"d",
|
|
1516
|
-
]),
|
|
1517
|
-
indexes: number[] = [];
|
|
1518
|
-
await collection
|
|
1519
|
-
.countBy({
|
|
1520
|
-
mapFn: (item, index) => {
|
|
1521
|
-
indexes.push(index);
|
|
1522
|
-
return item;
|
|
1523
|
-
},
|
|
1524
|
-
})
|
|
1525
|
-
.toArray();
|
|
1526
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4, 5, 6, 7]);
|
|
1527
|
-
});
|
|
1528
|
-
});
|
|
1529
|
-
describe("method: unique", () => {
|
|
1530
|
-
test("Should return unique items with default map function", async () => {
|
|
1531
|
-
const collection = new AsyncIterableCollection([
|
|
1532
|
-
"a",
|
|
1533
|
-
"b",
|
|
1534
|
-
"c",
|
|
1535
|
-
"a",
|
|
1536
|
-
"b",
|
|
1537
|
-
"c",
|
|
1538
|
-
]),
|
|
1539
|
-
newCollection = collection.unique();
|
|
1540
|
-
expect(await newCollection.toArray()).toEqual(["a", "b", "c"]);
|
|
1541
|
-
});
|
|
1542
|
-
test("Should return unique items with custom map function", async () => {
|
|
1543
|
-
const collection = new AsyncIterableCollection([
|
|
1544
|
-
"a",
|
|
1545
|
-
"bb",
|
|
1546
|
-
"cc",
|
|
1547
|
-
"acc",
|
|
1548
|
-
"b",
|
|
1549
|
-
"cccc",
|
|
1550
|
-
]),
|
|
1551
|
-
newCollection = collection.unique({
|
|
1552
|
-
mapFn(item) {
|
|
1553
|
-
return item.length;
|
|
1554
|
-
},
|
|
1555
|
-
});
|
|
1556
|
-
expect(await newCollection.toArray()).toEqual([
|
|
1557
|
-
"a",
|
|
1558
|
-
"bb",
|
|
1559
|
-
"acc",
|
|
1560
|
-
"cccc",
|
|
1561
|
-
]);
|
|
1562
|
-
});
|
|
1563
|
-
test("Should input correct indexes to filter function", async () => {
|
|
1564
|
-
const collection = new AsyncIterableCollection([
|
|
1565
|
-
"a",
|
|
1566
|
-
"b",
|
|
1567
|
-
"c",
|
|
1568
|
-
"a",
|
|
1569
|
-
"b",
|
|
1570
|
-
"c",
|
|
1571
|
-
"b",
|
|
1572
|
-
"d",
|
|
1573
|
-
]),
|
|
1574
|
-
indexes: number[] = [];
|
|
1575
|
-
await collection
|
|
1576
|
-
.unique({
|
|
1577
|
-
mapFn: (item, index) => {
|
|
1578
|
-
indexes.push(index);
|
|
1579
|
-
return item;
|
|
1580
|
-
},
|
|
1581
|
-
})
|
|
1582
|
-
.toArray();
|
|
1583
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4, 5, 6, 7]);
|
|
1584
|
-
});
|
|
1585
|
-
test("Should work with async filter function", async () => {
|
|
1586
|
-
const collection = new AsyncIterableCollection([
|
|
1587
|
-
"a",
|
|
1588
|
-
"bb",
|
|
1589
|
-
"cc",
|
|
1590
|
-
"acc",
|
|
1591
|
-
"b",
|
|
1592
|
-
"cccc",
|
|
1593
|
-
]),
|
|
1594
|
-
newCollection = collection.unique({
|
|
1595
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1596
|
-
mapFn: async (item) => {
|
|
1597
|
-
return item.length;
|
|
1598
|
-
},
|
|
1599
|
-
});
|
|
1600
|
-
expect(await newCollection.toArray()).toEqual([
|
|
1601
|
-
"a",
|
|
1602
|
-
"bb",
|
|
1603
|
-
"acc",
|
|
1604
|
-
"cccc",
|
|
1605
|
-
]);
|
|
1606
|
-
});
|
|
1607
|
-
});
|
|
1608
|
-
describe("method: difference", () => {
|
|
1609
|
-
test("Should remove all elements matches the given Iterable", async () => {
|
|
1610
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
1611
|
-
const difference = collection.difference([2, 4, 6, 8]);
|
|
1612
|
-
expect(await difference.toArray()).toEqual([1, 3, 5]);
|
|
1613
|
-
});
|
|
1614
|
-
test("Should remove all elements matches the given AsyncIterable", async () => {
|
|
1615
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
1616
|
-
const asyncIterable: AsyncIterable<number> = {
|
|
1617
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1618
|
-
async *[Symbol.asyncIterator](): AsyncIterator<number> {
|
|
1619
|
-
yield 2;
|
|
1620
|
-
yield 4;
|
|
1621
|
-
yield 6;
|
|
1622
|
-
yield 8;
|
|
1623
|
-
},
|
|
1624
|
-
};
|
|
1625
|
-
const difference = collection.difference(asyncIterable);
|
|
1626
|
-
expect(await difference.toArray()).toEqual([1, 3, 5]);
|
|
1627
|
-
});
|
|
1628
|
-
});
|
|
1629
|
-
describe("method: repeat", () => {
|
|
1630
|
-
test("Should repeath all elements 2 times when input is 3", async () => {
|
|
1631
|
-
const arr = [1, 2, 3];
|
|
1632
|
-
const collection = new AsyncIterableCollection(arr);
|
|
1633
|
-
const newCollection = collection.repeat(4);
|
|
1634
|
-
expect(await newCollection.toArray()).toEqual([
|
|
1635
|
-
...arr,
|
|
1636
|
-
...arr,
|
|
1637
|
-
...arr,
|
|
1638
|
-
]);
|
|
1639
|
-
});
|
|
1640
|
-
});
|
|
1641
|
-
describe("method: padStart", () => {
|
|
1642
|
-
test(`Should retuern "foofoofabc" when maxLength is 10 and fillItems "foo"`, async () => {
|
|
1643
|
-
const result = await new AsyncIterableCollection("abc")
|
|
1644
|
-
.padStart(10, "foo")
|
|
1645
|
-
.join({
|
|
1646
|
-
seperator: "",
|
|
1647
|
-
});
|
|
1648
|
-
expect(result).toBe("foofoofabc");
|
|
1649
|
-
});
|
|
1650
|
-
test(`Should retuern "123abc" when maxLength is 6 and fillItems "abc"`, async () => {
|
|
1651
|
-
const result = await new AsyncIterableCollection("abc")
|
|
1652
|
-
.padStart(6, "123465")
|
|
1653
|
-
.join({ seperator: "" });
|
|
1654
|
-
expect(result).toBe("123abc");
|
|
1655
|
-
});
|
|
1656
|
-
test(`Should retuern "00000abc" when maxLength is 8 and fillItems "00000abc"`, async () => {
|
|
1657
|
-
const result = await new AsyncIterableCollection("abc")
|
|
1658
|
-
.padStart(8, "0")
|
|
1659
|
-
.join({ seperator: "" });
|
|
1660
|
-
expect(result).toBe("00000abc");
|
|
1661
|
-
});
|
|
1662
|
-
test(`Should retuern "abc" when maxLength is 1 and fillItems "_"`, async () => {
|
|
1663
|
-
const result = await new AsyncIterableCollection("abc")
|
|
1664
|
-
.padStart(1, "_")
|
|
1665
|
-
.join({ seperator: "" });
|
|
1666
|
-
expect(result).toBe("abc");
|
|
1667
|
-
});
|
|
1668
|
-
test("Should work with AsyncIterable", async () => {
|
|
1669
|
-
const asyncIterable: AsyncIterable<string> = {
|
|
1670
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1671
|
-
async *[Symbol.asyncIterator](): AsyncIterator<string> {
|
|
1672
|
-
yield "f";
|
|
1673
|
-
yield "o";
|
|
1674
|
-
yield "o";
|
|
1675
|
-
},
|
|
1676
|
-
};
|
|
1677
|
-
const result = await new AsyncIterableCollection("abc")
|
|
1678
|
-
.padStart(10, asyncIterable)
|
|
1679
|
-
.join({
|
|
1680
|
-
seperator: "",
|
|
1681
|
-
});
|
|
1682
|
-
expect(result).toBe("foofoofabc");
|
|
1683
|
-
});
|
|
1684
|
-
});
|
|
1685
|
-
describe("method: padEnd", () => {
|
|
1686
|
-
test(`Should retuern "abcfoofoof" when maxLength is 10 and fillItems "foo"`, async () => {
|
|
1687
|
-
const result = await new AsyncIterableCollection("abc")
|
|
1688
|
-
.padEnd(10, "foo")
|
|
1689
|
-
.join({
|
|
1690
|
-
seperator: "",
|
|
1691
|
-
});
|
|
1692
|
-
expect(result).toBe("abcfoofoof");
|
|
1693
|
-
});
|
|
1694
|
-
test(`Should retuern "abc123" when maxLength is 6 and fillItems "abc"`, async () => {
|
|
1695
|
-
const result = await new AsyncIterableCollection("abc")
|
|
1696
|
-
.padEnd(6, "123465")
|
|
1697
|
-
.join({ seperator: "" });
|
|
1698
|
-
expect(result).toBe("abc123");
|
|
1699
|
-
});
|
|
1700
|
-
test(`Should retuern "abc00000" when maxLength is 8 and fillItems "00000abc"`, async () => {
|
|
1701
|
-
const result = await new AsyncIterableCollection("abc")
|
|
1702
|
-
.padEnd(8, "0")
|
|
1703
|
-
.join({ seperator: "" });
|
|
1704
|
-
expect(result).toBe("abc00000");
|
|
1705
|
-
});
|
|
1706
|
-
test(`Should retuern "abc" when maxLength is 1 and fillItems "_"`, async () => {
|
|
1707
|
-
const result = await new AsyncIterableCollection("abc")
|
|
1708
|
-
.padEnd(1, "_")
|
|
1709
|
-
.join({ seperator: "" });
|
|
1710
|
-
expect(result).toBe("abc");
|
|
1711
|
-
});
|
|
1712
|
-
test("Should work with AsyncIterable", async () => {
|
|
1713
|
-
const asyncIterable: AsyncIterable<string> = {
|
|
1714
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1715
|
-
async *[Symbol.asyncIterator](): AsyncIterator<string> {
|
|
1716
|
-
yield "f";
|
|
1717
|
-
yield "o";
|
|
1718
|
-
yield "o";
|
|
1719
|
-
},
|
|
1720
|
-
};
|
|
1721
|
-
const result = await new AsyncIterableCollection("abc")
|
|
1722
|
-
.padEnd(10, asyncIterable)
|
|
1723
|
-
.join({
|
|
1724
|
-
seperator: "",
|
|
1725
|
-
});
|
|
1726
|
-
expect(result).toBe("abcfoofoof");
|
|
1727
|
-
});
|
|
1728
|
-
});
|
|
1729
|
-
describe("method: slice", () => {
|
|
1730
|
-
test("Should return [1] when start is 0, end is 1 and array is [1, 2, 3, 4, 5]", async () => {
|
|
1731
|
-
const arr = [1, 2, 3, 4, 5];
|
|
1732
|
-
const collection = new AsyncIterableCollection(arr);
|
|
1733
|
-
const newCollection = collection.slice({ start: 0, end: 1 });
|
|
1734
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(0, 1));
|
|
1735
|
-
});
|
|
1736
|
-
test("Should return [4, 5] when start is -2 and array is [1, 2, 3, 4, 5]", async () => {
|
|
1737
|
-
const arr = [1, 2, 3, 4, 5];
|
|
1738
|
-
const collection = new AsyncIterableCollection(arr);
|
|
1739
|
-
const newCollection = collection.slice({ start: -2 });
|
|
1740
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(-2));
|
|
1741
|
-
});
|
|
1742
|
-
test("Should return [1, 2, 3, 4] when start is 0, end is -1 and array is [1, 2, 3, 4, 5]", async () => {
|
|
1743
|
-
const arr = [1, 2, 3, 4, 5];
|
|
1744
|
-
const collection = new AsyncIterableCollection(arr);
|
|
1745
|
-
const newCollection = collection.slice({ start: 0, end: -1 });
|
|
1746
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(0, -1));
|
|
1747
|
-
});
|
|
1748
|
-
test("Should return [3, 4] when start is 2, end is -1 and array is [1, 2, 3, 4, 5]", async () => {
|
|
1749
|
-
const arr = [1, 2, 3, 4, 5];
|
|
1750
|
-
const collection = new AsyncIterableCollection(arr);
|
|
1751
|
-
const newCollection = collection.slice({ start: 2, end: -1 });
|
|
1752
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(2, -1));
|
|
1753
|
-
});
|
|
1754
|
-
test("Should return [2, 3, 4] when start is 1, end is 4 and array is [1, 2, 3, 4, 5]", async () => {
|
|
1755
|
-
const arr = [1, 2, 3, 4, 5];
|
|
1756
|
-
const collection = new AsyncIterableCollection(arr);
|
|
1757
|
-
const newCollection = collection.slice({ start: 1, end: 4 });
|
|
1758
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(1, 4));
|
|
1759
|
-
});
|
|
1760
|
-
test("Should return [3, 4] when start is 2, end is 4 and array is [1, 2, 3, 4, 5]", async () => {
|
|
1761
|
-
const arr = [1, 2, 3, 4, 5];
|
|
1762
|
-
const collection = new AsyncIterableCollection(arr);
|
|
1763
|
-
const newCollection = collection.slice({ start: 2, end: 4 });
|
|
1764
|
-
expect(await newCollection.toArray()).toEqual(arr.slice(2, 4));
|
|
1765
|
-
});
|
|
1766
|
-
});
|
|
1767
|
-
describe("method: prepend", () => {
|
|
1768
|
-
test("Should prepend Iterable", async () => {
|
|
1769
|
-
const arr1 = ["a", "b", "c"],
|
|
1770
|
-
collection = new AsyncIterableCollection(arr1),
|
|
1771
|
-
arr2 = [1, 2, 3],
|
|
1772
|
-
prependedCollection = collection.prepend(arr2);
|
|
1773
|
-
expect(await prependedCollection.toArray()).toEqual([
|
|
1774
|
-
...arr2,
|
|
1775
|
-
...arr1,
|
|
1776
|
-
]);
|
|
1777
|
-
});
|
|
1778
|
-
test("Should prepend AsyncIterable", async () => {
|
|
1779
|
-
const arr1 = ["a", "b", "c"],
|
|
1780
|
-
collection = new AsyncIterableCollection(arr1),
|
|
1781
|
-
arr2 = [1, 2, 3];
|
|
1782
|
-
const asyncIterable: AsyncIterable<number> = {
|
|
1783
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1784
|
-
async *[Symbol.asyncIterator](): AsyncIterator<number> {
|
|
1785
|
-
yield* arr2;
|
|
1786
|
-
},
|
|
1787
|
-
};
|
|
1788
|
-
const prependedCollection = collection.prepend(asyncIterable);
|
|
1789
|
-
expect(await prependedCollection.toArray()).toEqual([
|
|
1790
|
-
...arr2,
|
|
1791
|
-
...arr1,
|
|
1792
|
-
]);
|
|
1793
|
-
});
|
|
1794
|
-
});
|
|
1795
|
-
describe("method: append", () => {
|
|
1796
|
-
test("Should append Iterable", async () => {
|
|
1797
|
-
const arr1 = ["a", "b", "c"],
|
|
1798
|
-
collection = new AsyncIterableCollection(arr1),
|
|
1799
|
-
arr2 = [1, 2, 3],
|
|
1800
|
-
appendedCollection = collection.append(arr2);
|
|
1801
|
-
expect(await appendedCollection.toArray()).toEqual([
|
|
1802
|
-
...arr1,
|
|
1803
|
-
...arr2,
|
|
1804
|
-
]);
|
|
1805
|
-
});
|
|
1806
|
-
test("Should append AsyncIterable", async () => {
|
|
1807
|
-
const arr1 = ["a", "b", "c"],
|
|
1808
|
-
collection = new AsyncIterableCollection(arr1),
|
|
1809
|
-
arr2 = [1, 2, 3];
|
|
1810
|
-
const asyncIterable: AsyncIterable<number> = {
|
|
1811
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1812
|
-
async *[Symbol.asyncIterator](): AsyncIterator<number> {
|
|
1813
|
-
yield* arr2;
|
|
1814
|
-
},
|
|
1815
|
-
};
|
|
1816
|
-
const appendedCollection = collection.append(asyncIterable);
|
|
1817
|
-
expect(await appendedCollection.toArray()).toEqual([
|
|
1818
|
-
...arr1,
|
|
1819
|
-
...arr2,
|
|
1820
|
-
]);
|
|
1821
|
-
});
|
|
1822
|
-
});
|
|
1823
|
-
describe("method: insertBefore", () => {
|
|
1824
|
-
test("Should insert Iterable before first item", async () => {
|
|
1825
|
-
const arr1 = ["a", "b", "c"],
|
|
1826
|
-
collection = new AsyncIterableCollection(arr1),
|
|
1827
|
-
arr2 = [1, 2, 3],
|
|
1828
|
-
newCollection = collection.insertBefore(
|
|
1829
|
-
(item) => item === "a",
|
|
1830
|
-
arr2,
|
|
1831
|
-
);
|
|
1832
|
-
expect(await newCollection.toArray()).toEqual([...arr2, ...arr1]);
|
|
1833
|
-
});
|
|
1834
|
-
test("Should insert Iterable before last item", async () => {
|
|
1835
|
-
const arr1 = ["a", "b", "c"],
|
|
1836
|
-
collection = new AsyncIterableCollection(arr1),
|
|
1837
|
-
arr2 = [1, 2, 3],
|
|
1838
|
-
newCollection = collection.insertBefore(
|
|
1839
|
-
(item) => item === "c",
|
|
1840
|
-
arr2,
|
|
1841
|
-
);
|
|
1842
|
-
expect(await newCollection.toArray()).toEqual([
|
|
1843
|
-
...arr1.slice(0, -1),
|
|
1844
|
-
...arr2,
|
|
1845
|
-
...arr1.slice(-1),
|
|
1846
|
-
]);
|
|
1847
|
-
});
|
|
1848
|
-
test("Should not insert Iterable if filter item not found", async () => {
|
|
1849
|
-
const arr1 = ["a", "b", "c"],
|
|
1850
|
-
collection = new AsyncIterableCollection(arr1),
|
|
1851
|
-
arr2 = [1, 2, 3],
|
|
1852
|
-
newCollection = collection.insertBefore(
|
|
1853
|
-
(item) => item === "d",
|
|
1854
|
-
arr2,
|
|
1855
|
-
);
|
|
1856
|
-
expect(await newCollection.toArray()).toEqual(arr1);
|
|
1857
|
-
});
|
|
1858
|
-
test("Should insert AsyncIterable before first item", async () => {
|
|
1859
|
-
const arr1 = ["a", "b", "c"],
|
|
1860
|
-
collection = new AsyncIterableCollection(arr1),
|
|
1861
|
-
arr2 = [1, 2, 3];
|
|
1862
|
-
const asyncIterable: AsyncIterable<number> = {
|
|
1863
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1864
|
-
async *[Symbol.asyncIterator](): AsyncIterator<number> {
|
|
1865
|
-
yield* arr2;
|
|
1866
|
-
},
|
|
1867
|
-
};
|
|
1868
|
-
const newCollection = collection.insertBefore(
|
|
1869
|
-
(item) => item === "a",
|
|
1870
|
-
asyncIterable,
|
|
1871
|
-
);
|
|
1872
|
-
expect(await newCollection.toArray()).toEqual([...arr2, ...arr1]);
|
|
1873
|
-
});
|
|
1874
|
-
});
|
|
1875
|
-
describe("method: insertAfter", () => {
|
|
1876
|
-
test("Should insert Iterable after last item", async () => {
|
|
1877
|
-
const arr1 = ["a", "b", "c"],
|
|
1878
|
-
collection = new AsyncIterableCollection(arr1),
|
|
1879
|
-
arr2 = [1, 2, 3],
|
|
1880
|
-
newCollection = collection.insertAfter(
|
|
1881
|
-
(item) => item === "c",
|
|
1882
|
-
arr2,
|
|
1883
|
-
);
|
|
1884
|
-
expect(await newCollection.toArray()).toEqual([...arr1, ...arr2]);
|
|
1885
|
-
});
|
|
1886
|
-
test("Should insert Iterable after first item", async () => {
|
|
1887
|
-
const arr1 = ["a", "b", "c"],
|
|
1888
|
-
collection = new AsyncIterableCollection(arr1),
|
|
1889
|
-
arr2 = [1, 2, 3],
|
|
1890
|
-
newCollection = collection.insertAfter(
|
|
1891
|
-
(item) => item === "a",
|
|
1892
|
-
arr2,
|
|
1893
|
-
);
|
|
1894
|
-
expect(await newCollection.toArray()).toEqual([
|
|
1895
|
-
...arr1.slice(0, 1),
|
|
1896
|
-
...arr2,
|
|
1897
|
-
...arr1.slice(-2),
|
|
1898
|
-
]);
|
|
1899
|
-
});
|
|
1900
|
-
test("Should not insert Iterable if filter item not found", async () => {
|
|
1901
|
-
const arr1 = ["a", "b", "c"],
|
|
1902
|
-
collection = new AsyncIterableCollection(arr1),
|
|
1903
|
-
arr2 = [1, 2, 3],
|
|
1904
|
-
newCollection = collection.insertAfter(
|
|
1905
|
-
(item) => item === "d",
|
|
1906
|
-
arr2,
|
|
1907
|
-
);
|
|
1908
|
-
expect(await newCollection.toArray()).toEqual(arr1);
|
|
1909
|
-
});
|
|
1910
|
-
test("Should insert AsyncIterable after last item", async () => {
|
|
1911
|
-
const arr1 = ["a", "b", "c"],
|
|
1912
|
-
collection = new AsyncIterableCollection(arr1),
|
|
1913
|
-
arr2 = [1, 2, 3];
|
|
1914
|
-
const asyncIterable: AsyncIterable<number> = {
|
|
1915
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1916
|
-
async *[Symbol.asyncIterator](): AsyncIterator<number> {
|
|
1917
|
-
yield* arr2;
|
|
1918
|
-
},
|
|
1919
|
-
};
|
|
1920
|
-
const newCollection = collection.insertAfter(
|
|
1921
|
-
(item) => item === "c",
|
|
1922
|
-
asyncIterable,
|
|
1923
|
-
);
|
|
1924
|
-
expect(await newCollection.toArray()).toEqual([...arr1, ...arr2]);
|
|
1925
|
-
});
|
|
1926
|
-
});
|
|
1927
|
-
describe("method: crossJoin", () => {
|
|
1928
|
-
test(`Should return 4 combinations when input Iterable is [1, 2] and ["a", "b"]`, async () => {
|
|
1929
|
-
const collection = new AsyncIterableCollection([1, 2]);
|
|
1930
|
-
const matrix = collection.crossJoin(["a", "b"]);
|
|
1931
|
-
|
|
1932
|
-
expect(
|
|
1933
|
-
await matrix
|
|
1934
|
-
.map((collection) => collection.toArray())
|
|
1935
|
-
.toArray(),
|
|
1936
|
-
).toEqual([
|
|
1937
|
-
[1, "a"],
|
|
1938
|
-
[1, "b"],
|
|
1939
|
-
[2, "a"],
|
|
1940
|
-
[2, "b"],
|
|
1941
|
-
]);
|
|
1942
|
-
});
|
|
1943
|
-
test("Should work with AsyncIterables", async () => {
|
|
1944
|
-
const collection = new AsyncIterableCollection([1, 2]);
|
|
1945
|
-
const asyncIterable: AsyncIterable<string> = {
|
|
1946
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1947
|
-
async *[Symbol.asyncIterator](): AsyncIterator<string> {
|
|
1948
|
-
yield "a";
|
|
1949
|
-
yield "b";
|
|
1950
|
-
},
|
|
1951
|
-
};
|
|
1952
|
-
const matrix = collection.crossJoin(asyncIterable);
|
|
1953
|
-
|
|
1954
|
-
expect(
|
|
1955
|
-
await matrix
|
|
1956
|
-
.map((collection) => collection.toArray())
|
|
1957
|
-
.toArray(),
|
|
1958
|
-
).toEqual([
|
|
1959
|
-
[1, "a"],
|
|
1960
|
-
[1, "b"],
|
|
1961
|
-
[2, "a"],
|
|
1962
|
-
[2, "b"],
|
|
1963
|
-
]);
|
|
1964
|
-
});
|
|
1965
|
-
test(`Should return 8 combinations when input Iterable is [1, 2], ["a", "b"] and ["I", "II"]`, async () => {
|
|
1966
|
-
const collection = new AsyncIterableCollection([1, 2]);
|
|
1967
|
-
const matrix = collection.crossJoin(["a", "b"], ["I", "II"]);
|
|
1968
|
-
expect(
|
|
1969
|
-
await matrix
|
|
1970
|
-
.map((collection) => collection.toArray())
|
|
1971
|
-
.toArray(),
|
|
1972
|
-
).toEqual([
|
|
1973
|
-
[1, "a", "I"],
|
|
1974
|
-
[1, "a", "II"],
|
|
1975
|
-
[1, "b", "I"],
|
|
1976
|
-
[1, "b", "II"],
|
|
1977
|
-
[2, "a", "I"],
|
|
1978
|
-
[2, "a", "II"],
|
|
1979
|
-
[2, "b", "I"],
|
|
1980
|
-
[2, "b", "II"],
|
|
1981
|
-
]);
|
|
1982
|
-
});
|
|
1983
|
-
});
|
|
1984
|
-
describe("method: zip", () => {
|
|
1985
|
-
test("Should zip Iterable", async () => {
|
|
1986
|
-
const arr1 = ["a", "b", "c"],
|
|
1987
|
-
collection = new AsyncIterableCollection(arr1),
|
|
1988
|
-
arr2 = [1, 2, 3],
|
|
1989
|
-
newCollection = collection.zip(arr2);
|
|
1990
|
-
expect(await newCollection.toArray()).toEqual([
|
|
1991
|
-
[arr1[0], arr2[0]],
|
|
1992
|
-
[arr1[1], arr2[1]],
|
|
1993
|
-
[arr1[2], arr2[2]],
|
|
1994
|
-
]);
|
|
1995
|
-
});
|
|
1996
|
-
test("Should zip AsyncIterable", async () => {
|
|
1997
|
-
const arr1 = ["a", "b", "c"],
|
|
1998
|
-
collection = new AsyncIterableCollection(arr1),
|
|
1999
|
-
arr2 = [1, 2, 3];
|
|
2000
|
-
const asyncIterable: AsyncIterable<number> = {
|
|
2001
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2002
|
-
async *[Symbol.asyncIterator](): AsyncIterator<number> {
|
|
2003
|
-
yield* arr2;
|
|
2004
|
-
},
|
|
2005
|
-
};
|
|
2006
|
-
const newCollection = collection.zip(asyncIterable);
|
|
2007
|
-
expect(await newCollection.toArray()).toEqual([
|
|
2008
|
-
[arr1[0], arr2[0]],
|
|
2009
|
-
[arr1[1], arr2[1]],
|
|
2010
|
-
[arr1[2], arr2[2]],
|
|
2011
|
-
]);
|
|
2012
|
-
});
|
|
2013
|
-
test("Should have the length of collection", async () => {
|
|
2014
|
-
const arr1 = ["a", "b", "c", "d"],
|
|
2015
|
-
collection = new AsyncIterableCollection(arr1),
|
|
2016
|
-
arr2 = [1, 2, 3],
|
|
2017
|
-
newCollection = collection.zip(arr2);
|
|
2018
|
-
expect(await newCollection.toArray()).toEqual([
|
|
2019
|
-
[arr1[0], arr2[0]],
|
|
2020
|
-
[arr1[1], arr2[1]],
|
|
2021
|
-
[arr1[2], arr2[2]],
|
|
2022
|
-
]);
|
|
2023
|
-
});
|
|
2024
|
-
test("Should have the length of input Iterable", async () => {
|
|
2025
|
-
const arr1 = ["a", "b", "c"],
|
|
2026
|
-
collection = new AsyncIterableCollection(arr1),
|
|
2027
|
-
arr2 = [1, 2, 3, 4],
|
|
2028
|
-
newCollection = collection.zip(arr2);
|
|
2029
|
-
expect(await newCollection.toArray()).toEqual([
|
|
2030
|
-
[arr1[0], arr2[0]],
|
|
2031
|
-
[arr1[1], arr2[1]],
|
|
2032
|
-
[arr1[2], arr2[2]],
|
|
2033
|
-
]);
|
|
2034
|
-
});
|
|
2035
|
-
});
|
|
2036
|
-
describe("method: sort", () => {
|
|
2037
|
-
test("Sort numbers from smallest to largest with custom comparator function", async () => {
|
|
2038
|
-
const arr = [-1, 2, 1, -3, 4, 20, 15, -5, -3],
|
|
2039
|
-
collection = new AsyncIterableCollection(arr),
|
|
2040
|
-
newCollection = collection.sort((a, b) => a - b);
|
|
2041
|
-
expect(await newCollection.toArray()).toEqual(
|
|
2042
|
-
[...arr].sort((a, b) => a - b),
|
|
2043
|
-
);
|
|
2044
|
-
});
|
|
2045
|
-
test("Sort numbers from smallest to largest with default compartor function", async () => {
|
|
2046
|
-
const arr = [-1, 2, 1, -3, 4, 20, 15, -5, -3],
|
|
2047
|
-
collection = new AsyncIterableCollection(arr),
|
|
2048
|
-
newCollection = collection.sort();
|
|
2049
|
-
expect(await newCollection.toArray()).toEqual([...arr].sort());
|
|
2050
|
-
});
|
|
2051
|
-
});
|
|
2052
|
-
describe("method: reverse", () => {
|
|
2053
|
-
test("Should reverse Iterable", async () => {
|
|
2054
|
-
const arr = ["a", "b", "c", "d", "e", "f"],
|
|
2055
|
-
collection = new AsyncIterableCollection(arr),
|
|
2056
|
-
newCollection = collection.reverse();
|
|
2057
|
-
expect(await newCollection.toArray()).toEqual([...arr].reverse());
|
|
2058
|
-
});
|
|
2059
|
-
});
|
|
2060
|
-
describe("method: first", () => {
|
|
2061
|
-
test("Should return first item that matches the filter function", async () => {
|
|
2062
|
-
type Person = {
|
|
2063
|
-
name: string;
|
|
2064
|
-
age: number;
|
|
2065
|
-
};
|
|
2066
|
-
const persons: Person[] = [
|
|
2067
|
-
{
|
|
2068
|
-
name: "Joe",
|
|
2069
|
-
age: 20,
|
|
2070
|
-
},
|
|
2071
|
-
{
|
|
2072
|
-
name: "Jhon",
|
|
2073
|
-
age: 23,
|
|
2074
|
-
},
|
|
2075
|
-
{
|
|
2076
|
-
name: "Joe",
|
|
2077
|
-
age: 30,
|
|
2078
|
-
},
|
|
2079
|
-
{
|
|
2080
|
-
name: "Jhon",
|
|
2081
|
-
age: 50,
|
|
2082
|
-
},
|
|
2083
|
-
],
|
|
2084
|
-
collection = new AsyncIterableCollection(persons),
|
|
2085
|
-
item = await collection.first({
|
|
2086
|
-
filterFn: (person) => person.name === "Joe",
|
|
2087
|
-
});
|
|
2088
|
-
expect(item).toEqual(persons[0]);
|
|
2089
|
-
});
|
|
2090
|
-
test("Should return first item when found", async () => {
|
|
2091
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2092
|
-
item = await collection.first();
|
|
2093
|
-
expect(item).toBe(1);
|
|
2094
|
-
});
|
|
2095
|
-
test("Should return null when item not found", async () => {
|
|
2096
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2097
|
-
item = await collection.first({
|
|
2098
|
-
filterFn: (item) => item === 6,
|
|
2099
|
-
});
|
|
2100
|
-
expect(item).toBe(null);
|
|
2101
|
-
});
|
|
2102
|
-
test("Should input correct indexes to filter function", async () => {
|
|
2103
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2104
|
-
indexes: number[] = [];
|
|
2105
|
-
await collection.first({
|
|
2106
|
-
filterFn: (item, index) => {
|
|
2107
|
-
indexes.push(index);
|
|
2108
|
-
return item === 6;
|
|
2109
|
-
},
|
|
2110
|
-
});
|
|
2111
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4]);
|
|
2112
|
-
});
|
|
2113
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
2114
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
2115
|
-
expect(await collection.first()).toBe(1);
|
|
2116
|
-
expect(await collection.first()).toBe(1);
|
|
2117
|
-
});
|
|
2118
|
-
test("Should work with async filter function", async () => {
|
|
2119
|
-
type Person = {
|
|
2120
|
-
name: string;
|
|
2121
|
-
age: number;
|
|
2122
|
-
};
|
|
2123
|
-
const persons: Person[] = [
|
|
2124
|
-
{
|
|
2125
|
-
name: "Joe",
|
|
2126
|
-
age: 20,
|
|
2127
|
-
},
|
|
2128
|
-
{
|
|
2129
|
-
name: "Jhon",
|
|
2130
|
-
age: 23,
|
|
2131
|
-
},
|
|
2132
|
-
{
|
|
2133
|
-
name: "Joe",
|
|
2134
|
-
age: 30,
|
|
2135
|
-
},
|
|
2136
|
-
{
|
|
2137
|
-
name: "Jhon",
|
|
2138
|
-
age: 50,
|
|
2139
|
-
},
|
|
2140
|
-
],
|
|
2141
|
-
collection = new AsyncIterableCollection(persons),
|
|
2142
|
-
item = await collection.first({
|
|
2143
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2144
|
-
filterFn: async (person) => person.name === "Joe",
|
|
2145
|
-
});
|
|
2146
|
-
expect(item).toEqual(persons[0]);
|
|
2147
|
-
});
|
|
2148
|
-
});
|
|
2149
|
-
describe("method: firstOr", () => {
|
|
2150
|
-
test("Should return first item that matches the filter function", async () => {
|
|
2151
|
-
type Person = {
|
|
2152
|
-
name: string;
|
|
2153
|
-
age: number;
|
|
2154
|
-
};
|
|
2155
|
-
const persons: Person[] = [
|
|
2156
|
-
{
|
|
2157
|
-
name: "Joe",
|
|
2158
|
-
age: 20,
|
|
2159
|
-
},
|
|
2160
|
-
{
|
|
2161
|
-
name: "Jhon",
|
|
2162
|
-
age: 23,
|
|
2163
|
-
},
|
|
2164
|
-
{
|
|
2165
|
-
name: "Joe",
|
|
2166
|
-
age: 30,
|
|
2167
|
-
},
|
|
2168
|
-
{
|
|
2169
|
-
name: "Jhon",
|
|
2170
|
-
age: 50,
|
|
2171
|
-
},
|
|
2172
|
-
],
|
|
2173
|
-
collection = new AsyncIterableCollection(persons),
|
|
2174
|
-
item = await collection.firstOr({
|
|
2175
|
-
defaultValue: null,
|
|
2176
|
-
filterFn: (person) => person.name === "Joe",
|
|
2177
|
-
});
|
|
2178
|
-
expect(item).toEqual(persons[0]);
|
|
2179
|
-
});
|
|
2180
|
-
test("Should return first item when found", async () => {
|
|
2181
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2182
|
-
item = await collection.firstOr({
|
|
2183
|
-
defaultValue: "a",
|
|
2184
|
-
});
|
|
2185
|
-
expect(item).toBe(1);
|
|
2186
|
-
});
|
|
2187
|
-
test("Should return default value when item not found", async () => {
|
|
2188
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2189
|
-
item = await collection.firstOr({
|
|
2190
|
-
defaultValue: "a",
|
|
2191
|
-
filterFn: (item) => item === 6,
|
|
2192
|
-
});
|
|
2193
|
-
expect(item).toBe("a");
|
|
2194
|
-
});
|
|
2195
|
-
test("Should input correct indexes to filter function", async () => {
|
|
2196
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2197
|
-
indexes: number[] = [];
|
|
2198
|
-
await collection.firstOr({
|
|
2199
|
-
defaultValue: null,
|
|
2200
|
-
filterFn: (item, index) => {
|
|
2201
|
-
indexes.push(index);
|
|
2202
|
-
return item === 6;
|
|
2203
|
-
},
|
|
2204
|
-
});
|
|
2205
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4]);
|
|
2206
|
-
});
|
|
2207
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
2208
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
2209
|
-
expect(
|
|
2210
|
-
await collection.firstOr({
|
|
2211
|
-
defaultValue: "a",
|
|
2212
|
-
}),
|
|
2213
|
-
).toBe(1);
|
|
2214
|
-
expect(
|
|
2215
|
-
await collection.firstOr({
|
|
2216
|
-
defaultValue: "a",
|
|
2217
|
-
}),
|
|
2218
|
-
).toBe(1);
|
|
2219
|
-
});
|
|
2220
|
-
test("Should work with async filter function", async () => {
|
|
2221
|
-
type Person = {
|
|
2222
|
-
name: string;
|
|
2223
|
-
age: number;
|
|
2224
|
-
};
|
|
2225
|
-
const persons: Person[] = [
|
|
2226
|
-
{
|
|
2227
|
-
name: "Joe",
|
|
2228
|
-
age: 20,
|
|
2229
|
-
},
|
|
2230
|
-
{
|
|
2231
|
-
name: "Jhon",
|
|
2232
|
-
age: 23,
|
|
2233
|
-
},
|
|
2234
|
-
{
|
|
2235
|
-
name: "Joe",
|
|
2236
|
-
age: 30,
|
|
2237
|
-
},
|
|
2238
|
-
{
|
|
2239
|
-
name: "Jhon",
|
|
2240
|
-
age: 50,
|
|
2241
|
-
},
|
|
2242
|
-
],
|
|
2243
|
-
collection = new AsyncIterableCollection(persons),
|
|
2244
|
-
item = await collection.firstOr({
|
|
2245
|
-
defaultValue: null,
|
|
2246
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2247
|
-
filterFn: async (person) => person.name === "Joe",
|
|
2248
|
-
});
|
|
2249
|
-
expect(item).toEqual(persons[0]);
|
|
2250
|
-
});
|
|
2251
|
-
});
|
|
2252
|
-
describe("method: firstOrFail", () => {
|
|
2253
|
-
test("Should return first item that matches the filter function", async () => {
|
|
2254
|
-
type Person = {
|
|
2255
|
-
name: string;
|
|
2256
|
-
age: number;
|
|
2257
|
-
};
|
|
2258
|
-
const persons: Person[] = [
|
|
2259
|
-
{
|
|
2260
|
-
name: "Joe",
|
|
2261
|
-
age: 20,
|
|
2262
|
-
},
|
|
2263
|
-
{
|
|
2264
|
-
name: "Jhon",
|
|
2265
|
-
age: 23,
|
|
2266
|
-
},
|
|
2267
|
-
{
|
|
2268
|
-
name: "Joe",
|
|
2269
|
-
age: 30,
|
|
2270
|
-
},
|
|
2271
|
-
{
|
|
2272
|
-
name: "Jhon",
|
|
2273
|
-
age: 50,
|
|
2274
|
-
},
|
|
2275
|
-
],
|
|
2276
|
-
collection = new AsyncIterableCollection(persons),
|
|
2277
|
-
item = await collection.firstOrFail({
|
|
2278
|
-
filterFn: (person) => person.name === "Joe",
|
|
2279
|
-
});
|
|
2280
|
-
expect(item).toEqual(persons[0]);
|
|
2281
|
-
});
|
|
2282
|
-
test("Should return first item when found", async () => {
|
|
2283
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2284
|
-
item = await collection.firstOrFail();
|
|
2285
|
-
expect(item).toBe(1);
|
|
2286
|
-
});
|
|
2287
|
-
test("Should throw CollectionError when item not found", async () => {
|
|
2288
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
2289
|
-
await expect(async () => {
|
|
2290
|
-
await collection.firstOrFail({
|
|
2291
|
-
filterFn: (item) => item === 6,
|
|
2292
|
-
});
|
|
2293
|
-
}).rejects.toThrowError(CollectionError);
|
|
2294
|
-
});
|
|
2295
|
-
test("Should throw ItemNotFoundError when item not found", async () => {
|
|
2296
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
2297
|
-
await expect(async () => {
|
|
2298
|
-
await collection.firstOrFail({
|
|
2299
|
-
filterFn: (item) => item === 6,
|
|
2300
|
-
});
|
|
2301
|
-
}).rejects.toThrowError(ItemNotFoundError);
|
|
2302
|
-
});
|
|
2303
|
-
test("Should input correct indexes to filter function", async () => {
|
|
2304
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2305
|
-
indexes: number[] = [];
|
|
2306
|
-
try {
|
|
2307
|
-
await collection.firstOrFail({
|
|
2308
|
-
filterFn: (item, index) => {
|
|
2309
|
-
indexes.push(index);
|
|
2310
|
-
return item === 6;
|
|
2311
|
-
},
|
|
2312
|
-
});
|
|
2313
|
-
} catch {
|
|
2314
|
-
/* Empty */
|
|
2315
|
-
}
|
|
2316
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4]);
|
|
2317
|
-
});
|
|
2318
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
2319
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
2320
|
-
expect(await collection.firstOrFail()).toBe(1);
|
|
2321
|
-
expect(await collection.firstOrFail()).toBe(1);
|
|
2322
|
-
});
|
|
2323
|
-
test("Should work with async filter function", async () => {
|
|
2324
|
-
type Person = {
|
|
2325
|
-
name: string;
|
|
2326
|
-
age: number;
|
|
2327
|
-
};
|
|
2328
|
-
const persons: Person[] = [
|
|
2329
|
-
{
|
|
2330
|
-
name: "Joe",
|
|
2331
|
-
age: 20,
|
|
2332
|
-
},
|
|
2333
|
-
{
|
|
2334
|
-
name: "Jhon",
|
|
2335
|
-
age: 23,
|
|
2336
|
-
},
|
|
2337
|
-
{
|
|
2338
|
-
name: "Joe",
|
|
2339
|
-
age: 30,
|
|
2340
|
-
},
|
|
2341
|
-
{
|
|
2342
|
-
name: "Jhon",
|
|
2343
|
-
age: 50,
|
|
2344
|
-
},
|
|
2345
|
-
],
|
|
2346
|
-
collection = new AsyncIterableCollection(persons),
|
|
2347
|
-
item = await collection.firstOrFail({
|
|
2348
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2349
|
-
filterFn: async (person) => person.name === "Joe",
|
|
2350
|
-
});
|
|
2351
|
-
expect(item).toEqual(persons[0]);
|
|
2352
|
-
});
|
|
2353
|
-
});
|
|
2354
|
-
describe("method: last", () => {
|
|
2355
|
-
test("Should return last item that matches the filter function", async () => {
|
|
2356
|
-
type Person = {
|
|
2357
|
-
name: string;
|
|
2358
|
-
age: number;
|
|
2359
|
-
};
|
|
2360
|
-
const persons: Person[] = [
|
|
2361
|
-
{
|
|
2362
|
-
name: "Joe",
|
|
2363
|
-
age: 20,
|
|
2364
|
-
},
|
|
2365
|
-
{
|
|
2366
|
-
name: "Jhon",
|
|
2367
|
-
age: 23,
|
|
2368
|
-
},
|
|
2369
|
-
{
|
|
2370
|
-
name: "Joe",
|
|
2371
|
-
age: 30,
|
|
2372
|
-
},
|
|
2373
|
-
{
|
|
2374
|
-
name: "Jhon",
|
|
2375
|
-
age: 50,
|
|
2376
|
-
},
|
|
2377
|
-
],
|
|
2378
|
-
collection = new AsyncIterableCollection(persons),
|
|
2379
|
-
item = await collection.last({
|
|
2380
|
-
filterFn: (person) => person.name === "Joe",
|
|
2381
|
-
});
|
|
2382
|
-
expect(item).toEqual(persons[2]);
|
|
2383
|
-
});
|
|
2384
|
-
test("Should return last item when found", async () => {
|
|
2385
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2386
|
-
item = await collection.last();
|
|
2387
|
-
expect(item).toBe(5);
|
|
2388
|
-
});
|
|
2389
|
-
test("Should return null when item not found", async () => {
|
|
2390
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2391
|
-
item = await collection.last({
|
|
2392
|
-
filterFn: (item) => item === 6,
|
|
2393
|
-
});
|
|
2394
|
-
expect(item).toBe(null);
|
|
2395
|
-
});
|
|
2396
|
-
test("Should input correct indexes to filter function", async () => {
|
|
2397
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2398
|
-
indexes: number[] = [];
|
|
2399
|
-
await collection.last({
|
|
2400
|
-
filterFn: (item, index) => {
|
|
2401
|
-
indexes.push(index);
|
|
2402
|
-
return item === 6;
|
|
2403
|
-
},
|
|
2404
|
-
});
|
|
2405
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4]);
|
|
2406
|
-
});
|
|
2407
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
2408
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
2409
|
-
expect(await collection.last()).toBe(5);
|
|
2410
|
-
expect(await collection.last()).toBe(5);
|
|
2411
|
-
});
|
|
2412
|
-
test("Should work with async filter function", async () => {
|
|
2413
|
-
type Person = {
|
|
2414
|
-
name: string;
|
|
2415
|
-
age: number;
|
|
2416
|
-
};
|
|
2417
|
-
const persons: Person[] = [
|
|
2418
|
-
{
|
|
2419
|
-
name: "Joe",
|
|
2420
|
-
age: 20,
|
|
2421
|
-
},
|
|
2422
|
-
{
|
|
2423
|
-
name: "Jhon",
|
|
2424
|
-
age: 23,
|
|
2425
|
-
},
|
|
2426
|
-
{
|
|
2427
|
-
name: "Joe",
|
|
2428
|
-
age: 30,
|
|
2429
|
-
},
|
|
2430
|
-
{
|
|
2431
|
-
name: "Jhon",
|
|
2432
|
-
age: 50,
|
|
2433
|
-
},
|
|
2434
|
-
],
|
|
2435
|
-
collection = new AsyncIterableCollection(persons),
|
|
2436
|
-
item = await collection.last({
|
|
2437
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2438
|
-
filterFn: async (person) => person.name === "Joe",
|
|
2439
|
-
});
|
|
2440
|
-
expect(item).toEqual(persons[2]);
|
|
2441
|
-
});
|
|
2442
|
-
});
|
|
2443
|
-
describe("method: lastOr", () => {
|
|
2444
|
-
test("Should return last item that matches the filter function", async () => {
|
|
2445
|
-
type Person = {
|
|
2446
|
-
name: string;
|
|
2447
|
-
age: number;
|
|
2448
|
-
};
|
|
2449
|
-
const persons: Person[] = [
|
|
2450
|
-
{
|
|
2451
|
-
name: "Joe",
|
|
2452
|
-
age: 20,
|
|
2453
|
-
},
|
|
2454
|
-
{
|
|
2455
|
-
name: "Jhon",
|
|
2456
|
-
age: 23,
|
|
2457
|
-
},
|
|
2458
|
-
{
|
|
2459
|
-
name: "Joe",
|
|
2460
|
-
age: 30,
|
|
2461
|
-
},
|
|
2462
|
-
{
|
|
2463
|
-
name: "Jhon",
|
|
2464
|
-
age: 50,
|
|
2465
|
-
},
|
|
2466
|
-
],
|
|
2467
|
-
collection = new AsyncIterableCollection(persons),
|
|
2468
|
-
item = await collection.lastOr({
|
|
2469
|
-
defaultValue: null,
|
|
2470
|
-
filterFn: (person) => person.name === "Joe",
|
|
2471
|
-
});
|
|
2472
|
-
expect(item).toEqual(persons[2]);
|
|
2473
|
-
});
|
|
2474
|
-
test("Should return last item when found", async () => {
|
|
2475
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2476
|
-
item = await collection.lastOr({
|
|
2477
|
-
defaultValue: "a",
|
|
2478
|
-
});
|
|
2479
|
-
expect(item).toBe(5);
|
|
2480
|
-
});
|
|
2481
|
-
test("Should return default value when item not found", async () => {
|
|
2482
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2483
|
-
item = await collection.lastOr({
|
|
2484
|
-
defaultValue: "a",
|
|
2485
|
-
filterFn: (item) => item === 6,
|
|
2486
|
-
});
|
|
2487
|
-
expect(item).toBe("a");
|
|
2488
|
-
});
|
|
2489
|
-
test("Should input correct indexes to filter function", async () => {
|
|
2490
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2491
|
-
indexes: number[] = [];
|
|
2492
|
-
await collection.lastOr({
|
|
2493
|
-
defaultValue: null,
|
|
2494
|
-
filterFn: (item, index) => {
|
|
2495
|
-
indexes.push(index);
|
|
2496
|
-
return item === 6;
|
|
2497
|
-
},
|
|
2498
|
-
});
|
|
2499
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4]);
|
|
2500
|
-
});
|
|
2501
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
2502
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
2503
|
-
expect(
|
|
2504
|
-
await collection.lastOr({
|
|
2505
|
-
defaultValue: "a",
|
|
2506
|
-
}),
|
|
2507
|
-
).toBe(5);
|
|
2508
|
-
expect(
|
|
2509
|
-
await collection.lastOr({
|
|
2510
|
-
defaultValue: "a",
|
|
2511
|
-
}),
|
|
2512
|
-
).toBe(5);
|
|
2513
|
-
});
|
|
2514
|
-
test("Should work with async filter function", async () => {
|
|
2515
|
-
type Person = {
|
|
2516
|
-
name: string;
|
|
2517
|
-
age: number;
|
|
2518
|
-
};
|
|
2519
|
-
const persons: Person[] = [
|
|
2520
|
-
{
|
|
2521
|
-
name: "Joe",
|
|
2522
|
-
age: 20,
|
|
2523
|
-
},
|
|
2524
|
-
{
|
|
2525
|
-
name: "Jhon",
|
|
2526
|
-
age: 23,
|
|
2527
|
-
},
|
|
2528
|
-
{
|
|
2529
|
-
name: "Joe",
|
|
2530
|
-
age: 30,
|
|
2531
|
-
},
|
|
2532
|
-
{
|
|
2533
|
-
name: "Jhon",
|
|
2534
|
-
age: 50,
|
|
2535
|
-
},
|
|
2536
|
-
],
|
|
2537
|
-
collection = new AsyncIterableCollection(persons),
|
|
2538
|
-
item = await collection.lastOr({
|
|
2539
|
-
defaultValue: null,
|
|
2540
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2541
|
-
filterFn: async (person) => person.name === "Joe",
|
|
2542
|
-
});
|
|
2543
|
-
expect(item).toEqual(persons[2]);
|
|
2544
|
-
});
|
|
2545
|
-
});
|
|
2546
|
-
describe("method: lastOrFail", () => {
|
|
2547
|
-
test("Should return last item that matches the filter function", async () => {
|
|
2548
|
-
type Person = {
|
|
2549
|
-
name: string;
|
|
2550
|
-
age: number;
|
|
2551
|
-
};
|
|
2552
|
-
const persons: Person[] = [
|
|
2553
|
-
{
|
|
2554
|
-
name: "Joe",
|
|
2555
|
-
age: 20,
|
|
2556
|
-
},
|
|
2557
|
-
{
|
|
2558
|
-
name: "Jhon",
|
|
2559
|
-
age: 23,
|
|
2560
|
-
},
|
|
2561
|
-
{
|
|
2562
|
-
name: "Joe",
|
|
2563
|
-
age: 30,
|
|
2564
|
-
},
|
|
2565
|
-
{
|
|
2566
|
-
name: "Jhon",
|
|
2567
|
-
age: 50,
|
|
2568
|
-
},
|
|
2569
|
-
],
|
|
2570
|
-
collection = new AsyncIterableCollection(persons),
|
|
2571
|
-
item = await collection.lastOrFail({
|
|
2572
|
-
filterFn: (person) => person.name === "Joe",
|
|
2573
|
-
});
|
|
2574
|
-
expect(item).toEqual(persons[2]);
|
|
2575
|
-
});
|
|
2576
|
-
test("Should return last item when found", async () => {
|
|
2577
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2578
|
-
item = await collection.lastOrFail();
|
|
2579
|
-
expect(item).toBe(5);
|
|
2580
|
-
});
|
|
2581
|
-
test("Should throw CollectionError when item not found", async () => {
|
|
2582
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
2583
|
-
await expect(async () => {
|
|
2584
|
-
await collection.lastOrFail({
|
|
2585
|
-
filterFn: (item) => item === 6,
|
|
2586
|
-
});
|
|
2587
|
-
}).rejects.toThrowError(CollectionError);
|
|
2588
|
-
});
|
|
2589
|
-
test("Should throw ItemNotFoundError when item not found", async () => {
|
|
2590
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
2591
|
-
await expect(async () => {
|
|
2592
|
-
await collection.lastOrFail({
|
|
2593
|
-
filterFn: (item) => item === 6,
|
|
2594
|
-
});
|
|
2595
|
-
}).rejects.toThrowError(ItemNotFoundError);
|
|
2596
|
-
});
|
|
2597
|
-
test("Should input correct indexes to filter function", async () => {
|
|
2598
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]),
|
|
2599
|
-
indexes: number[] = [];
|
|
2600
|
-
try {
|
|
2601
|
-
await collection.lastOrFail({
|
|
2602
|
-
filterFn: (item, index) => {
|
|
2603
|
-
indexes.push(index);
|
|
2604
|
-
return item === 6;
|
|
2605
|
-
},
|
|
2606
|
-
});
|
|
2607
|
-
} catch {
|
|
2608
|
-
/* Empty */
|
|
2609
|
-
}
|
|
2610
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4]);
|
|
2611
|
-
});
|
|
2612
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
2613
|
-
const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
2614
|
-
expect(await collection.lastOrFail()).toBe(5);
|
|
2615
|
-
expect(await collection.lastOrFail()).toBe(5);
|
|
2616
|
-
});
|
|
2617
|
-
test("Should work with async filter function", async () => {
|
|
2618
|
-
type Person = {
|
|
2619
|
-
name: string;
|
|
2620
|
-
age: number;
|
|
2621
|
-
};
|
|
2622
|
-
const persons: Person[] = [
|
|
2623
|
-
{
|
|
2624
|
-
name: "Joe",
|
|
2625
|
-
age: 20,
|
|
2626
|
-
},
|
|
2627
|
-
{
|
|
2628
|
-
name: "Jhon",
|
|
2629
|
-
age: 23,
|
|
2630
|
-
},
|
|
2631
|
-
{
|
|
2632
|
-
name: "Joe",
|
|
2633
|
-
age: 30,
|
|
2634
|
-
},
|
|
2635
|
-
{
|
|
2636
|
-
name: "Jhon",
|
|
2637
|
-
age: 50,
|
|
2638
|
-
},
|
|
2639
|
-
],
|
|
2640
|
-
collection = new AsyncIterableCollection(persons),
|
|
2641
|
-
item = await collection.lastOrFail({
|
|
2642
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2643
|
-
filterFn: async (person) => person.name === "Joe",
|
|
2644
|
-
});
|
|
2645
|
-
expect(item).toEqual(persons[2]);
|
|
2646
|
-
});
|
|
2647
|
-
});
|
|
2648
|
-
describe("method: before", () => {
|
|
2649
|
-
test(`Should return "a" when searching for string "b" of ["a", "b", "c"]`, async () => {
|
|
2650
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2651
|
-
item = await collection.before((item) => item === "b");
|
|
2652
|
-
expect(item).toBe("a");
|
|
2653
|
-
});
|
|
2654
|
-
test(`Should return "b" when searching for string "c" of ["a", "b", "c"]`, async () => {
|
|
2655
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2656
|
-
item = await collection.before((item) => item === "c");
|
|
2657
|
-
expect(item).toBe("b");
|
|
2658
|
-
});
|
|
2659
|
-
test(`Should return null when searching for string "a" of ["a", "b", "c"]`, async () => {
|
|
2660
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2661
|
-
item = await collection.before((item) => item === "a");
|
|
2662
|
-
expect(item).toBe(null);
|
|
2663
|
-
});
|
|
2664
|
-
test(`Should return null when searching for string "d" of ["a", "b", "c"]`, async () => {
|
|
2665
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2666
|
-
item = await collection.before((item) => item === "d");
|
|
2667
|
-
expect(item).toBe(null);
|
|
2668
|
-
});
|
|
2669
|
-
test("Should input correct indexes to filter function", async () => {
|
|
2670
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2671
|
-
indexes: number[] = [];
|
|
2672
|
-
await collection.before((item, index) => {
|
|
2673
|
-
indexes.push(index);
|
|
2674
|
-
return item === "c";
|
|
2675
|
-
});
|
|
2676
|
-
expect(indexes).toEqual([0, 1, 2]);
|
|
2677
|
-
});
|
|
2678
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
2679
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
2680
|
-
expect(await collection.before((item) => item === "c")).toBe("b");
|
|
2681
|
-
expect(await collection.before((item) => item === "c")).toBe("b");
|
|
2682
|
-
});
|
|
2683
|
-
test("Should work with async filter function", async () => {
|
|
2684
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2685
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2686
|
-
item = await collection.before(async (item) => item === "b");
|
|
2687
|
-
expect(item).toBe("a");
|
|
2688
|
-
});
|
|
2689
|
-
});
|
|
2690
|
-
describe("method: beforeOr", () => {
|
|
2691
|
-
test(`Should return "a" when searching for string "b" of ["a", "b", "c"]`, async () => {
|
|
2692
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2693
|
-
item = await collection.beforeOr(-1, (item) => item === "b");
|
|
2694
|
-
expect(item).toBe("a");
|
|
2695
|
-
});
|
|
2696
|
-
test(`Should return "b" when searching for string "c" of ["a", "b", "c"]`, async () => {
|
|
2697
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2698
|
-
item = await collection.beforeOr(-1, (item) => item === "c");
|
|
2699
|
-
expect(item).toBe("b");
|
|
2700
|
-
});
|
|
2701
|
-
test(`Should return default value when searching for string "a" of ["a", "b", "c"]`, async () => {
|
|
2702
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2703
|
-
item = await collection.beforeOr(-1, (item) => item === "a");
|
|
2704
|
-
expect(item).toBe(-1);
|
|
2705
|
-
});
|
|
2706
|
-
test(`Should return default value when searching for string "d" of ["a", "b", "c"]`, async () => {
|
|
2707
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2708
|
-
item = await collection.beforeOr(-1, (item) => item === "d");
|
|
2709
|
-
expect(item).toBe(-1);
|
|
2710
|
-
});
|
|
2711
|
-
test("Should input correct indexes to filter function", async () => {
|
|
2712
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2713
|
-
indexes: number[] = [];
|
|
2714
|
-
await collection.beforeOr(null, (item, index) => {
|
|
2715
|
-
indexes.push(index);
|
|
2716
|
-
return item === "c";
|
|
2717
|
-
});
|
|
2718
|
-
expect(indexes).toEqual([0, 1, 2]);
|
|
2719
|
-
});
|
|
2720
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
2721
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
2722
|
-
expect(await collection.beforeOr(-1, (item) => item === "c")).toBe(
|
|
2723
|
-
"b",
|
|
2724
|
-
);
|
|
2725
|
-
expect(await collection.beforeOr(-1, (item) => item === "c")).toBe(
|
|
2726
|
-
"b",
|
|
2727
|
-
);
|
|
2728
|
-
});
|
|
2729
|
-
test("Should work with async filter function", async () => {
|
|
2730
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2731
|
-
item = await collection.beforeOr(
|
|
2732
|
-
-1,
|
|
2733
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2734
|
-
async (item) => item === "b",
|
|
2735
|
-
);
|
|
2736
|
-
expect(item).toBe("a");
|
|
2737
|
-
});
|
|
2738
|
-
});
|
|
2739
|
-
describe("method: beforeOrFail", () => {
|
|
2740
|
-
test(`Should return "a" when searching for string "b" of ["a", "b", "c"]`, async () => {
|
|
2741
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2742
|
-
item = await collection.beforeOrFail((item) => item === "b");
|
|
2743
|
-
expect(item).toBe("a");
|
|
2744
|
-
});
|
|
2745
|
-
test(`Should return "b" when searching for string "c" of ["a", "b", "c"]`, async () => {
|
|
2746
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2747
|
-
item = await collection.beforeOrFail((item) => item === "c");
|
|
2748
|
-
expect(item).toBe("b");
|
|
2749
|
-
});
|
|
2750
|
-
test(`Should throw CollectionError when searching for string "a" of ["a", "b", "c"]`, async () => {
|
|
2751
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
2752
|
-
await expect(async () => {
|
|
2753
|
-
await collection.beforeOrFail((item) => item === "a");
|
|
2754
|
-
}).rejects.toThrowError(CollectionError);
|
|
2755
|
-
});
|
|
2756
|
-
test(`Should throw ItemNotFoundError when searching for string "d" of ["a", "b", "c"]`, async () => {
|
|
2757
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
2758
|
-
await expect(async () => {
|
|
2759
|
-
await collection.beforeOrFail((item) => item === "d");
|
|
2760
|
-
}).rejects.toThrowError(ItemNotFoundError);
|
|
2761
|
-
});
|
|
2762
|
-
test("Should input correct indexes to filter function", async () => {
|
|
2763
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2764
|
-
indexes: number[] = [];
|
|
2765
|
-
try {
|
|
2766
|
-
await collection.beforeOrFail((item, index) => {
|
|
2767
|
-
indexes.push(index);
|
|
2768
|
-
return item === "c";
|
|
2769
|
-
});
|
|
2770
|
-
} catch {
|
|
2771
|
-
/* Empty */
|
|
2772
|
-
}
|
|
2773
|
-
expect(indexes).toEqual([0, 1, 2]);
|
|
2774
|
-
});
|
|
2775
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
2776
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
2777
|
-
expect(await collection.beforeOrFail((item) => item === "c")).toBe(
|
|
2778
|
-
"b",
|
|
2779
|
-
);
|
|
2780
|
-
expect(await collection.beforeOrFail((item) => item === "c")).toBe(
|
|
2781
|
-
"b",
|
|
2782
|
-
);
|
|
2783
|
-
});
|
|
2784
|
-
test("Should work with async filter function", async () => {
|
|
2785
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2786
|
-
item = await collection.beforeOrFail(
|
|
2787
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2788
|
-
async (item) => item === "b",
|
|
2789
|
-
);
|
|
2790
|
-
expect(item).toBe("a");
|
|
2791
|
-
});
|
|
2792
|
-
});
|
|
2793
|
-
describe("method: after", () => {
|
|
2794
|
-
test(`Should return "c" when searching for string "b" of ["a", "b", "c"]`, async () => {
|
|
2795
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2796
|
-
item = await collection.after((item) => item === "b");
|
|
2797
|
-
expect(item).toBe("c");
|
|
2798
|
-
});
|
|
2799
|
-
test(`Should return "b" when searching for string "a" of ["a", "b", "c"]`, async () => {
|
|
2800
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2801
|
-
item = await collection.after((item) => item === "a");
|
|
2802
|
-
expect(item).toBe("b");
|
|
2803
|
-
});
|
|
2804
|
-
test(`Should return null when searching for string "c" of ["a", "b", "c"]`, async () => {
|
|
2805
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2806
|
-
item = await collection.after((item) => item === "c");
|
|
2807
|
-
expect(item).toBe(null);
|
|
2808
|
-
});
|
|
2809
|
-
test(`Should return null when searching for string "d" of ["a", "b", "c"]`, async () => {
|
|
2810
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2811
|
-
item = await collection.after((item) => item === "d");
|
|
2812
|
-
expect(item).toBe(null);
|
|
2813
|
-
});
|
|
2814
|
-
test("Should input correct indexes to filter function", async () => {
|
|
2815
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2816
|
-
indexes: number[] = [];
|
|
2817
|
-
await collection.after((item, index) => {
|
|
2818
|
-
indexes.push(index);
|
|
2819
|
-
return item === "c";
|
|
2820
|
-
});
|
|
2821
|
-
expect(indexes).toEqual([0, 1, 2]);
|
|
2822
|
-
});
|
|
2823
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
2824
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
2825
|
-
expect(await collection.after((item) => item === "a")).toBe("b");
|
|
2826
|
-
expect(await collection.after((item) => item === "a")).toBe("b");
|
|
2827
|
-
});
|
|
2828
|
-
test("Should work with async filter function", async () => {
|
|
2829
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2830
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2831
|
-
item = await collection.after(async (item) => item === "b");
|
|
2832
|
-
expect(item).toBe("c");
|
|
2833
|
-
});
|
|
2834
|
-
});
|
|
2835
|
-
describe("method: afterOr", () => {
|
|
2836
|
-
test(`Should return "c" when searching for string "b" of ["a", "b", "c"]`, async () => {
|
|
2837
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2838
|
-
item = await collection.afterOr(-1, (item) => item === "b");
|
|
2839
|
-
expect(item).toBe("c");
|
|
2840
|
-
});
|
|
2841
|
-
test(`Should return "b" when searching for string "a" of ["a", "b", "c"]`, async () => {
|
|
2842
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2843
|
-
item = await collection.afterOr(-1, (item) => item === "a");
|
|
2844
|
-
expect(item).toBe("b");
|
|
2845
|
-
});
|
|
2846
|
-
test(`Should return default value when searching for string "c" of ["a", "b", "c"]`, async () => {
|
|
2847
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2848
|
-
item = await collection.afterOr(-1, (item) => item === "c");
|
|
2849
|
-
expect(item).toBe(-1);
|
|
2850
|
-
});
|
|
2851
|
-
test(`Should return default value when searching for string "d" of ["a", "b", "c"]`, async () => {
|
|
2852
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2853
|
-
item = await collection.afterOr(-1, (item) => item === "d");
|
|
2854
|
-
expect(item).toBe(-1);
|
|
2855
|
-
});
|
|
2856
|
-
test("Should input correct indexes to filter function", async () => {
|
|
2857
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2858
|
-
indexes: number[] = [];
|
|
2859
|
-
await collection.afterOr(null, (item, index) => {
|
|
2860
|
-
indexes.push(index);
|
|
2861
|
-
return item === "c";
|
|
2862
|
-
});
|
|
2863
|
-
expect(indexes).toEqual([0, 1, 2]);
|
|
2864
|
-
});
|
|
2865
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
2866
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
2867
|
-
expect(await collection.afterOr(-1, (item) => item === "a")).toBe(
|
|
2868
|
-
"b",
|
|
2869
|
-
);
|
|
2870
|
-
expect(await collection.afterOr(-1, (item) => item === "a")).toBe(
|
|
2871
|
-
"b",
|
|
2872
|
-
);
|
|
2873
|
-
});
|
|
2874
|
-
test("Should work async filter function", async () => {
|
|
2875
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2876
|
-
item = await collection.afterOr(
|
|
2877
|
-
-1,
|
|
2878
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2879
|
-
async (item) => item === "b",
|
|
2880
|
-
);
|
|
2881
|
-
expect(item).toBe("c");
|
|
2882
|
-
});
|
|
2883
|
-
});
|
|
2884
|
-
describe("method: afterOrFail", () => {
|
|
2885
|
-
test(`Should return "c" when searching for string "b" of ["a", "b", "c"]`, async () => {
|
|
2886
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2887
|
-
item = await collection.afterOrFail((item) => item === "b");
|
|
2888
|
-
expect(item).toBe("c");
|
|
2889
|
-
});
|
|
2890
|
-
test(`Should return "b" when searching for string "a" of ["a", "b", "c"]`, async () => {
|
|
2891
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2892
|
-
item = await collection.afterOrFail((item) => item === "a");
|
|
2893
|
-
expect(item).toBe("b");
|
|
2894
|
-
});
|
|
2895
|
-
test(`Should throw CollectionError when searching for string "c" of ["a", "b", "c"]`, async () => {
|
|
2896
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
2897
|
-
await expect(async () => {
|
|
2898
|
-
await collection.afterOrFail((item) => item === "c");
|
|
2899
|
-
}).rejects.toThrowError(CollectionError);
|
|
2900
|
-
});
|
|
2901
|
-
test(`Should throw ItemNotFoundError when searching for string "d" of ["a", "b", "c"]`, async () => {
|
|
2902
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
2903
|
-
await expect(async () => {
|
|
2904
|
-
await collection.afterOrFail((item) => item === "d");
|
|
2905
|
-
}).rejects.toThrowError(ItemNotFoundError);
|
|
2906
|
-
});
|
|
2907
|
-
test("Should input correct indexes to filter function", async () => {
|
|
2908
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2909
|
-
indexes: number[] = [];
|
|
2910
|
-
try {
|
|
2911
|
-
await collection.afterOrFail((item, index) => {
|
|
2912
|
-
indexes.push(index);
|
|
2913
|
-
return item === "c";
|
|
2914
|
-
});
|
|
2915
|
-
} catch {
|
|
2916
|
-
/* Empty */
|
|
2917
|
-
}
|
|
2918
|
-
expect(indexes).toEqual([0, 1, 2]);
|
|
2919
|
-
});
|
|
2920
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
2921
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
2922
|
-
expect(await collection.afterOrFail((item) => item === "a")).toBe(
|
|
2923
|
-
"b",
|
|
2924
|
-
);
|
|
2925
|
-
expect(await collection.afterOrFail((item) => item === "a")).toBe(
|
|
2926
|
-
"b",
|
|
2927
|
-
);
|
|
2928
|
-
});
|
|
2929
|
-
test("Should work with async filter function", async () => {
|
|
2930
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]),
|
|
2931
|
-
item = await collection.afterOrFail(
|
|
2932
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2933
|
-
async (item) => item === "b",
|
|
2934
|
-
);
|
|
2935
|
-
expect(item).toBe("c");
|
|
2936
|
-
});
|
|
2937
|
-
});
|
|
2938
|
-
describe("method: sole", () => {
|
|
2939
|
-
test("Should throw ItemNotFoundError when item does not exist", async () => {
|
|
2940
|
-
const collection = new AsyncIterableCollection([
|
|
2941
|
-
"a",
|
|
2942
|
-
"a",
|
|
2943
|
-
"b",
|
|
2944
|
-
"c",
|
|
2945
|
-
"b",
|
|
2946
|
-
]);
|
|
2947
|
-
await expect(async () => {
|
|
2948
|
-
await collection.sole((item) => item === "f");
|
|
2949
|
-
}).rejects.toThrowError(ItemNotFoundError);
|
|
2950
|
-
});
|
|
2951
|
-
test("Should throw MultipleItemsFoundError when multiple item of same sort does exist", async () => {
|
|
2952
|
-
const collection = new AsyncIterableCollection([
|
|
2953
|
-
"a",
|
|
2954
|
-
"a",
|
|
2955
|
-
"b",
|
|
2956
|
-
"c",
|
|
2957
|
-
"b",
|
|
2958
|
-
]);
|
|
2959
|
-
await expect(async () => {
|
|
2960
|
-
await collection.sole((item) => item === "a");
|
|
2961
|
-
}).rejects.toThrowError(MultipleItemsFoundError);
|
|
2962
|
-
});
|
|
2963
|
-
test("Should return item when only one item of the same sort exist", async () => {
|
|
2964
|
-
const collection = new AsyncIterableCollection([
|
|
2965
|
-
"a",
|
|
2966
|
-
"a",
|
|
2967
|
-
"b",
|
|
2968
|
-
"c",
|
|
2969
|
-
"b",
|
|
2970
|
-
]);
|
|
2971
|
-
expect(await collection.sole((item) => item === "c")).toBe("c");
|
|
2972
|
-
});
|
|
2973
|
-
test("Should input correct indexes to filter function", async () => {
|
|
2974
|
-
const collection = new AsyncIterableCollection([
|
|
2975
|
-
"a",
|
|
2976
|
-
"a",
|
|
2977
|
-
"b",
|
|
2978
|
-
"c",
|
|
2979
|
-
"b",
|
|
2980
|
-
]),
|
|
2981
|
-
indexes: number[] = [];
|
|
2982
|
-
await collection.sole((item, index) => {
|
|
2983
|
-
indexes.push(index);
|
|
2984
|
-
return item === "c";
|
|
2985
|
-
});
|
|
2986
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4]);
|
|
2987
|
-
});
|
|
2988
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
2989
|
-
const collection = new AsyncIterableCollection([
|
|
2990
|
-
"a",
|
|
2991
|
-
"a",
|
|
2992
|
-
"b",
|
|
2993
|
-
"c",
|
|
2994
|
-
"b",
|
|
2995
|
-
]);
|
|
2996
|
-
expect(await collection.sole((item) => item === "c")).toBe("c");
|
|
2997
|
-
expect(await collection.sole((item) => item === "c")).toBe("c");
|
|
2998
|
-
});
|
|
2999
|
-
test("Should work with async filter function", async () => {
|
|
3000
|
-
const collection = new AsyncIterableCollection([
|
|
3001
|
-
"a",
|
|
3002
|
-
"a",
|
|
3003
|
-
"b",
|
|
3004
|
-
"c",
|
|
3005
|
-
"b",
|
|
3006
|
-
]);
|
|
3007
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
3008
|
-
expect(await collection.sole(async (item) => item === "c")).toBe(
|
|
3009
|
-
"c",
|
|
3010
|
-
);
|
|
3011
|
-
});
|
|
3012
|
-
});
|
|
3013
|
-
describe("method: nth", () => {
|
|
3014
|
-
test("Should filter the 4:th items", async () => {
|
|
3015
|
-
const collection = new AsyncIterableCollection([
|
|
3016
|
-
"a",
|
|
3017
|
-
"b",
|
|
3018
|
-
"c",
|
|
3019
|
-
"d",
|
|
3020
|
-
"e",
|
|
3021
|
-
"f",
|
|
3022
|
-
]),
|
|
3023
|
-
newCollection = collection.nth(4);
|
|
3024
|
-
expect(await newCollection.toArray()).toEqual(["a", "e"]);
|
|
3025
|
-
});
|
|
3026
|
-
});
|
|
3027
|
-
describe("method: count", () => {
|
|
3028
|
-
test(`Should return number 0 when filtering all string "a" of ["b", "b"]`, async () => {
|
|
3029
|
-
const collection = new AsyncIterableCollection(["b", "b"]);
|
|
3030
|
-
expect(await collection.count((item) => item === "a")).toBe(0);
|
|
3031
|
-
});
|
|
3032
|
-
test(`Should return number 3 when filtering all string "a" of ["a", "b", "a", "b", "a"]`, async () => {
|
|
3033
|
-
const collection = new AsyncIterableCollection([
|
|
3034
|
-
"a",
|
|
3035
|
-
"b",
|
|
3036
|
-
"a",
|
|
3037
|
-
"b",
|
|
3038
|
-
"a",
|
|
3039
|
-
]);
|
|
3040
|
-
expect(await collection.count((item) => item === "a")).toBe(3);
|
|
3041
|
-
});
|
|
3042
|
-
test("Should input correct indexes to filter function", async () => {
|
|
3043
|
-
const collection = new AsyncIterableCollection([
|
|
3044
|
-
"a",
|
|
3045
|
-
"a",
|
|
3046
|
-
"b",
|
|
3047
|
-
"c",
|
|
3048
|
-
"b",
|
|
3049
|
-
]),
|
|
3050
|
-
indexes: number[] = [];
|
|
3051
|
-
await collection.count((_item, index) => {
|
|
3052
|
-
indexes.push(index);
|
|
3053
|
-
return true;
|
|
3054
|
-
});
|
|
3055
|
-
expect(indexes).toEqual([0, 1, 2, 3, 4]);
|
|
3056
|
-
});
|
|
3057
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
3058
|
-
const collection = new AsyncIterableCollection([
|
|
3059
|
-
"a",
|
|
3060
|
-
"b",
|
|
3061
|
-
"a",
|
|
3062
|
-
"b",
|
|
3063
|
-
"a",
|
|
3064
|
-
]);
|
|
3065
|
-
expect(await collection.count((item) => item === "a")).toBe(3);
|
|
3066
|
-
expect(await collection.count((item) => item === "a")).toBe(3);
|
|
3067
|
-
});
|
|
3068
|
-
test("Should work with async filter function", async () => {
|
|
3069
|
-
const collection = new AsyncIterableCollection(["b", "b"]);
|
|
3070
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
3071
|
-
expect(await collection.count(async (item) => item === "b")).toBe(
|
|
3072
|
-
2,
|
|
3073
|
-
);
|
|
3074
|
-
});
|
|
3075
|
-
});
|
|
3076
|
-
describe("method: size", () => {
|
|
3077
|
-
test("Should return 0 when empty", async () => {
|
|
3078
|
-
const collection = new AsyncIterableCollection([]);
|
|
3079
|
-
expect(await collection.size()).toBe(0);
|
|
3080
|
-
});
|
|
3081
|
-
test("Should return number larger than 0 when empty", async () => {
|
|
3082
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
3083
|
-
expect(await collection.size()).toBeGreaterThan(0);
|
|
3084
|
-
});
|
|
3085
|
-
test("Should return 3 when contains 3 items", async () => {
|
|
3086
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
3087
|
-
expect(await collection.size()).toBe(3);
|
|
3088
|
-
});
|
|
3089
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
3090
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
3091
|
-
expect(await collection.size()).toBe(3);
|
|
3092
|
-
expect(await collection.size()).toBe(3);
|
|
3093
|
-
});
|
|
3094
|
-
});
|
|
3095
|
-
describe("method: empty", () => {
|
|
3096
|
-
test("Should return true when empty", async () => {
|
|
3097
|
-
const collection = new AsyncIterableCollection([]);
|
|
3098
|
-
expect(await collection.empty()).toBe(true);
|
|
3099
|
-
});
|
|
3100
|
-
test("Should return false when not empty", async () => {
|
|
3101
|
-
const collection = new AsyncIterableCollection([""]);
|
|
3102
|
-
expect(await collection.empty()).toBe(false);
|
|
3103
|
-
});
|
|
3104
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
3105
|
-
const collection = new AsyncIterableCollection([]);
|
|
3106
|
-
expect(await collection.empty()).toBe(true);
|
|
3107
|
-
expect(await collection.empty()).toBe(true);
|
|
3108
|
-
});
|
|
3109
|
-
});
|
|
3110
|
-
describe("method: notEmpty", () => {
|
|
3111
|
-
test("Should return true when not empty", async () => {
|
|
3112
|
-
const collection = new AsyncIterableCollection([""]);
|
|
3113
|
-
expect(await collection.notEmpty()).toBe(true);
|
|
3114
|
-
});
|
|
3115
|
-
test("Should return false when empty", async () => {
|
|
3116
|
-
const collection = new AsyncIterableCollection([]);
|
|
3117
|
-
expect(await collection.notEmpty()).toBe(false);
|
|
3118
|
-
});
|
|
3119
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
3120
|
-
const collection = new AsyncIterableCollection([""]);
|
|
3121
|
-
expect(await collection.notEmpty()).toBe(true);
|
|
3122
|
-
expect(await collection.notEmpty()).toBe(true);
|
|
3123
|
-
});
|
|
3124
|
-
});
|
|
3125
|
-
describe("method: search", () => {
|
|
3126
|
-
test("Should return -1 when searching for value that does not exist in collection", async () => {
|
|
3127
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
3128
|
-
expect(await collection.search((item) => item === "d")).toBe(-1);
|
|
3129
|
-
});
|
|
3130
|
-
test(`Should return 1 when searching for string "b" of ["a", "b", "c"]`, async () => {
|
|
3131
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
3132
|
-
expect(await collection.search((item) => item === "b")).toBe(1);
|
|
3133
|
-
});
|
|
3134
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
3135
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
3136
|
-
expect(await collection.search((item) => item === "b")).toBe(1);
|
|
3137
|
-
expect(await collection.search((item) => item === "b")).toBe(1);
|
|
3138
|
-
});
|
|
3139
|
-
test("Should work with async filter function", async () => {
|
|
3140
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
3141
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
3142
|
-
expect(await collection.search(async (item) => item === "b")).toBe(
|
|
3143
|
-
1,
|
|
3144
|
-
);
|
|
3145
|
-
});
|
|
3146
|
-
});
|
|
3147
|
-
describe("method: forEach", () => {
|
|
3148
|
-
test("Should iterate all items", async () => {
|
|
3149
|
-
const arr1 = [1, 2, 3],
|
|
3150
|
-
collection = new AsyncIterableCollection(arr1),
|
|
3151
|
-
arr2: number[] = [];
|
|
3152
|
-
await collection.forEach((item) => arr2.push(item));
|
|
3153
|
-
expect(arr2).toEqual(arr1);
|
|
3154
|
-
});
|
|
3155
|
-
test("Should input correct indexes to filter function", async () => {
|
|
3156
|
-
const collection = new AsyncIterableCollection([1, 2, 3]),
|
|
3157
|
-
indexes: number[] = [];
|
|
3158
|
-
await collection.forEach((_item, index) => {
|
|
3159
|
-
indexes.push(index);
|
|
3160
|
-
});
|
|
3161
|
-
expect(indexes).toEqual([0, 1, 2]);
|
|
3162
|
-
});
|
|
3163
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
3164
|
-
const arr1 = [1, 2, 3],
|
|
3165
|
-
collection = new AsyncIterableCollection(arr1),
|
|
3166
|
-
arr2: number[] = [];
|
|
3167
|
-
await collection.forEach((item) => arr2.push(item));
|
|
3168
|
-
expect(arr2).toEqual(arr1);
|
|
3169
|
-
expect(arr2).toEqual(arr1);
|
|
3170
|
-
});
|
|
3171
|
-
test("Should work with async filter function", async () => {
|
|
3172
|
-
const arr1 = [1, 2, 3],
|
|
3173
|
-
collection = new AsyncIterableCollection(arr1),
|
|
3174
|
-
arr2: number[] = [];
|
|
3175
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
3176
|
-
await collection.forEach(async (item) => arr2.push(item));
|
|
3177
|
-
expect(arr2).toEqual(arr1);
|
|
3178
|
-
});
|
|
3179
|
-
});
|
|
3180
|
-
describe("method: toArray", () => {
|
|
3181
|
-
test("Should return array with 0 items when empty", async () => {
|
|
3182
|
-
const collection = new AsyncIterableCollection([]);
|
|
3183
|
-
expect(await collection.toArray()).toEqual([]);
|
|
3184
|
-
});
|
|
3185
|
-
test("Should return array with items when that match collection items", async () => {
|
|
3186
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
3187
|
-
expect(await collection.toArray()).toEqual(["a", "b", "c"]);
|
|
3188
|
-
});
|
|
3189
|
-
test("Should return the same value when called more than 1 times", async () => {
|
|
3190
|
-
const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
3191
|
-
expect(await collection.toArray()).toEqual(["a", "b", "c"]);
|
|
3192
|
-
expect(await collection.toArray()).toEqual(["a", "b", "c"]);
|
|
3193
|
-
});
|
|
3194
|
-
});
|
|
3195
|
-
});
|