@daiso-tech/core 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/_shared/utilities.js +19 -0
- package/dist/cjs/_shared/utilities.js.map +1 -0
- package/dist/cjs/collection/_shared.js +4 -2
- package/dist/cjs/collection/_shared.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/_module.js +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/_module.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-chunk-iterable.js +8 -7
- package/dist/cjs/collection/async-iterable-collection/_shared/async-chunk-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/{async-chunk-whilte-iterable.js → async-chunk-while-iterable.js} +14 -16
- package/dist/cjs/collection/async-iterable-collection/_shared/async-chunk-while-iterable.js.map +1 -0
- package/dist/cjs/collection/async-iterable-collection/_shared/async-collapse-iterable.js +1 -2
- package/dist/cjs/collection/async-iterable-collection/_shared/async-collapse-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-count-by-iterable.js +3 -6
- package/dist/cjs/collection/async-iterable-collection/_shared/async-count-by-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-cross-join-iterable.js +19 -18
- package/dist/cjs/collection/async-iterable-collection/_shared/async-cross-join-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-entries-iterable.js +1 -8
- package/dist/cjs/collection/async-iterable-collection/_shared/async-entries-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-filter-iterable.js +6 -9
- package/dist/cjs/collection/async-iterable-collection/_shared/async-filter-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-flat-map-iterable.js +3 -6
- package/dist/cjs/collection/async-iterable-collection/_shared/async-flat-map-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-group-by-iterable.js +12 -13
- package/dist/cjs/collection/async-iterable-collection/_shared/async-group-by-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-insert-after-iterable.js +5 -12
- package/dist/cjs/collection/async-iterable-collection/_shared/async-insert-after-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-insert-before-iterable.js +5 -12
- package/dist/cjs/collection/async-iterable-collection/_shared/async-insert-before-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-map-iterable.js +3 -6
- package/dist/cjs/collection/async-iterable-collection/_shared/async-map-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-merge-iterable.js +1 -2
- package/dist/cjs/collection/async-iterable-collection/_shared/async-merge-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-pad-end-iterable.js +1 -4
- package/dist/cjs/collection/async-iterable-collection/_shared/async-pad-end-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-pad-start-iterable.js +1 -4
- package/dist/cjs/collection/async-iterable-collection/_shared/async-pad-start-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-partion-iterable.js +12 -19
- package/dist/cjs/collection/async-iterable-collection/_shared/async-partion-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-repeat-iterable.js +2 -3
- package/dist/cjs/collection/async-iterable-collection/_shared/async-repeat-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-reverse-iterable.js +3 -10
- package/dist/cjs/collection/async-iterable-collection/_shared/async-reverse-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-shuffle-iterable.js +4 -2
- package/dist/cjs/collection/async-iterable-collection/_shared/async-shuffle-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-skip-iterable.js +4 -9
- package/dist/cjs/collection/async-iterable-collection/_shared/async-skip-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-skip-until-iterable.js +5 -12
- package/dist/cjs/collection/async-iterable-collection/_shared/async-skip-until-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-slice-iterable.js +2 -4
- package/dist/cjs/collection/async-iterable-collection/_shared/async-slice-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-sliding-iterable.js +4 -11
- package/dist/cjs/collection/async-iterable-collection/_shared/async-sliding-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-split-iterable.js +7 -9
- package/dist/cjs/collection/async-iterable-collection/_shared/async-split-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-take-iterable.js +4 -9
- package/dist/cjs/collection/async-iterable-collection/_shared/async-take-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-take-until-iterable.js +6 -9
- package/dist/cjs/collection/async-iterable-collection/_shared/async-take-until-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-tap-iterable.js +1 -2
- package/dist/cjs/collection/async-iterable-collection/_shared/async-tap-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-unique-iterable.js +2 -5
- package/dist/cjs/collection/async-iterable-collection/_shared/async-unique-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-update-iterable.js +6 -9
- package/dist/cjs/collection/async-iterable-collection/_shared/async-update-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-when-iterable.js +1 -2
- package/dist/cjs/collection/async-iterable-collection/_shared/async-when-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-zip-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/async-iterable-collection.js +173 -228
- package/dist/cjs/collection/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/_module.js +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/_module.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/chunk-iterable.js +8 -7
- package/dist/cjs/collection/iterable-collection/_shared/chunk-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/{chunk-whilte-iterable.js → chunk-while-iterable.js} +12 -14
- package/dist/cjs/collection/iterable-collection/_shared/chunk-while-iterable.js.map +1 -0
- package/dist/cjs/collection/iterable-collection/_shared/collapse-iterable.js +1 -2
- package/dist/cjs/collection/iterable-collection/_shared/collapse-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/count-by-iterable.js +3 -6
- package/dist/cjs/collection/iterable-collection/_shared/count-by-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/cross-join-iterable.js +26 -20
- package/dist/cjs/collection/iterable-collection/_shared/cross-join-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/entries-iterable.js +2 -9
- package/dist/cjs/collection/iterable-collection/_shared/entries-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/filter-iterable.js +3 -6
- package/dist/cjs/collection/iterable-collection/_shared/filter-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/flat-map-iterable.js +3 -6
- package/dist/cjs/collection/iterable-collection/_shared/flat-map-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/group-by-iterable.js +10 -12
- package/dist/cjs/collection/iterable-collection/_shared/group-by-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/insert-after-iterable.js +3 -6
- package/dist/cjs/collection/iterable-collection/_shared/insert-after-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/insert-before-iterable.js +3 -6
- package/dist/cjs/collection/iterable-collection/_shared/insert-before-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/map-iterable.js +3 -6
- package/dist/cjs/collection/iterable-collection/_shared/map-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/merge-iterable.js +1 -2
- package/dist/cjs/collection/iterable-collection/_shared/merge-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/pad-end-iterable.js +2 -6
- package/dist/cjs/collection/iterable-collection/_shared/pad-end-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/pad-start-iterable.js +2 -6
- package/dist/cjs/collection/iterable-collection/_shared/pad-start-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/partion-iterable.js +9 -11
- package/dist/cjs/collection/iterable-collection/_shared/partion-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/repeat-iterable.js +2 -3
- package/dist/cjs/collection/iterable-collection/_shared/repeat-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/reverse-iterable.js +4 -12
- package/dist/cjs/collection/iterable-collection/_shared/reverse-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/shuffle-iterable.js +5 -4
- package/dist/cjs/collection/iterable-collection/_shared/shuffle-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/skip-iterable.js +4 -9
- package/dist/cjs/collection/iterable-collection/_shared/skip-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/skip-until-iterable.js +3 -6
- package/dist/cjs/collection/iterable-collection/_shared/skip-until-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/slice-iterable.js +3 -6
- package/dist/cjs/collection/iterable-collection/_shared/slice-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/sliding-iterable.js +4 -11
- package/dist/cjs/collection/iterable-collection/_shared/sliding-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/sort-iterable.js +1 -2
- package/dist/cjs/collection/iterable-collection/_shared/sort-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/split-iterable.js +7 -9
- package/dist/cjs/collection/iterable-collection/_shared/split-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/take-iterable.js +4 -9
- package/dist/cjs/collection/iterable-collection/_shared/take-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/take-until-iterable.js +3 -6
- package/dist/cjs/collection/iterable-collection/_shared/take-until-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/tap-iterable.js +1 -2
- package/dist/cjs/collection/iterable-collection/_shared/tap-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/unique-iterable.js +3 -6
- package/dist/cjs/collection/iterable-collection/_shared/unique-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/update-iterable.js +3 -6
- package/dist/cjs/collection/iterable-collection/_shared/update-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/when-iterable.js +1 -2
- package/dist/cjs/collection/iterable-collection/_shared/when-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/zip-iterable.js +1 -2
- package/dist/cjs/collection/iterable-collection/_shared/zip-iterable.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/iterable-collection.js +161 -251
- package/dist/cjs/collection/iterable-collection/iterable-collection.js.map +1 -1
- package/dist/cjs/collection/list-collection/list-collection.js +213 -299
- package/dist/cjs/collection/list-collection/list-collection.js.map +1 -1
- package/dist/cjs/contracts/collection/_shared.js +17 -10
- package/dist/cjs/contracts/collection/_shared.js.map +1 -1
- package/dist/esm/_shared/utilities.js +15 -0
- package/dist/esm/_shared/utilities.js.map +1 -0
- package/dist/esm/collection/_shared.js +4 -2
- package/dist/esm/collection/_shared.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/_module.js +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/_module.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-chunk-iterable.js +8 -7
- package/dist/esm/collection/async-iterable-collection/_shared/async-chunk-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-chunk-while-iterable.js +37 -0
- package/dist/esm/collection/async-iterable-collection/_shared/async-chunk-while-iterable.js.map +1 -0
- package/dist/esm/collection/async-iterable-collection/_shared/async-collapse-iterable.js +1 -2
- package/dist/esm/collection/async-iterable-collection/_shared/async-collapse-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-count-by-iterable.js +3 -6
- package/dist/esm/collection/async-iterable-collection/_shared/async-count-by-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-cross-join-iterable.js +19 -18
- package/dist/esm/collection/async-iterable-collection/_shared/async-cross-join-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-entries-iterable.js +1 -8
- package/dist/esm/collection/async-iterable-collection/_shared/async-entries-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-filter-iterable.js +6 -9
- package/dist/esm/collection/async-iterable-collection/_shared/async-filter-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-flat-map-iterable.js +3 -6
- package/dist/esm/collection/async-iterable-collection/_shared/async-flat-map-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-group-by-iterable.js +12 -13
- package/dist/esm/collection/async-iterable-collection/_shared/async-group-by-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-insert-after-iterable.js +6 -13
- package/dist/esm/collection/async-iterable-collection/_shared/async-insert-after-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-insert-before-iterable.js +6 -13
- package/dist/esm/collection/async-iterable-collection/_shared/async-insert-before-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-map-iterable.js +3 -6
- package/dist/esm/collection/async-iterable-collection/_shared/async-map-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-merge-iterable.js +1 -2
- package/dist/esm/collection/async-iterable-collection/_shared/async-merge-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-pad-end-iterable.js +1 -4
- package/dist/esm/collection/async-iterable-collection/_shared/async-pad-end-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-pad-start-iterable.js +1 -4
- package/dist/esm/collection/async-iterable-collection/_shared/async-pad-start-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-partion-iterable.js +13 -20
- package/dist/esm/collection/async-iterable-collection/_shared/async-partion-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-repeat-iterable.js +2 -3
- package/dist/esm/collection/async-iterable-collection/_shared/async-repeat-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-reverse-iterable.js +3 -10
- package/dist/esm/collection/async-iterable-collection/_shared/async-reverse-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-shuffle-iterable.js +4 -2
- package/dist/esm/collection/async-iterable-collection/_shared/async-shuffle-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-skip-iterable.js +4 -9
- package/dist/esm/collection/async-iterable-collection/_shared/async-skip-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-skip-until-iterable.js +6 -13
- package/dist/esm/collection/async-iterable-collection/_shared/async-skip-until-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-slice-iterable.js +2 -4
- package/dist/esm/collection/async-iterable-collection/_shared/async-slice-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-sliding-iterable.js +4 -11
- package/dist/esm/collection/async-iterable-collection/_shared/async-sliding-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-split-iterable.js +7 -9
- package/dist/esm/collection/async-iterable-collection/_shared/async-split-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-take-iterable.js +4 -9
- package/dist/esm/collection/async-iterable-collection/_shared/async-take-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-take-until-iterable.js +6 -9
- package/dist/esm/collection/async-iterable-collection/_shared/async-take-until-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-tap-iterable.js +1 -2
- package/dist/esm/collection/async-iterable-collection/_shared/async-tap-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-unique-iterable.js +2 -5
- package/dist/esm/collection/async-iterable-collection/_shared/async-unique-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-update-iterable.js +6 -9
- package/dist/esm/collection/async-iterable-collection/_shared/async-update-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-when-iterable.js +1 -2
- package/dist/esm/collection/async-iterable-collection/_shared/async-when-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-zip-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/async-iterable-collection.js +174 -229
- package/dist/esm/collection/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/_module.js +1 -1
- package/dist/esm/collection/iterable-collection/_shared/_module.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/chunk-iterable.js +8 -7
- package/dist/esm/collection/iterable-collection/_shared/chunk-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/{chunk-whilte-iterable.js → chunk-while-iterable.js} +12 -14
- package/dist/esm/collection/iterable-collection/_shared/chunk-while-iterable.js.map +1 -0
- package/dist/esm/collection/iterable-collection/_shared/collapse-iterable.js +1 -2
- package/dist/esm/collection/iterable-collection/_shared/collapse-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/count-by-iterable.js +3 -6
- package/dist/esm/collection/iterable-collection/_shared/count-by-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/cross-join-iterable.js +24 -18
- package/dist/esm/collection/iterable-collection/_shared/cross-join-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/entries-iterable.js +3 -10
- package/dist/esm/collection/iterable-collection/_shared/entries-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/filter-iterable.js +3 -6
- package/dist/esm/collection/iterable-collection/_shared/filter-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/flat-map-iterable.js +3 -6
- package/dist/esm/collection/iterable-collection/_shared/flat-map-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/group-by-iterable.js +10 -12
- package/dist/esm/collection/iterable-collection/_shared/group-by-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/insert-after-iterable.js +3 -6
- package/dist/esm/collection/iterable-collection/_shared/insert-after-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/insert-before-iterable.js +3 -6
- package/dist/esm/collection/iterable-collection/_shared/insert-before-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/map-iterable.js +3 -6
- package/dist/esm/collection/iterable-collection/_shared/map-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/merge-iterable.js +1 -2
- package/dist/esm/collection/iterable-collection/_shared/merge-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/pad-end-iterable.js +2 -6
- package/dist/esm/collection/iterable-collection/_shared/pad-end-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/pad-start-iterable.js +2 -6
- package/dist/esm/collection/iterable-collection/_shared/pad-start-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/partion-iterable.js +9 -11
- package/dist/esm/collection/iterable-collection/_shared/partion-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/repeat-iterable.js +2 -3
- package/dist/esm/collection/iterable-collection/_shared/repeat-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/reverse-iterable.js +4 -12
- package/dist/esm/collection/iterable-collection/_shared/reverse-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/shuffle-iterable.js +5 -4
- package/dist/esm/collection/iterable-collection/_shared/shuffle-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/skip-iterable.js +4 -9
- package/dist/esm/collection/iterable-collection/_shared/skip-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/skip-until-iterable.js +3 -6
- package/dist/esm/collection/iterable-collection/_shared/skip-until-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/slice-iterable.js +3 -6
- package/dist/esm/collection/iterable-collection/_shared/slice-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/sliding-iterable.js +4 -11
- package/dist/esm/collection/iterable-collection/_shared/sliding-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/sort-iterable.js +1 -2
- package/dist/esm/collection/iterable-collection/_shared/sort-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/split-iterable.js +7 -9
- package/dist/esm/collection/iterable-collection/_shared/split-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/take-iterable.js +4 -9
- package/dist/esm/collection/iterable-collection/_shared/take-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/take-until-iterable.js +3 -6
- package/dist/esm/collection/iterable-collection/_shared/take-until-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/tap-iterable.js +1 -2
- package/dist/esm/collection/iterable-collection/_shared/tap-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/unique-iterable.js +3 -6
- package/dist/esm/collection/iterable-collection/_shared/unique-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/update-iterable.js +3 -6
- package/dist/esm/collection/iterable-collection/_shared/update-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/when-iterable.js +1 -2
- package/dist/esm/collection/iterable-collection/_shared/when-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/zip-iterable.js +1 -2
- package/dist/esm/collection/iterable-collection/_shared/zip-iterable.js.map +1 -1
- package/dist/esm/collection/iterable-collection/iterable-collection.js +162 -252
- package/dist/esm/collection/iterable-collection/iterable-collection.js.map +1 -1
- package/dist/esm/collection/list-collection/list-collection.js +214 -300
- package/dist/esm/collection/list-collection/list-collection.js.map +1 -1
- package/dist/esm/contracts/collection/_shared.js +12 -6
- package/dist/esm/contracts/collection/_shared.js.map +1 -1
- package/dist/types/_shared/types.d.ts +5 -0
- package/dist/types/_shared/utilities.d.ts +3 -0
- package/dist/types/collection/async-iterable-collection/_shared/_module.d.ts +1 -1
- package/dist/types/collection/async-iterable-collection/_shared/async-chunk-iterable.d.ts +2 -1
- package/dist/types/collection/async-iterable-collection/_shared/async-chunk-while-iterable.d.ts +12 -0
- package/dist/types/collection/async-iterable-collection/_shared/async-count-by-iterable.d.ts +3 -3
- package/dist/types/collection/async-iterable-collection/_shared/async-cross-join-iterable.d.ts +6 -5
- package/dist/types/collection/async-iterable-collection/_shared/async-entries-iterable.d.ts +3 -4
- package/dist/types/collection/async-iterable-collection/_shared/async-filter-iterable.d.ts +2 -3
- package/dist/types/collection/async-iterable-collection/_shared/async-flat-map-iterable.d.ts +1 -2
- package/dist/types/collection/async-iterable-collection/_shared/async-group-by-iterable.d.ts +4 -4
- package/dist/types/collection/async-iterable-collection/_shared/async-insert-after-iterable.d.ts +4 -4
- package/dist/types/collection/async-iterable-collection/_shared/async-insert-before-iterable.d.ts +4 -4
- package/dist/types/collection/async-iterable-collection/_shared/async-map-iterable.d.ts +1 -2
- package/dist/types/collection/async-iterable-collection/_shared/async-merge-iterable.d.ts +1 -1
- package/dist/types/collection/async-iterable-collection/_shared/async-pad-end-iterable.d.ts +2 -1
- package/dist/types/collection/async-iterable-collection/_shared/async-pad-start-iterable.d.ts +2 -1
- package/dist/types/collection/async-iterable-collection/_shared/async-partion-iterable.d.ts +4 -4
- package/dist/types/collection/async-iterable-collection/_shared/async-repeat-iterable.d.ts +2 -1
- package/dist/types/collection/async-iterable-collection/_shared/async-reverse-iterable.d.ts +3 -3
- package/dist/types/collection/async-iterable-collection/_shared/async-shuffle-iterable.d.ts +2 -1
- package/dist/types/collection/async-iterable-collection/_shared/async-skip-iterable.d.ts +1 -2
- package/dist/types/collection/async-iterable-collection/_shared/async-skip-until-iterable.d.ts +2 -3
- package/dist/types/collection/async-iterable-collection/_shared/async-slice-iterable.d.ts +1 -2
- package/dist/types/collection/async-iterable-collection/_shared/async-sliding-iterable.d.ts +1 -2
- package/dist/types/collection/async-iterable-collection/_shared/async-split-iterable.d.ts +3 -3
- package/dist/types/collection/async-iterable-collection/_shared/async-take-iterable.d.ts +1 -2
- package/dist/types/collection/async-iterable-collection/_shared/async-take-until-iterable.d.ts +2 -3
- package/dist/types/collection/async-iterable-collection/_shared/async-unique-iterable.d.ts +1 -2
- package/dist/types/collection/async-iterable-collection/_shared/async-update-iterable.d.ts +5 -6
- package/dist/types/collection/async-iterable-collection/_shared/async-zip-iterable.d.ts +2 -1
- package/dist/types/collection/async-iterable-collection/async-iterable-collection.d.ts +56 -54
- package/dist/types/collection/iterable-collection/_shared/_module.d.ts +1 -1
- package/dist/types/collection/iterable-collection/_shared/{chunk-whilte-iterable.d.ts → chunk-while-iterable.d.ts} +1 -2
- package/dist/types/collection/iterable-collection/_shared/count-by-iterable.d.ts +3 -3
- package/dist/types/collection/iterable-collection/_shared/cross-join-iterable.d.ts +5 -8
- package/dist/types/collection/iterable-collection/_shared/entries-iterable.d.ts +2 -3
- package/dist/types/collection/iterable-collection/_shared/filter-iterable.d.ts +1 -2
- package/dist/types/collection/iterable-collection/_shared/flat-map-iterable.d.ts +1 -2
- package/dist/types/collection/iterable-collection/_shared/group-by-iterable.d.ts +3 -3
- package/dist/types/collection/iterable-collection/_shared/insert-after-iterable.d.ts +1 -2
- package/dist/types/collection/iterable-collection/_shared/insert-before-iterable.d.ts +1 -2
- package/dist/types/collection/iterable-collection/_shared/map-iterable.d.ts +1 -2
- package/dist/types/collection/iterable-collection/_shared/partion-iterable.d.ts +1 -2
- package/dist/types/collection/iterable-collection/_shared/reverse-iterable.d.ts +1 -2
- package/dist/types/collection/iterable-collection/_shared/shuffle-iterable.d.ts +2 -1
- package/dist/types/collection/iterable-collection/_shared/skip-iterable.d.ts +1 -2
- package/dist/types/collection/iterable-collection/_shared/skip-until-iterable.d.ts +1 -2
- package/dist/types/collection/iterable-collection/_shared/slice-iterable.d.ts +1 -2
- package/dist/types/collection/iterable-collection/_shared/sliding-iterable.d.ts +1 -2
- package/dist/types/collection/iterable-collection/_shared/split-iterable.d.ts +1 -2
- package/dist/types/collection/iterable-collection/_shared/take-iterable.d.ts +1 -2
- package/dist/types/collection/iterable-collection/_shared/take-until-iterable.d.ts +1 -2
- package/dist/types/collection/iterable-collection/_shared/unique-iterable.d.ts +1 -2
- package/dist/types/collection/iterable-collection/_shared/update-iterable.d.ts +4 -5
- package/dist/types/collection/iterable-collection/_shared/zip-iterable.d.ts +1 -1
- package/dist/types/collection/iterable-collection/iterable-collection.d.ts +56 -54
- package/dist/types/collection/list-collection/list-collection.d.ts +57 -54
- package/dist/types/contracts/collection/_shared.d.ts +14 -158
- package/dist/types/contracts/collection/async-collection.contract.d.ts +430 -284
- package/dist/types/contracts/collection/collection.contract.d.ts +417 -260
- package/package.json +2 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-chunk-whilte-iterable.js.map +0 -1
- package/dist/cjs/collection/iterable-collection/_shared/chunk-whilte-iterable.js.map +0 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-chunk-whilte-iterable.js +0 -39
- package/dist/esm/collection/async-iterable-collection/_shared/async-chunk-whilte-iterable.js.map +0 -1
- package/dist/esm/collection/iterable-collection/_shared/chunk-whilte-iterable.js.map +0 -1
- package/dist/types/collection/async-iterable-collection/_shared/async-chunk-whilte-iterable.d.ts +0 -12
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isIterable } from "../../collection/_shared";
|
|
2
|
-
import { CollectionError,
|
|
2
|
+
import { CollectionError, ItemNotFoundCollectionError, MultipleItemsFoundCollectionError, UnexpectedCollectionError, TypeCollectionError, EmptyCollectionError, } from "../../contracts/collection/_module";
|
|
3
|
+
import { simplifyLazyable } from "../../_shared/utilities";
|
|
3
4
|
export class ListCollection {
|
|
4
5
|
array;
|
|
5
6
|
constructor(iterable = []) {
|
|
@@ -11,25 +12,23 @@ export class ListCollection {
|
|
|
11
12
|
toIterator() {
|
|
12
13
|
return this[Symbol.iterator]();
|
|
13
14
|
}
|
|
14
|
-
entries(
|
|
15
|
+
entries() {
|
|
15
16
|
try {
|
|
16
17
|
return new ListCollection(this.array.entries());
|
|
17
18
|
}
|
|
18
19
|
catch (error) {
|
|
19
|
-
if (error instanceof CollectionError
|
|
20
|
-
error instanceof TypeError) {
|
|
20
|
+
if (error instanceof CollectionError) {
|
|
21
21
|
throw error;
|
|
22
22
|
}
|
|
23
23
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
keys(
|
|
26
|
+
keys() {
|
|
27
27
|
try {
|
|
28
28
|
return new ListCollection(this.array.keys());
|
|
29
29
|
}
|
|
30
30
|
catch (error) {
|
|
31
|
-
if (error instanceof CollectionError
|
|
32
|
-
error instanceof TypeError) {
|
|
31
|
+
if (error instanceof CollectionError) {
|
|
33
32
|
throw error;
|
|
34
33
|
}
|
|
35
34
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -38,89 +37,81 @@ export class ListCollection {
|
|
|
38
37
|
values() {
|
|
39
38
|
return new ListCollection(this);
|
|
40
39
|
}
|
|
41
|
-
filter(predicateFn
|
|
40
|
+
filter(predicateFn) {
|
|
42
41
|
try {
|
|
43
42
|
return new ListCollection(this.array.filter((item, index) => predicateFn(item, index, this)));
|
|
44
43
|
}
|
|
45
44
|
catch (error) {
|
|
46
|
-
if (error instanceof CollectionError
|
|
47
|
-
error instanceof TypeError) {
|
|
45
|
+
if (error instanceof CollectionError) {
|
|
48
46
|
throw error;
|
|
49
47
|
}
|
|
50
48
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
|
-
reject(predicateFn
|
|
51
|
+
reject(predicateFn) {
|
|
54
52
|
try {
|
|
55
53
|
return new ListCollection(this.array.filter((item, index) => !predicateFn(item, index, this)));
|
|
56
54
|
}
|
|
57
55
|
catch (error) {
|
|
58
|
-
if (error instanceof CollectionError
|
|
59
|
-
error instanceof TypeError) {
|
|
56
|
+
if (error instanceof CollectionError) {
|
|
60
57
|
throw error;
|
|
61
58
|
}
|
|
62
59
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
|
-
map(mapFn
|
|
62
|
+
map(mapFn) {
|
|
66
63
|
try {
|
|
67
64
|
return new ListCollection(this.array.map((item, index) => mapFn(item, index, this)));
|
|
68
65
|
}
|
|
69
66
|
catch (error) {
|
|
70
|
-
if (error instanceof CollectionError
|
|
71
|
-
error instanceof TypeError) {
|
|
67
|
+
if (error instanceof CollectionError) {
|
|
72
68
|
throw error;
|
|
73
69
|
}
|
|
74
70
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
75
71
|
}
|
|
76
72
|
}
|
|
77
|
-
reduce(
|
|
73
|
+
reduce(reduceFn, initialValue) {
|
|
78
74
|
try {
|
|
79
|
-
if (
|
|
80
|
-
throw new
|
|
75
|
+
if (initialValue === undefined && this.isEmpty()) {
|
|
76
|
+
throw new TypeCollectionError("Reduce of empty array must be inputed a initial value");
|
|
81
77
|
}
|
|
82
|
-
if (
|
|
83
|
-
return this.array.reduce((initialValue, item, index) =>
|
|
78
|
+
if (initialValue !== undefined) {
|
|
79
|
+
return this.array.reduce((initialValue, item, index) => reduceFn(initialValue, item, index, this), initialValue);
|
|
84
80
|
}
|
|
85
81
|
return this.array.reduce((initialValue, item, index) => {
|
|
86
|
-
const reduce =
|
|
82
|
+
const reduce = reduceFn;
|
|
87
83
|
return reduce(initialValue, item, index, this);
|
|
88
84
|
});
|
|
89
85
|
}
|
|
90
86
|
catch (error) {
|
|
91
|
-
if (error instanceof CollectionError
|
|
92
|
-
error instanceof TypeError) {
|
|
87
|
+
if (error instanceof CollectionError) {
|
|
93
88
|
throw error;
|
|
94
89
|
}
|
|
95
90
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
96
91
|
}
|
|
97
92
|
}
|
|
98
|
-
join(
|
|
93
|
+
join(separator = ",") {
|
|
99
94
|
try {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return str + separator + item;
|
|
107
|
-
},
|
|
108
|
-
});
|
|
95
|
+
for (const item of this) {
|
|
96
|
+
if (typeof item !== "string") {
|
|
97
|
+
throw new TypeCollectionError("Item type is invalid must be string");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return this.array.join(separator);
|
|
109
101
|
}
|
|
110
102
|
catch (error) {
|
|
111
|
-
if (error instanceof CollectionError
|
|
112
|
-
error instanceof TypeError) {
|
|
103
|
+
if (error instanceof CollectionError) {
|
|
113
104
|
throw error;
|
|
114
105
|
}
|
|
115
106
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
116
107
|
}
|
|
117
108
|
}
|
|
118
109
|
collapse() {
|
|
119
|
-
const items = [];
|
|
120
110
|
try {
|
|
111
|
+
const items = [];
|
|
121
112
|
for (const item of this.array) {
|
|
122
113
|
if (isIterable(item)) {
|
|
123
|
-
items.push(...
|
|
114
|
+
items.push(...item);
|
|
124
115
|
}
|
|
125
116
|
else {
|
|
126
117
|
items.push(item);
|
|
@@ -129,28 +120,26 @@ export class ListCollection {
|
|
|
129
120
|
return new ListCollection(items);
|
|
130
121
|
}
|
|
131
122
|
catch (error) {
|
|
132
|
-
if (error instanceof CollectionError
|
|
133
|
-
error instanceof TypeError) {
|
|
123
|
+
if (error instanceof CollectionError) {
|
|
134
124
|
throw error;
|
|
135
125
|
}
|
|
136
126
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
137
127
|
}
|
|
138
128
|
}
|
|
139
|
-
flatMap(mapFn
|
|
129
|
+
flatMap(mapFn) {
|
|
140
130
|
try {
|
|
141
131
|
return new ListCollection(this.array.flatMap((item, index) => [
|
|
142
132
|
...mapFn(item, index, this),
|
|
143
133
|
]));
|
|
144
134
|
}
|
|
145
135
|
catch (error) {
|
|
146
|
-
if (error instanceof CollectionError
|
|
147
|
-
error instanceof TypeError) {
|
|
136
|
+
if (error instanceof CollectionError) {
|
|
148
137
|
throw error;
|
|
149
138
|
}
|
|
150
139
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
151
140
|
}
|
|
152
141
|
}
|
|
153
|
-
|
|
142
|
+
change(predicateFn, mapFn) {
|
|
154
143
|
try {
|
|
155
144
|
return new ListCollection(this.array.map((item, index) => {
|
|
156
145
|
if (predicateFn(item, index, this)) {
|
|
@@ -160,39 +149,43 @@ export class ListCollection {
|
|
|
160
149
|
}));
|
|
161
150
|
}
|
|
162
151
|
catch (error) {
|
|
163
|
-
if (error instanceof CollectionError
|
|
164
|
-
error instanceof TypeError) {
|
|
152
|
+
if (error instanceof CollectionError) {
|
|
165
153
|
throw error;
|
|
166
154
|
}
|
|
167
155
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
168
156
|
}
|
|
169
157
|
}
|
|
170
|
-
page(
|
|
171
|
-
const { page, pageSize } = settings;
|
|
158
|
+
page(page, pageSize) {
|
|
172
159
|
if (page < 0) {
|
|
173
160
|
return this.skip(page * pageSize).take(pageSize);
|
|
174
161
|
}
|
|
175
|
-
return this.skip((page - 1) * pageSize).take(
|
|
162
|
+
return this.skip((page - 1) * pageSize).take(pageSize);
|
|
176
163
|
}
|
|
177
164
|
sum() {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
});
|
|
165
|
+
if (this.isEmpty()) {
|
|
166
|
+
throw new EmptyCollectionError("Collection is empty therby operation cannot be performed");
|
|
167
|
+
}
|
|
168
|
+
return this.reduce((sum, item) => {
|
|
169
|
+
if (typeof item !== "number") {
|
|
170
|
+
throw new TypeCollectionError("Item type is invalid must be number");
|
|
171
|
+
}
|
|
172
|
+
return sum + item;
|
|
173
|
+
}, 0);
|
|
187
174
|
}
|
|
188
175
|
average() {
|
|
176
|
+
if (this.isEmpty()) {
|
|
177
|
+
throw new EmptyCollectionError("Collection is empty therby operation cannot be performed");
|
|
178
|
+
}
|
|
189
179
|
return (this.sum() / this.size());
|
|
190
180
|
}
|
|
191
|
-
median(
|
|
181
|
+
median() {
|
|
192
182
|
try {
|
|
183
|
+
if (this.isEmpty()) {
|
|
184
|
+
throw new EmptyCollectionError("Collection is empty therby operation cannot be performed");
|
|
185
|
+
}
|
|
193
186
|
const nbrs = this.array.map((item) => {
|
|
194
187
|
if (typeof item !== "number") {
|
|
195
|
-
throw new
|
|
188
|
+
throw new TypeCollectionError("Item type is invalid must be number");
|
|
196
189
|
}
|
|
197
190
|
return item;
|
|
198
191
|
}), index = Math.floor(this.array.length / 2), isEven = this.array.length % 2 === 0, a = nbrs[index];
|
|
@@ -209,8 +202,7 @@ export class ListCollection {
|
|
|
209
202
|
return a;
|
|
210
203
|
}
|
|
211
204
|
catch (error) {
|
|
212
|
-
if (error instanceof CollectionError
|
|
213
|
-
error instanceof TypeError) {
|
|
205
|
+
if (error instanceof CollectionError) {
|
|
214
206
|
throw error;
|
|
215
207
|
}
|
|
216
208
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -218,10 +210,13 @@ export class ListCollection {
|
|
|
218
210
|
}
|
|
219
211
|
min() {
|
|
220
212
|
try {
|
|
213
|
+
if (this.isEmpty()) {
|
|
214
|
+
throw new EmptyCollectionError("Collection is empty therby operation cannot be performed");
|
|
215
|
+
}
|
|
221
216
|
let min = 0;
|
|
222
217
|
for (const item of this.array) {
|
|
223
218
|
if (typeof item !== "number") {
|
|
224
|
-
throw new
|
|
219
|
+
throw new TypeCollectionError("Item type is invalid must be number");
|
|
225
220
|
}
|
|
226
221
|
if (min === 0) {
|
|
227
222
|
min = item;
|
|
@@ -233,8 +228,7 @@ export class ListCollection {
|
|
|
233
228
|
return min;
|
|
234
229
|
}
|
|
235
230
|
catch (error) {
|
|
236
|
-
if (error instanceof CollectionError
|
|
237
|
-
error instanceof TypeError) {
|
|
231
|
+
if (error instanceof CollectionError) {
|
|
238
232
|
throw error;
|
|
239
233
|
}
|
|
240
234
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -242,10 +236,13 @@ export class ListCollection {
|
|
|
242
236
|
}
|
|
243
237
|
max() {
|
|
244
238
|
try {
|
|
239
|
+
if (this.isEmpty()) {
|
|
240
|
+
throw new EmptyCollectionError("Collection is empty therby operation cannot be performed");
|
|
241
|
+
}
|
|
245
242
|
let max = 0;
|
|
246
243
|
for (const item of this.array) {
|
|
247
244
|
if (typeof item !== "number") {
|
|
248
|
-
throw new
|
|
245
|
+
throw new TypeCollectionError("Item type is invalid must be number");
|
|
249
246
|
}
|
|
250
247
|
if (max === 0) {
|
|
251
248
|
max = item;
|
|
@@ -257,62 +254,60 @@ export class ListCollection {
|
|
|
257
254
|
return max;
|
|
258
255
|
}
|
|
259
256
|
catch (error) {
|
|
260
|
-
if (error instanceof CollectionError
|
|
261
|
-
error instanceof TypeError) {
|
|
257
|
+
if (error instanceof CollectionError) {
|
|
262
258
|
throw error;
|
|
263
259
|
}
|
|
264
260
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
265
261
|
}
|
|
266
262
|
}
|
|
267
|
-
percentage(predicateFn
|
|
263
|
+
percentage(predicateFn) {
|
|
268
264
|
try {
|
|
265
|
+
if (this.isEmpty()) {
|
|
266
|
+
throw new EmptyCollectionError("Collection is empty therby operation cannot be performed");
|
|
267
|
+
}
|
|
269
268
|
return (this.count(predicateFn) / this.size()) * 100;
|
|
270
269
|
}
|
|
271
270
|
catch (error) {
|
|
272
|
-
if (error instanceof CollectionError
|
|
273
|
-
error instanceof TypeError) {
|
|
271
|
+
if (error instanceof CollectionError) {
|
|
274
272
|
throw error;
|
|
275
273
|
}
|
|
276
274
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
277
275
|
}
|
|
278
276
|
}
|
|
279
|
-
some(predicateFn
|
|
277
|
+
some(predicateFn) {
|
|
280
278
|
try {
|
|
281
279
|
return this.array.some((item, index) => predicateFn(item, index, this));
|
|
282
280
|
}
|
|
283
281
|
catch (error) {
|
|
284
|
-
if (error instanceof CollectionError
|
|
285
|
-
error instanceof TypeError) {
|
|
282
|
+
if (error instanceof CollectionError) {
|
|
286
283
|
throw error;
|
|
287
284
|
}
|
|
288
285
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
289
286
|
}
|
|
290
287
|
}
|
|
291
|
-
every(predicateFn
|
|
288
|
+
every(predicateFn) {
|
|
292
289
|
try {
|
|
293
290
|
return this.array.every((item, index) => predicateFn(item, index, this));
|
|
294
291
|
}
|
|
295
292
|
catch (error) {
|
|
296
|
-
if (error instanceof CollectionError
|
|
297
|
-
error instanceof TypeError) {
|
|
293
|
+
if (error instanceof CollectionError) {
|
|
298
294
|
throw error;
|
|
299
295
|
}
|
|
300
296
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
301
297
|
}
|
|
302
298
|
}
|
|
303
|
-
take(limit
|
|
299
|
+
take(limit) {
|
|
304
300
|
try {
|
|
305
301
|
return new ListCollection(this.array.slice(0, limit));
|
|
306
302
|
}
|
|
307
303
|
catch (error) {
|
|
308
|
-
if (error instanceof CollectionError
|
|
309
|
-
error instanceof TypeError) {
|
|
304
|
+
if (error instanceof CollectionError) {
|
|
310
305
|
throw error;
|
|
311
306
|
}
|
|
312
307
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
313
308
|
}
|
|
314
309
|
}
|
|
315
|
-
takeUntil(predicateFn
|
|
310
|
+
takeUntil(predicateFn) {
|
|
316
311
|
try {
|
|
317
312
|
const items = [];
|
|
318
313
|
for (const [index, item] of this.array.entries()) {
|
|
@@ -324,38 +319,35 @@ export class ListCollection {
|
|
|
324
319
|
return new ListCollection(items);
|
|
325
320
|
}
|
|
326
321
|
catch (error) {
|
|
327
|
-
if (error instanceof CollectionError
|
|
328
|
-
error instanceof TypeError) {
|
|
322
|
+
if (error instanceof CollectionError) {
|
|
329
323
|
throw error;
|
|
330
324
|
}
|
|
331
325
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
332
326
|
}
|
|
333
327
|
}
|
|
334
|
-
takeWhile(predicateFn
|
|
328
|
+
takeWhile(predicateFn) {
|
|
335
329
|
try {
|
|
336
330
|
return this.takeUntil((...arguments_) => !predicateFn(...arguments_));
|
|
337
331
|
}
|
|
338
332
|
catch (error) {
|
|
339
|
-
if (error instanceof CollectionError
|
|
340
|
-
error instanceof TypeError) {
|
|
333
|
+
if (error instanceof CollectionError) {
|
|
341
334
|
throw error;
|
|
342
335
|
}
|
|
343
336
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
344
337
|
}
|
|
345
338
|
}
|
|
346
|
-
skip(offset
|
|
339
|
+
skip(offset) {
|
|
347
340
|
try {
|
|
348
341
|
return new ListCollection(this.array.slice(offset));
|
|
349
342
|
}
|
|
350
343
|
catch (error) {
|
|
351
|
-
if (error instanceof CollectionError
|
|
352
|
-
error instanceof TypeError) {
|
|
344
|
+
if (error instanceof CollectionError) {
|
|
353
345
|
throw error;
|
|
354
346
|
}
|
|
355
347
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
356
348
|
}
|
|
357
349
|
}
|
|
358
|
-
skipUntil(predicateFn
|
|
350
|
+
skipUntil(predicateFn) {
|
|
359
351
|
try {
|
|
360
352
|
let hasMatched = false;
|
|
361
353
|
const items = [];
|
|
@@ -370,20 +362,18 @@ export class ListCollection {
|
|
|
370
362
|
return new ListCollection(items);
|
|
371
363
|
}
|
|
372
364
|
catch (error) {
|
|
373
|
-
if (error instanceof CollectionError
|
|
374
|
-
error instanceof TypeError) {
|
|
365
|
+
if (error instanceof CollectionError) {
|
|
375
366
|
throw error;
|
|
376
367
|
}
|
|
377
368
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
378
369
|
}
|
|
379
370
|
}
|
|
380
|
-
skipWhile(predicateFn
|
|
371
|
+
skipWhile(predicateFn) {
|
|
381
372
|
try {
|
|
382
373
|
return this.skipUntil((...arguments_) => !predicateFn(...arguments_));
|
|
383
374
|
}
|
|
384
375
|
catch (error) {
|
|
385
|
-
if (error instanceof CollectionError
|
|
386
|
-
error instanceof TypeError) {
|
|
376
|
+
if (error instanceof CollectionError) {
|
|
387
377
|
throw error;
|
|
388
378
|
}
|
|
389
379
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -397,8 +387,7 @@ export class ListCollection {
|
|
|
397
387
|
return this;
|
|
398
388
|
}
|
|
399
389
|
catch (error) {
|
|
400
|
-
if (error instanceof CollectionError
|
|
401
|
-
error instanceof TypeError) {
|
|
390
|
+
if (error instanceof CollectionError) {
|
|
402
391
|
throw error;
|
|
403
392
|
}
|
|
404
393
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -409,8 +398,7 @@ export class ListCollection {
|
|
|
409
398
|
return this.when(this.isEmpty(), callback);
|
|
410
399
|
}
|
|
411
400
|
catch (error) {
|
|
412
|
-
if (error instanceof CollectionError
|
|
413
|
-
error instanceof TypeError) {
|
|
401
|
+
if (error instanceof CollectionError) {
|
|
414
402
|
throw error;
|
|
415
403
|
}
|
|
416
404
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -421,8 +409,7 @@ export class ListCollection {
|
|
|
421
409
|
return this.when(!condition, callback);
|
|
422
410
|
}
|
|
423
411
|
catch (error) {
|
|
424
|
-
if (error instanceof CollectionError
|
|
425
|
-
error instanceof TypeError) {
|
|
412
|
+
if (error instanceof CollectionError) {
|
|
426
413
|
throw error;
|
|
427
414
|
}
|
|
428
415
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -433,8 +420,7 @@ export class ListCollection {
|
|
|
433
420
|
return this.when(this.isNotEmpty(), callback);
|
|
434
421
|
}
|
|
435
422
|
catch (error) {
|
|
436
|
-
if (error instanceof CollectionError
|
|
437
|
-
error instanceof TypeError) {
|
|
423
|
+
if (error instanceof CollectionError) {
|
|
438
424
|
throw error;
|
|
439
425
|
}
|
|
440
426
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -445,8 +431,7 @@ export class ListCollection {
|
|
|
445
431
|
return callback(this);
|
|
446
432
|
}
|
|
447
433
|
catch (error) {
|
|
448
|
-
if (error instanceof CollectionError
|
|
449
|
-
error instanceof TypeError) {
|
|
434
|
+
if (error instanceof CollectionError) {
|
|
450
435
|
throw error;
|
|
451
436
|
}
|
|
452
437
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -458,8 +443,7 @@ export class ListCollection {
|
|
|
458
443
|
return new ListCollection(this);
|
|
459
444
|
}
|
|
460
445
|
catch (error) {
|
|
461
|
-
if (error instanceof CollectionError
|
|
462
|
-
error instanceof TypeError) {
|
|
446
|
+
if (error instanceof CollectionError) {
|
|
463
447
|
throw error;
|
|
464
448
|
}
|
|
465
449
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -474,14 +458,13 @@ export class ListCollection {
|
|
|
474
458
|
return new ListCollection(chunks);
|
|
475
459
|
}
|
|
476
460
|
catch (error) {
|
|
477
|
-
if (error instanceof CollectionError
|
|
478
|
-
error instanceof TypeError) {
|
|
461
|
+
if (error instanceof CollectionError) {
|
|
479
462
|
throw error;
|
|
480
463
|
}
|
|
481
464
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
482
465
|
}
|
|
483
466
|
}
|
|
484
|
-
chunkWhile(predicateFn
|
|
467
|
+
chunkWhile(predicateFn) {
|
|
485
468
|
try {
|
|
486
469
|
let currentChunk = new ListCollection([]);
|
|
487
470
|
const chunks = [];
|
|
@@ -501,14 +484,13 @@ export class ListCollection {
|
|
|
501
484
|
return new ListCollection(chunks);
|
|
502
485
|
}
|
|
503
486
|
catch (error) {
|
|
504
|
-
if (error instanceof CollectionError
|
|
505
|
-
error instanceof TypeError) {
|
|
487
|
+
if (error instanceof CollectionError) {
|
|
506
488
|
throw error;
|
|
507
489
|
}
|
|
508
490
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
509
491
|
}
|
|
510
492
|
}
|
|
511
|
-
split(chunkAmount
|
|
493
|
+
split(chunkAmount) {
|
|
512
494
|
try {
|
|
513
495
|
const size = this.size(), minChunkSize = Math.floor(size / chunkAmount), restSize = size % chunkAmount, chunkSizes = Array.from({
|
|
514
496
|
length: chunkAmount,
|
|
@@ -529,14 +511,13 @@ export class ListCollection {
|
|
|
529
511
|
return new ListCollection(chunks);
|
|
530
512
|
}
|
|
531
513
|
catch (error) {
|
|
532
|
-
if (error instanceof CollectionError
|
|
533
|
-
error instanceof TypeError) {
|
|
514
|
+
if (error instanceof CollectionError) {
|
|
534
515
|
throw error;
|
|
535
516
|
}
|
|
536
517
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
537
518
|
}
|
|
538
519
|
}
|
|
539
|
-
partition(predicateFn
|
|
520
|
+
partition(predicateFn) {
|
|
540
521
|
try {
|
|
541
522
|
const chunkA = [], chunkB = [];
|
|
542
523
|
for (const [index, item] of this.array.entries()) {
|
|
@@ -553,16 +534,14 @@ export class ListCollection {
|
|
|
553
534
|
]);
|
|
554
535
|
}
|
|
555
536
|
catch (error) {
|
|
556
|
-
if (error instanceof CollectionError
|
|
557
|
-
error instanceof TypeError) {
|
|
537
|
+
if (error instanceof CollectionError) {
|
|
558
538
|
throw error;
|
|
559
539
|
}
|
|
560
540
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
561
541
|
}
|
|
562
542
|
}
|
|
563
|
-
sliding(
|
|
543
|
+
sliding(chunkSize, step = chunkSize - 1) {
|
|
564
544
|
try {
|
|
565
|
-
const { chunkSize, step = chunkSize - 1 } = settings;
|
|
566
545
|
let chunks = new ListCollection([]);
|
|
567
546
|
if (step <= 0) {
|
|
568
547
|
return new ListCollection([]);
|
|
@@ -570,12 +549,7 @@ export class ListCollection {
|
|
|
570
549
|
for (let index = 0; index < this.size(); index += step) {
|
|
571
550
|
const start = index;
|
|
572
551
|
const end = index + chunkSize;
|
|
573
|
-
chunks = chunks.append([
|
|
574
|
-
this.slice({
|
|
575
|
-
start,
|
|
576
|
-
end,
|
|
577
|
-
}),
|
|
578
|
-
]);
|
|
552
|
+
chunks = chunks.append([this.slice(start, end)]);
|
|
579
553
|
if (end >= this.size()) {
|
|
580
554
|
break;
|
|
581
555
|
}
|
|
@@ -583,18 +557,17 @@ export class ListCollection {
|
|
|
583
557
|
return chunks;
|
|
584
558
|
}
|
|
585
559
|
catch (error) {
|
|
586
|
-
if (error instanceof CollectionError
|
|
587
|
-
error instanceof TypeError) {
|
|
560
|
+
if (error instanceof CollectionError) {
|
|
588
561
|
throw error;
|
|
589
562
|
}
|
|
590
563
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
591
564
|
}
|
|
592
565
|
}
|
|
593
|
-
groupBy(
|
|
566
|
+
groupBy(selectFn = (item) => item) {
|
|
594
567
|
try {
|
|
595
|
-
const map = new Map()
|
|
568
|
+
const map = new Map();
|
|
596
569
|
for (const [index, item] of this.array.entries()) {
|
|
597
|
-
const key =
|
|
570
|
+
const key = selectFn(item, index, this);
|
|
598
571
|
let collection = map.get(key);
|
|
599
572
|
if (collection === undefined) {
|
|
600
573
|
collection = new ListCollection([]);
|
|
@@ -605,18 +578,17 @@ export class ListCollection {
|
|
|
605
578
|
return new ListCollection(map);
|
|
606
579
|
}
|
|
607
580
|
catch (error) {
|
|
608
|
-
if (error instanceof CollectionError
|
|
609
|
-
error instanceof TypeError) {
|
|
581
|
+
if (error instanceof CollectionError) {
|
|
610
582
|
throw error;
|
|
611
583
|
}
|
|
612
584
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
613
585
|
}
|
|
614
586
|
}
|
|
615
|
-
countBy(
|
|
587
|
+
countBy(selectFn = (item) => item) {
|
|
616
588
|
try {
|
|
617
|
-
const map = new Map()
|
|
589
|
+
const map = new Map();
|
|
618
590
|
for (const [index, item] of this.array.entries()) {
|
|
619
|
-
const key =
|
|
591
|
+
const key = selectFn(item, index, this);
|
|
620
592
|
if (!map.has(key)) {
|
|
621
593
|
map.set(key, 0);
|
|
622
594
|
}
|
|
@@ -628,18 +600,17 @@ export class ListCollection {
|
|
|
628
600
|
return new ListCollection(map);
|
|
629
601
|
}
|
|
630
602
|
catch (error) {
|
|
631
|
-
if (error instanceof CollectionError
|
|
632
|
-
error instanceof TypeError) {
|
|
603
|
+
if (error instanceof CollectionError) {
|
|
633
604
|
throw error;
|
|
634
605
|
}
|
|
635
606
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
636
607
|
}
|
|
637
608
|
}
|
|
638
|
-
unique(
|
|
609
|
+
unique(selectFn = (item) => item) {
|
|
639
610
|
try {
|
|
640
|
-
const set = new Set([]),
|
|
611
|
+
const set = new Set([]), items = [];
|
|
641
612
|
for (const [index, item] of this.array.entries()) {
|
|
642
|
-
const item_ =
|
|
613
|
+
const item_ = selectFn(item, index, this);
|
|
643
614
|
if (!set.has(item_)) {
|
|
644
615
|
items.push(item);
|
|
645
616
|
}
|
|
@@ -648,8 +619,7 @@ export class ListCollection {
|
|
|
648
619
|
return new ListCollection(items);
|
|
649
620
|
}
|
|
650
621
|
catch (error) {
|
|
651
|
-
if (error instanceof CollectionError
|
|
652
|
-
error instanceof TypeError) {
|
|
622
|
+
if (error instanceof CollectionError) {
|
|
653
623
|
throw error;
|
|
654
624
|
}
|
|
655
625
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -666,8 +636,7 @@ export class ListCollection {
|
|
|
666
636
|
});
|
|
667
637
|
}
|
|
668
638
|
catch (error) {
|
|
669
|
-
if (error instanceof CollectionError
|
|
670
|
-
error instanceof TypeError) {
|
|
639
|
+
if (error instanceof CollectionError) {
|
|
671
640
|
throw error;
|
|
672
641
|
}
|
|
673
642
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -676,14 +645,13 @@ export class ListCollection {
|
|
|
676
645
|
repeat(amount) {
|
|
677
646
|
try {
|
|
678
647
|
let collection = new ListCollection([]);
|
|
679
|
-
for (let index = 0; index < amount
|
|
648
|
+
for (let index = 0; index < amount; index++) {
|
|
680
649
|
collection = collection.append(this);
|
|
681
650
|
}
|
|
682
651
|
return collection;
|
|
683
652
|
}
|
|
684
653
|
catch (error) {
|
|
685
|
-
if (error instanceof CollectionError
|
|
686
|
-
error instanceof TypeError) {
|
|
654
|
+
if (error instanceof CollectionError) {
|
|
687
655
|
throw error;
|
|
688
656
|
}
|
|
689
657
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -709,8 +677,7 @@ export class ListCollection {
|
|
|
709
677
|
return new ListCollection(resultItemsArray);
|
|
710
678
|
}
|
|
711
679
|
catch (error) {
|
|
712
|
-
if (error instanceof CollectionError
|
|
713
|
-
error instanceof TypeError) {
|
|
680
|
+
if (error instanceof CollectionError) {
|
|
714
681
|
throw error;
|
|
715
682
|
}
|
|
716
683
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -736,20 +703,18 @@ export class ListCollection {
|
|
|
736
703
|
return new ListCollection(resultItemsArray);
|
|
737
704
|
}
|
|
738
705
|
catch (error) {
|
|
739
|
-
if (error instanceof CollectionError
|
|
740
|
-
error instanceof TypeError) {
|
|
706
|
+
if (error instanceof CollectionError) {
|
|
741
707
|
throw error;
|
|
742
708
|
}
|
|
743
709
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
744
710
|
}
|
|
745
711
|
}
|
|
746
|
-
slice(
|
|
712
|
+
slice(start, end) {
|
|
747
713
|
try {
|
|
748
|
-
return new ListCollection(this.array.slice(
|
|
714
|
+
return new ListCollection(this.array.slice(start, end));
|
|
749
715
|
}
|
|
750
716
|
catch (error) {
|
|
751
|
-
if (error instanceof CollectionError
|
|
752
|
-
error instanceof TypeError) {
|
|
717
|
+
if (error instanceof CollectionError) {
|
|
753
718
|
throw error;
|
|
754
719
|
}
|
|
755
720
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -760,8 +725,7 @@ export class ListCollection {
|
|
|
760
725
|
return new ListCollection([...iterable, ...this.array]);
|
|
761
726
|
}
|
|
762
727
|
catch (error) {
|
|
763
|
-
if (error instanceof CollectionError
|
|
764
|
-
error instanceof TypeError) {
|
|
728
|
+
if (error instanceof CollectionError) {
|
|
765
729
|
throw error;
|
|
766
730
|
}
|
|
767
731
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -772,14 +736,13 @@ export class ListCollection {
|
|
|
772
736
|
return new ListCollection([...this.array, ...iterable]);
|
|
773
737
|
}
|
|
774
738
|
catch (error) {
|
|
775
|
-
if (error instanceof CollectionError
|
|
776
|
-
error instanceof TypeError) {
|
|
739
|
+
if (error instanceof CollectionError) {
|
|
777
740
|
throw error;
|
|
778
741
|
}
|
|
779
742
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
780
743
|
}
|
|
781
744
|
}
|
|
782
|
-
insertBefore(predicateFn, iterable
|
|
745
|
+
insertBefore(predicateFn, iterable) {
|
|
783
746
|
try {
|
|
784
747
|
const index = this.array.findIndex((item, index) => predicateFn(item, index, this));
|
|
785
748
|
if (index === -1) {
|
|
@@ -790,14 +753,13 @@ export class ListCollection {
|
|
|
790
753
|
return new ListCollection(newArray);
|
|
791
754
|
}
|
|
792
755
|
catch (error) {
|
|
793
|
-
if (error instanceof CollectionError
|
|
794
|
-
error instanceof TypeError) {
|
|
756
|
+
if (error instanceof CollectionError) {
|
|
795
757
|
throw error;
|
|
796
758
|
}
|
|
797
759
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
798
760
|
}
|
|
799
761
|
}
|
|
800
|
-
insertAfter(predicateFn, iterable
|
|
762
|
+
insertAfter(predicateFn, iterable) {
|
|
801
763
|
try {
|
|
802
764
|
const index = this.array.findIndex((item, index) => predicateFn(item, index, this));
|
|
803
765
|
if (index === -1) {
|
|
@@ -811,35 +773,39 @@ export class ListCollection {
|
|
|
811
773
|
]);
|
|
812
774
|
}
|
|
813
775
|
catch (error) {
|
|
814
|
-
if (error instanceof CollectionError
|
|
815
|
-
error instanceof TypeError) {
|
|
776
|
+
if (error instanceof CollectionError) {
|
|
816
777
|
throw error;
|
|
817
778
|
}
|
|
818
779
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
819
780
|
}
|
|
820
781
|
}
|
|
821
|
-
crossJoin(
|
|
782
|
+
crossJoin(iterable) {
|
|
822
783
|
try {
|
|
823
|
-
|
|
824
|
-
this,
|
|
825
|
-
...
|
|
826
|
-
]
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
.reduce({
|
|
833
|
-
reduceFn: (c, b) => c.append(b),
|
|
834
|
-
initialValue: new ListCollection([]),
|
|
784
|
+
const array = [
|
|
785
|
+
[...this],
|
|
786
|
+
[...iterable],
|
|
787
|
+
]
|
|
788
|
+
.reduce((a, b) => {
|
|
789
|
+
return a
|
|
790
|
+
.map((x) => {
|
|
791
|
+
return b.map((y) => {
|
|
792
|
+
return [...x, y];
|
|
835
793
|
});
|
|
836
|
-
}
|
|
837
|
-
|
|
794
|
+
})
|
|
795
|
+
.reduce((c, b) => [...c, ...b], []);
|
|
796
|
+
}, [[]])
|
|
797
|
+
.map((combination) => {
|
|
798
|
+
return combination.reduce((a, b) => {
|
|
799
|
+
return [
|
|
800
|
+
...a,
|
|
801
|
+
...(isIterable(b) ? b : [b]),
|
|
802
|
+
];
|
|
803
|
+
}, []);
|
|
838
804
|
});
|
|
805
|
+
return new ListCollection(array);
|
|
839
806
|
}
|
|
840
807
|
catch (error) {
|
|
841
|
-
if (error instanceof CollectionError
|
|
842
|
-
error instanceof TypeError) {
|
|
808
|
+
if (error instanceof CollectionError) {
|
|
843
809
|
throw error;
|
|
844
810
|
}
|
|
845
811
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -863,8 +829,7 @@ export class ListCollection {
|
|
|
863
829
|
return new ListCollection(items);
|
|
864
830
|
}
|
|
865
831
|
catch (error) {
|
|
866
|
-
if (error instanceof CollectionError
|
|
867
|
-
error instanceof TypeError) {
|
|
832
|
+
if (error instanceof CollectionError) {
|
|
868
833
|
throw error;
|
|
869
834
|
}
|
|
870
835
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -875,30 +840,28 @@ export class ListCollection {
|
|
|
875
840
|
return new ListCollection(this.array.sort(comparator));
|
|
876
841
|
}
|
|
877
842
|
catch (error) {
|
|
878
|
-
if (error instanceof CollectionError
|
|
879
|
-
error instanceof TypeError) {
|
|
843
|
+
if (error instanceof CollectionError) {
|
|
880
844
|
throw error;
|
|
881
845
|
}
|
|
882
846
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
883
847
|
}
|
|
884
848
|
}
|
|
885
|
-
reverse(
|
|
849
|
+
reverse(_chunkSize) {
|
|
886
850
|
try {
|
|
887
851
|
return new ListCollection([...this.array].reverse());
|
|
888
852
|
}
|
|
889
853
|
catch (error) {
|
|
890
|
-
if (error instanceof CollectionError
|
|
891
|
-
error instanceof TypeError) {
|
|
854
|
+
if (error instanceof CollectionError) {
|
|
892
855
|
throw error;
|
|
893
856
|
}
|
|
894
857
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
895
858
|
}
|
|
896
859
|
}
|
|
897
|
-
shuffle() {
|
|
860
|
+
shuffle(mathRandom = Math.random) {
|
|
898
861
|
try {
|
|
899
862
|
const newArray = [...this.array];
|
|
900
863
|
for (let i = newArray.length - 1; i > 0; i--) {
|
|
901
|
-
const j = Math.floor(
|
|
864
|
+
const j = Math.floor(mathRandom() * (i + 1));
|
|
902
865
|
const temp = newArray[i];
|
|
903
866
|
if (newArray[j] !== undefined) {
|
|
904
867
|
newArray[i] = newArray[j];
|
|
@@ -910,34 +873,28 @@ export class ListCollection {
|
|
|
910
873
|
return new ListCollection(newArray);
|
|
911
874
|
}
|
|
912
875
|
catch (error) {
|
|
913
|
-
if (error instanceof CollectionError
|
|
914
|
-
error instanceof TypeError) {
|
|
876
|
+
if (error instanceof CollectionError) {
|
|
915
877
|
throw error;
|
|
916
878
|
}
|
|
917
879
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
918
880
|
}
|
|
919
881
|
}
|
|
920
|
-
first(
|
|
882
|
+
first(predicateFn) {
|
|
921
883
|
try {
|
|
922
|
-
return this.firstOr(
|
|
923
|
-
defaultValue: null,
|
|
924
|
-
...settings,
|
|
925
|
-
});
|
|
884
|
+
return this.firstOr(null, predicateFn);
|
|
926
885
|
}
|
|
927
886
|
catch (error) {
|
|
928
|
-
if (error instanceof CollectionError
|
|
929
|
-
error instanceof TypeError) {
|
|
887
|
+
if (error instanceof CollectionError) {
|
|
930
888
|
throw error;
|
|
931
889
|
}
|
|
932
890
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
933
891
|
}
|
|
934
892
|
}
|
|
935
|
-
firstOr(
|
|
893
|
+
firstOr(defaultValue, predicateFn) {
|
|
936
894
|
try {
|
|
937
|
-
|
|
938
|
-
if (filter) {
|
|
895
|
+
if (predicateFn) {
|
|
939
896
|
for (const [index, item] of this.array.entries()) {
|
|
940
|
-
if (
|
|
897
|
+
if (predicateFn(item, index, this)) {
|
|
941
898
|
return item;
|
|
942
899
|
}
|
|
943
900
|
}
|
|
@@ -948,59 +905,47 @@ export class ListCollection {
|
|
|
948
905
|
return firstItem;
|
|
949
906
|
}
|
|
950
907
|
}
|
|
951
|
-
|
|
952
|
-
if (typeof defaultValue === "function") {
|
|
953
|
-
const defaultFn = defaultValue;
|
|
954
|
-
return defaultFn();
|
|
955
|
-
}
|
|
956
|
-
return defaultValue;
|
|
908
|
+
return simplifyLazyable(defaultValue);
|
|
957
909
|
}
|
|
958
910
|
catch (error) {
|
|
959
|
-
if (error instanceof CollectionError
|
|
960
|
-
error instanceof TypeError) {
|
|
911
|
+
if (error instanceof CollectionError) {
|
|
961
912
|
throw error;
|
|
962
913
|
}
|
|
963
914
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
964
915
|
}
|
|
965
916
|
}
|
|
966
|
-
firstOrFail(
|
|
917
|
+
firstOrFail(predicateFn) {
|
|
967
918
|
try {
|
|
968
|
-
const item = this.first(
|
|
919
|
+
const item = this.first(predicateFn);
|
|
969
920
|
if (item === null) {
|
|
970
|
-
throw new
|
|
921
|
+
throw new ItemNotFoundCollectionError("Item was not found");
|
|
971
922
|
}
|
|
972
923
|
return item;
|
|
973
924
|
}
|
|
974
925
|
catch (error) {
|
|
975
|
-
if (error instanceof CollectionError
|
|
976
|
-
error instanceof TypeError) {
|
|
926
|
+
if (error instanceof CollectionError) {
|
|
977
927
|
throw error;
|
|
978
928
|
}
|
|
979
929
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
980
930
|
}
|
|
981
931
|
}
|
|
982
|
-
last(
|
|
932
|
+
last(predicateFn) {
|
|
983
933
|
try {
|
|
984
|
-
return this.lastOr(
|
|
985
|
-
...settings,
|
|
986
|
-
defaultValue: null,
|
|
987
|
-
});
|
|
934
|
+
return this.lastOr(null, predicateFn);
|
|
988
935
|
}
|
|
989
936
|
catch (error) {
|
|
990
|
-
if (error instanceof CollectionError
|
|
991
|
-
error instanceof TypeError) {
|
|
937
|
+
if (error instanceof CollectionError) {
|
|
992
938
|
throw error;
|
|
993
939
|
}
|
|
994
940
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
995
941
|
}
|
|
996
942
|
}
|
|
997
|
-
lastOr(
|
|
943
|
+
lastOr(defaultValue, predicateFn) {
|
|
998
944
|
try {
|
|
999
|
-
|
|
1000
|
-
if (filter) {
|
|
945
|
+
if (predicateFn) {
|
|
1001
946
|
let matchedItem = null;
|
|
1002
947
|
for (const [index, item] of this.array.entries()) {
|
|
1003
|
-
if (
|
|
948
|
+
if (predicateFn(item, index, this)) {
|
|
1004
949
|
matchedItem = item;
|
|
1005
950
|
}
|
|
1006
951
|
}
|
|
@@ -1014,50 +959,42 @@ export class ListCollection {
|
|
|
1014
959
|
return lastItem;
|
|
1015
960
|
}
|
|
1016
961
|
}
|
|
1017
|
-
|
|
1018
|
-
if (typeof defaultValue === "function") {
|
|
1019
|
-
const defaultFn = defaultValue;
|
|
1020
|
-
return defaultFn();
|
|
1021
|
-
}
|
|
1022
|
-
return defaultValue;
|
|
962
|
+
return simplifyLazyable(defaultValue);
|
|
1023
963
|
}
|
|
1024
964
|
catch (error) {
|
|
1025
|
-
if (error instanceof CollectionError
|
|
1026
|
-
error instanceof TypeError) {
|
|
965
|
+
if (error instanceof CollectionError) {
|
|
1027
966
|
throw error;
|
|
1028
967
|
}
|
|
1029
968
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
1030
969
|
}
|
|
1031
970
|
}
|
|
1032
|
-
lastOrFail(
|
|
971
|
+
lastOrFail(predicateFn) {
|
|
1033
972
|
try {
|
|
1034
|
-
const item = this.last(
|
|
973
|
+
const item = this.last(predicateFn);
|
|
1035
974
|
if (item === null) {
|
|
1036
|
-
throw new
|
|
975
|
+
throw new ItemNotFoundCollectionError("Item was not found");
|
|
1037
976
|
}
|
|
1038
977
|
return item;
|
|
1039
978
|
}
|
|
1040
979
|
catch (error) {
|
|
1041
|
-
if (error instanceof CollectionError
|
|
1042
|
-
error instanceof TypeError) {
|
|
980
|
+
if (error instanceof CollectionError) {
|
|
1043
981
|
throw error;
|
|
1044
982
|
}
|
|
1045
983
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
1046
984
|
}
|
|
1047
985
|
}
|
|
1048
|
-
before(predicateFn
|
|
986
|
+
before(predicateFn) {
|
|
1049
987
|
try {
|
|
1050
988
|
return this.beforeOr(null, predicateFn);
|
|
1051
989
|
}
|
|
1052
990
|
catch (error) {
|
|
1053
|
-
if (error instanceof CollectionError
|
|
1054
|
-
error instanceof TypeError) {
|
|
991
|
+
if (error instanceof CollectionError) {
|
|
1055
992
|
throw error;
|
|
1056
993
|
}
|
|
1057
994
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
1058
995
|
}
|
|
1059
996
|
}
|
|
1060
|
-
beforeOr(defaultValue, predicateFn
|
|
997
|
+
beforeOr(defaultValue, predicateFn) {
|
|
1061
998
|
try {
|
|
1062
999
|
for (const [index, item] of this.array.entries()) {
|
|
1063
1000
|
const beforeItem = this.array[index - 1];
|
|
@@ -1066,49 +1003,42 @@ export class ListCollection {
|
|
|
1066
1003
|
return beforeItem;
|
|
1067
1004
|
}
|
|
1068
1005
|
}
|
|
1069
|
-
|
|
1070
|
-
const defaultFn = defaultValue;
|
|
1071
|
-
return defaultFn();
|
|
1072
|
-
}
|
|
1073
|
-
return defaultValue;
|
|
1006
|
+
return simplifyLazyable(defaultValue);
|
|
1074
1007
|
}
|
|
1075
1008
|
catch (error) {
|
|
1076
|
-
if (error instanceof CollectionError
|
|
1077
|
-
error instanceof TypeError) {
|
|
1009
|
+
if (error instanceof CollectionError) {
|
|
1078
1010
|
throw error;
|
|
1079
1011
|
}
|
|
1080
1012
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
1081
1013
|
}
|
|
1082
1014
|
}
|
|
1083
|
-
beforeOrFail(predicateFn
|
|
1015
|
+
beforeOrFail(predicateFn) {
|
|
1084
1016
|
try {
|
|
1085
1017
|
const item = this.before(predicateFn);
|
|
1086
1018
|
if (item === null) {
|
|
1087
|
-
throw new
|
|
1019
|
+
throw new ItemNotFoundCollectionError("Item was not found");
|
|
1088
1020
|
}
|
|
1089
1021
|
return item;
|
|
1090
1022
|
}
|
|
1091
1023
|
catch (error) {
|
|
1092
|
-
if (error instanceof CollectionError
|
|
1093
|
-
error instanceof TypeError) {
|
|
1024
|
+
if (error instanceof CollectionError) {
|
|
1094
1025
|
throw error;
|
|
1095
1026
|
}
|
|
1096
1027
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
1097
1028
|
}
|
|
1098
1029
|
}
|
|
1099
|
-
after(predicateFn
|
|
1030
|
+
after(predicateFn) {
|
|
1100
1031
|
try {
|
|
1101
1032
|
return this.afterOr(null, predicateFn);
|
|
1102
1033
|
}
|
|
1103
1034
|
catch (error) {
|
|
1104
|
-
if (error instanceof CollectionError
|
|
1105
|
-
error instanceof TypeError) {
|
|
1035
|
+
if (error instanceof CollectionError) {
|
|
1106
1036
|
throw error;
|
|
1107
1037
|
}
|
|
1108
1038
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
1109
1039
|
}
|
|
1110
1040
|
}
|
|
1111
|
-
afterOr(defaultValue, predicateFn
|
|
1041
|
+
afterOr(defaultValue, predicateFn) {
|
|
1112
1042
|
try {
|
|
1113
1043
|
for (const [index, item] of this.array.entries()) {
|
|
1114
1044
|
const beforeItem = this.array[index + 1];
|
|
@@ -1117,37 +1047,31 @@ export class ListCollection {
|
|
|
1117
1047
|
return beforeItem;
|
|
1118
1048
|
}
|
|
1119
1049
|
}
|
|
1120
|
-
|
|
1121
|
-
const defaultFn = defaultValue;
|
|
1122
|
-
return defaultFn();
|
|
1123
|
-
}
|
|
1124
|
-
return defaultValue;
|
|
1050
|
+
return simplifyLazyable(defaultValue);
|
|
1125
1051
|
}
|
|
1126
1052
|
catch (error) {
|
|
1127
|
-
if (error instanceof CollectionError
|
|
1128
|
-
error instanceof TypeError) {
|
|
1053
|
+
if (error instanceof CollectionError) {
|
|
1129
1054
|
throw error;
|
|
1130
1055
|
}
|
|
1131
1056
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
1132
1057
|
}
|
|
1133
1058
|
}
|
|
1134
|
-
afterOrFail(predicateFn
|
|
1059
|
+
afterOrFail(predicateFn) {
|
|
1135
1060
|
try {
|
|
1136
1061
|
const item = this.after(predicateFn);
|
|
1137
1062
|
if (item === null) {
|
|
1138
|
-
throw new
|
|
1063
|
+
throw new ItemNotFoundCollectionError("Item was not found");
|
|
1139
1064
|
}
|
|
1140
1065
|
return item;
|
|
1141
1066
|
}
|
|
1142
1067
|
catch (error) {
|
|
1143
|
-
if (error instanceof CollectionError
|
|
1144
|
-
error instanceof TypeError) {
|
|
1068
|
+
if (error instanceof CollectionError) {
|
|
1145
1069
|
throw error;
|
|
1146
1070
|
}
|
|
1147
1071
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
1148
1072
|
}
|
|
1149
1073
|
}
|
|
1150
|
-
sole(predicateFn
|
|
1074
|
+
sole(predicateFn) {
|
|
1151
1075
|
try {
|
|
1152
1076
|
const matchedItems = [];
|
|
1153
1077
|
for (const [index, item] of this.array.entries()) {
|
|
@@ -1155,18 +1079,17 @@ export class ListCollection {
|
|
|
1155
1079
|
matchedItems.push(item);
|
|
1156
1080
|
}
|
|
1157
1081
|
if (matchedItems.length > 1) {
|
|
1158
|
-
throw new
|
|
1082
|
+
throw new MultipleItemsFoundCollectionError("Multiple items were found");
|
|
1159
1083
|
}
|
|
1160
1084
|
}
|
|
1161
1085
|
const [matchedItem] = matchedItems;
|
|
1162
1086
|
if (matchedItem === undefined) {
|
|
1163
|
-
throw new
|
|
1087
|
+
throw new ItemNotFoundCollectionError("Item was not found");
|
|
1164
1088
|
}
|
|
1165
1089
|
return matchedItem;
|
|
1166
1090
|
}
|
|
1167
1091
|
catch (error) {
|
|
1168
|
-
if (error instanceof CollectionError
|
|
1169
|
-
error instanceof TypeError) {
|
|
1092
|
+
if (error instanceof CollectionError) {
|
|
1170
1093
|
throw error;
|
|
1171
1094
|
}
|
|
1172
1095
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -1177,32 +1100,29 @@ export class ListCollection {
|
|
|
1177
1100
|
return this.filter((_item, index) => index % step === 0);
|
|
1178
1101
|
}
|
|
1179
1102
|
catch (error) {
|
|
1180
|
-
if (error instanceof CollectionError
|
|
1181
|
-
error instanceof TypeError) {
|
|
1103
|
+
if (error instanceof CollectionError) {
|
|
1182
1104
|
throw error;
|
|
1183
1105
|
}
|
|
1184
1106
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
1185
1107
|
}
|
|
1186
1108
|
}
|
|
1187
|
-
count(predicateFn
|
|
1109
|
+
count(predicateFn) {
|
|
1188
1110
|
try {
|
|
1189
1111
|
return this.filter(predicateFn).size();
|
|
1190
1112
|
}
|
|
1191
1113
|
catch (error) {
|
|
1192
|
-
if (error instanceof CollectionError
|
|
1193
|
-
error instanceof TypeError) {
|
|
1114
|
+
if (error instanceof CollectionError) {
|
|
1194
1115
|
throw error;
|
|
1195
1116
|
}
|
|
1196
1117
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
1197
1118
|
}
|
|
1198
1119
|
}
|
|
1199
|
-
size(
|
|
1120
|
+
size() {
|
|
1200
1121
|
try {
|
|
1201
1122
|
return this.array.length;
|
|
1202
1123
|
}
|
|
1203
1124
|
catch (error) {
|
|
1204
|
-
if (error instanceof CollectionError
|
|
1205
|
-
error instanceof TypeError) {
|
|
1125
|
+
if (error instanceof CollectionError) {
|
|
1206
1126
|
throw error;
|
|
1207
1127
|
}
|
|
1208
1128
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -1213,8 +1133,7 @@ export class ListCollection {
|
|
|
1213
1133
|
return this.array.length === 0;
|
|
1214
1134
|
}
|
|
1215
1135
|
catch (error) {
|
|
1216
|
-
if (error instanceof CollectionError
|
|
1217
|
-
error instanceof TypeError) {
|
|
1136
|
+
if (error instanceof CollectionError) {
|
|
1218
1137
|
throw error;
|
|
1219
1138
|
}
|
|
1220
1139
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -1225,26 +1144,24 @@ export class ListCollection {
|
|
|
1225
1144
|
return this.array.length !== 0;
|
|
1226
1145
|
}
|
|
1227
1146
|
catch (error) {
|
|
1228
|
-
if (error instanceof CollectionError
|
|
1229
|
-
error instanceof TypeError) {
|
|
1147
|
+
if (error instanceof CollectionError) {
|
|
1230
1148
|
throw error;
|
|
1231
1149
|
}
|
|
1232
1150
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
1233
1151
|
}
|
|
1234
1152
|
}
|
|
1235
|
-
searchFirst(predicateFn
|
|
1153
|
+
searchFirst(predicateFn) {
|
|
1236
1154
|
try {
|
|
1237
1155
|
return this.array.findIndex((item, index) => predicateFn(item, index, this));
|
|
1238
1156
|
}
|
|
1239
1157
|
catch (error) {
|
|
1240
|
-
if (error instanceof CollectionError
|
|
1241
|
-
error instanceof TypeError) {
|
|
1158
|
+
if (error instanceof CollectionError) {
|
|
1242
1159
|
throw error;
|
|
1243
1160
|
}
|
|
1244
1161
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
1245
1162
|
}
|
|
1246
1163
|
}
|
|
1247
|
-
searchLast(predicateFn
|
|
1164
|
+
searchLast(predicateFn) {
|
|
1248
1165
|
try {
|
|
1249
1166
|
let matchedIndex = -1;
|
|
1250
1167
|
for (const [index, item] of this.array.entries()) {
|
|
@@ -1255,22 +1172,20 @@ export class ListCollection {
|
|
|
1255
1172
|
return matchedIndex;
|
|
1256
1173
|
}
|
|
1257
1174
|
catch (error) {
|
|
1258
|
-
if (error instanceof CollectionError
|
|
1259
|
-
error instanceof TypeError) {
|
|
1175
|
+
if (error instanceof CollectionError) {
|
|
1260
1176
|
throw error;
|
|
1261
1177
|
}
|
|
1262
1178
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
1263
1179
|
}
|
|
1264
1180
|
}
|
|
1265
|
-
forEach(callback
|
|
1181
|
+
forEach(callback) {
|
|
1266
1182
|
try {
|
|
1267
1183
|
for (const [index, item] of this.array.entries()) {
|
|
1268
1184
|
callback(item, index, this);
|
|
1269
1185
|
}
|
|
1270
1186
|
}
|
|
1271
1187
|
catch (error) {
|
|
1272
|
-
if (error instanceof CollectionError
|
|
1273
|
-
error instanceof TypeError) {
|
|
1188
|
+
if (error instanceof CollectionError) {
|
|
1274
1189
|
throw error;
|
|
1275
1190
|
}
|
|
1276
1191
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|
|
@@ -1281,8 +1196,7 @@ export class ListCollection {
|
|
|
1281
1196
|
return [...this.array];
|
|
1282
1197
|
}
|
|
1283
1198
|
catch (error) {
|
|
1284
|
-
if (error instanceof CollectionError
|
|
1285
|
-
error instanceof TypeError) {
|
|
1199
|
+
if (error instanceof CollectionError) {
|
|
1286
1200
|
throw error;
|
|
1287
1201
|
}
|
|
1288
1202
|
throw new UnexpectedCollectionError(`Unexpected error "${String(error)}" occured`, error);
|