From 3c04a7c6b9a128521b3c35f743b6cd3dd17b0e46 Mon Sep 17 00:00:00 2001 From: Matteo Bilotta Date: Tue, 10 Sep 2024 15:59:01 +0200 Subject: [PATCH 1/3] wip: Reworking iterators after TypeScript 5.6 release... --- package.json | 6 +- pnpm-lock.yaml | 136 ++++++++-------- src/index.ts | 20 ++- .../aggregators/aggregated-async-iterator.ts | 32 ++-- src/models/aggregators/aggregated-iterator.ts | 145 +++++++++++++++--- src/models/aggregators/aggregator.ts | 46 ------ src/models/aggregators/async-aggregator.ts | 56 ------- src/models/aggregators/index.ts | 4 +- src/models/aggregators/reduced-iterator.ts | 16 +- src/models/aggregators/types.ts | 25 +-- src/models/index.ts | 2 - src/models/iterators/smart-async-iterator.ts | 126 +++++++++++++-- src/models/iterators/smart-iterator.ts | 111 +++++++++++++- src/models/iterators/types.ts | 25 ++- src/models/types.ts | 18 +-- 15 files changed, 485 insertions(+), 283 deletions(-) delete mode 100644 src/models/aggregators/aggregator.ts delete mode 100644 src/models/aggregators/async-aggregator.ts diff --git a/package.json b/package.json index add2240..c09d787 100644 --- a/package.json +++ b/package.json @@ -57,13 +57,13 @@ }, "devDependencies": { "@byloth/eslint-config-typescript": "^2.8.2", - "@types/node": "^20.16.2", + "@types/node": "^20.16.5", "@typescript-eslint/eslint-plugin": "^7.18.0", "@typescript-eslint/parser": "^7.18.0", "eslint": "^8.57.0", "husky": "^9.1.5", - "typescript": "^5.5.4", - "vite": "^5.4.2" + "typescript": "^5.6.2", + "vite": "^5.4.3" }, "packageManager": "pnpm@9.3.0+sha512.ee7b93e0c2bd11409c6424f92b866f31d3ea1bef5fbe47d3c7500cdc3c9668833d2e55681ad66df5b640c61fa9dc25d546efa54d76d7f8bf54b13614ac293631" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 71833e8..eb402f2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,16 +10,16 @@ importers: devDependencies: '@byloth/eslint-config-typescript': specifier: ^2.8.2 - version: 2.8.2(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0) + version: 2.8.2(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)(typescript@5.6.2))(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0) '@types/node': - specifier: ^20.16.2 - version: 20.16.2 + specifier: ^20.16.5 + version: 20.16.5 '@typescript-eslint/eslint-plugin': specifier: ^7.18.0 - version: 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4) + version: 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)(typescript@5.6.2) '@typescript-eslint/parser': specifier: ^7.18.0 - version: 7.18.0(eslint@8.57.0)(typescript@5.5.4) + version: 7.18.0(eslint@8.57.0)(typescript@5.6.2) eslint: specifier: ^8.57.0 version: 8.57.0 @@ -27,11 +27,11 @@ importers: specifier: ^9.1.5 version: 9.1.5 typescript: - specifier: ^5.5.4 - version: 5.5.4 + specifier: ^5.6.2 + version: 5.6.2 vite: - specifier: ^5.4.2 - version: 5.4.2(@types/node@20.16.2) + specifier: ^5.4.3 + version: 5.4.3(@types/node@20.16.5) packages: @@ -310,8 +310,8 @@ packages: '@types/estree@1.0.5': resolution: {integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==} - '@types/node@20.16.2': - resolution: {integrity: sha512-91s/n4qUPV/wg8eE9KHYW1kouTfDk2FPGjXbBMfRWP/2vg1rCXNQL1OCabwGs0XSdukuK+MwCDXE30QpSeMUhQ==} + '@types/node@20.16.5': + resolution: {integrity: sha512-VwYCweNo3ERajwy0IUlqqcyZ8/A7Zwa9ZP3MnENWcB11AejO+tLy3pu850goUW2FC/IJMdZUfKpX/yxL1gymCA==} '@typescript-eslint/eslint-plugin@7.18.0': resolution: {integrity: sha512-94EQTWZ40mzBc42ATNIBimBEDltSJ9RQHCC8vc/PDbxi4k8dVwUAv4o98dk50M1zB+JGFxp43FP7f8+FP8R6Sw==} @@ -437,8 +437,8 @@ packages: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} - debug@4.3.6: - resolution: {integrity: sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==} + debug@4.3.7: + resolution: {integrity: sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==} engines: {node: '>=6.0'} peerDependencies: supports-color: '*' @@ -654,8 +654,8 @@ packages: resolution: {integrity: sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==} engines: {node: '>=16 || 14 >=14.17'} - ms@2.1.2: - resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} + ms@2.1.3: + resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} nanoid@3.3.7: resolution: {integrity: sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==} @@ -700,15 +700,15 @@ packages: resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} engines: {node: '>=8'} - picocolors@1.0.1: - resolution: {integrity: sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==} + picocolors@1.1.0: + resolution: {integrity: sha512-TQ92mBOW0l3LeMeyLV6mzy/kWr8lkd/hp3mTg7wYK7zJhuBStmGMBG0BdeDZS/dZx1IukaX6Bk11zcln25o1Aw==} picomatch@2.3.1: resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} engines: {node: '>=8.6'} - postcss@8.4.41: - resolution: {integrity: sha512-TesUflQ0WKZqAvg52PWL6kHgLKP6xB6heTOdoYM0Wt2UHyxNa4K25EZZMgKns3BH1RLVbZCREPpLY0rhnNoHVQ==} + postcss@8.4.45: + resolution: {integrity: sha512-7KTLTdzdZZYscUc65XmjFiB73vBhBfbPztCYdUNvlaso9PrzjzcmjqBPR0lNGkcVlcO4BjiO5rK/qNz+XAen1Q==} engines: {node: ^10 || ^12 || >=14} prelude-ls@1.2.1: @@ -760,8 +760,8 @@ packages: resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} engines: {node: '>=8'} - source-map-js@1.2.0: - resolution: {integrity: sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==} + source-map-js@1.2.1: + resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} strip-ansi@6.0.1: @@ -797,8 +797,8 @@ packages: resolution: {integrity: sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==} engines: {node: '>=10'} - typescript@5.5.4: - resolution: {integrity: sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==} + typescript@5.6.2: + resolution: {integrity: sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==} engines: {node: '>=14.17'} hasBin: true @@ -808,8 +808,8 @@ packages: uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} - vite@5.4.2: - resolution: {integrity: sha512-dDrQTRHp5C1fTFzcSaMxjk6vdpKvT+2/mIdE07Gw2ykehT49O0z/VHS3zZ8iV/Gh8BJJKHWOe5RjaNrW5xf/GA==} + vite@5.4.3: + resolution: {integrity: sha512-IH+nl64eq9lJjFqU+/yrRnrHPVTlgy42/+IzbOdaFDVlyLgI/wDlf+FCobXLX1cT0X5+7LMyH1mIy2xJdLfo8Q==} engines: {node: ^18.0.0 || >=20.0.0} hasBin: true peerDependencies: @@ -857,11 +857,11 @@ packages: snapshots: - '@byloth/eslint-config-typescript@2.8.2(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)': + '@byloth/eslint-config-typescript@2.8.2(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)(typescript@5.6.2))(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)': dependencies: '@byloth/eslint-config': 2.8.2(eslint@8.57.0) - '@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4) - '@typescript-eslint/parser': 7.18.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)(typescript@5.6.2) + '@typescript-eslint/parser': 7.18.0(eslint@8.57.0)(typescript@5.6.2) transitivePeerDependencies: - eslint @@ -948,7 +948,7 @@ snapshots: '@eslint/eslintrc@2.1.4': dependencies: ajv: 6.12.6 - debug: 4.3.6 + debug: 4.3.7 espree: 9.6.1 globals: 13.24.0 ignore: 5.3.2 @@ -964,7 +964,7 @@ snapshots: '@humanwhocodes/config-array@0.11.14': dependencies: '@humanwhocodes/object-schema': 2.0.3 - debug: 4.3.6 + debug: 4.3.7 minimatch: 3.1.2 transitivePeerDependencies: - supports-color @@ -1035,38 +1035,38 @@ snapshots: '@types/estree@1.0.5': {} - '@types/node@20.16.2': + '@types/node@20.16.5': dependencies: undici-types: 6.19.8 - '@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4)': + '@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)(typescript@5.6.2)': dependencies: '@eslint-community/regexpp': 4.11.0 - '@typescript-eslint/parser': 7.18.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/parser': 7.18.0(eslint@8.57.0)(typescript@5.6.2) '@typescript-eslint/scope-manager': 7.18.0 - '@typescript-eslint/type-utils': 7.18.0(eslint@8.57.0)(typescript@5.5.4) - '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/type-utils': 7.18.0(eslint@8.57.0)(typescript@5.6.2) + '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.6.2) '@typescript-eslint/visitor-keys': 7.18.0 eslint: 8.57.0 graphemer: 1.4.0 ignore: 5.3.2 natural-compare: 1.4.0 - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.6.2) optionalDependencies: - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - supports-color - '@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4)': + '@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2)': dependencies: '@typescript-eslint/scope-manager': 7.18.0 '@typescript-eslint/types': 7.18.0 - '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.6.2) '@typescript-eslint/visitor-keys': 7.18.0 - debug: 4.3.6 + debug: 4.3.7 eslint: 8.57.0 optionalDependencies: - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - supports-color @@ -1075,41 +1075,41 @@ snapshots: '@typescript-eslint/types': 7.18.0 '@typescript-eslint/visitor-keys': 7.18.0 - '@typescript-eslint/type-utils@7.18.0(eslint@8.57.0)(typescript@5.5.4)': + '@typescript-eslint/type-utils@7.18.0(eslint@8.57.0)(typescript@5.6.2)': dependencies: - '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.5.4) - '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.5.4) - debug: 4.3.6 + '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.6.2) + '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.6.2) + debug: 4.3.7 eslint: 8.57.0 - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.6.2) optionalDependencies: - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - supports-color '@typescript-eslint/types@7.18.0': {} - '@typescript-eslint/typescript-estree@7.18.0(typescript@5.5.4)': + '@typescript-eslint/typescript-estree@7.18.0(typescript@5.6.2)': dependencies: '@typescript-eslint/types': 7.18.0 '@typescript-eslint/visitor-keys': 7.18.0 - debug: 4.3.6 + debug: 4.3.7 globby: 11.1.0 is-glob: 4.0.3 minimatch: 9.0.5 semver: 7.6.3 - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.6.2) optionalDependencies: - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - supports-color - '@typescript-eslint/utils@7.18.0(eslint@8.57.0)(typescript@5.5.4)': + '@typescript-eslint/utils@7.18.0(eslint@8.57.0)(typescript@5.6.2)': dependencies: '@eslint-community/eslint-utils': 4.4.0(eslint@8.57.0) '@typescript-eslint/scope-manager': 7.18.0 '@typescript-eslint/types': 7.18.0 - '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.6.2) eslint: 8.57.0 transitivePeerDependencies: - supports-color @@ -1181,9 +1181,9 @@ snapshots: shebang-command: 2.0.0 which: 2.0.2 - debug@4.3.6: + debug@4.3.7: dependencies: - ms: 2.1.2 + ms: 2.1.3 deep-is@0.1.4: {} @@ -1243,7 +1243,7 @@ snapshots: ajv: 6.12.6 chalk: 4.1.2 cross-spawn: 7.0.3 - debug: 4.3.6 + debug: 4.3.7 doctrine: 3.0.0 escape-string-regexp: 4.0.0 eslint-scope: 7.2.2 @@ -1439,7 +1439,7 @@ snapshots: dependencies: brace-expansion: 2.0.1 - ms@2.1.2: {} + ms@2.1.3: {} nanoid@3.3.7: {} @@ -1478,15 +1478,15 @@ snapshots: path-type@4.0.0: {} - picocolors@1.0.1: {} + picocolors@1.1.0: {} picomatch@2.3.1: {} - postcss@8.4.41: + postcss@8.4.45: dependencies: nanoid: 3.3.7 - picocolors: 1.0.1 - source-map-js: 1.2.0 + picocolors: 1.1.0 + source-map-js: 1.2.1 prelude-ls@1.2.1: {} @@ -1538,7 +1538,7 @@ snapshots: slash@3.0.0: {} - source-map-js@1.2.0: {} + source-map-js@1.2.1: {} strip-ansi@6.0.1: dependencies: @@ -1556,9 +1556,9 @@ snapshots: dependencies: is-number: 7.0.0 - ts-api-utils@1.3.0(typescript@5.5.4): + ts-api-utils@1.3.0(typescript@5.6.2): dependencies: - typescript: 5.5.4 + typescript: 5.6.2 type-check@0.4.0: dependencies: @@ -1566,7 +1566,7 @@ snapshots: type-fest@0.20.2: {} - typescript@5.5.4: {} + typescript@5.6.2: {} undici-types@6.19.8: {} @@ -1574,13 +1574,13 @@ snapshots: dependencies: punycode: 2.3.1 - vite@5.4.2(@types/node@20.16.2): + vite@5.4.3(@types/node@20.16.5): dependencies: esbuild: 0.21.5 - postcss: 8.4.41 + postcss: 8.4.45 rollup: 4.21.2 optionalDependencies: - '@types/node': 20.16.2 + '@types/node': 20.16.5 fsevents: 2.3.3 which@2.0.2: diff --git a/src/index.ts b/src/index.ts index b2b07df..f376228 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,8 +7,6 @@ export { isBrowser, isNode, isWebWorker } from "./helpers.js"; export { AggregatedIterator, AggregatedAsyncIterator, - Aggregator, - AsyncAggregator, Clock, Countdown, DeferredPromise, @@ -40,23 +38,23 @@ export { export type { AsyncGeneratorFunction, - AsyncIterLike, + AsyncIteratorLike, FulfilledHandler, GeneratorFunction, Iteratee, - IterLike, + IteratorLike, JSONArray, JSONObject, JSONValue, - KeyIteratee, - KeyReducer, - KeyTypeGuardIteratee, - MaybeAsyncKeyIteratee, - MaybeAsyncKeyReducer, - MaybeAsyncKeyTypeGuardIteratee, + KeyedIteratee, + KeyedReducer, + KeyedTypeGuardIteratee, + MaybeAsyncKeyedIteratee, + MaybeAsyncKeyedReducer, + MaybeAsyncKeyedTypeGuardIteratee, MaybeAsyncReducer, MaybeAsyncIteratee, - MaybeAsyncIterLike, + MaybeAsyncIteratorLike, MaybeAsyncTypeGuardIteratee, MaybePromise, PromiseExecutor, diff --git a/src/models/aggregators/aggregated-async-iterator.ts b/src/models/aggregators/aggregated-async-iterator.ts index d1b133b..02bba39 100644 --- a/src/models/aggregators/aggregated-async-iterator.ts +++ b/src/models/aggregators/aggregated-async-iterator.ts @@ -1,9 +1,15 @@ import { SmartAsyncIterator } from "../iterators/index.js"; -import type { AsyncGeneratorFunction, GeneratorFunction, MaybeAsyncIterLike } from "../iterators/types.js"; +import type { + GeneratorFunction, + AsyncGeneratorFunction, + MaybeAsyncGeneratorFunction, + MaybeAsyncIteratorLike + +} from "../iterators/types.js"; import type { MaybePromise } from "../types.js"; import ReducedIterator from "./reduced-iterator.js"; -import type { MaybeAsyncKeyIteratee, MaybeAsyncKeyTypeGuardIteratee, MaybeAsyncKeyReducer } from "./types.js"; +import type { MaybeAsyncKeyedIteratee, MaybeAsyncKeyedTypeGuardIteratee, MaybeAsyncKeyedReducer } from "./types.js"; export default class AggregatedAsyncIterator { @@ -15,13 +21,13 @@ export default class AggregatedAsyncIterator public constructor(iterator: AsyncIterator<[K, T]>); public constructor(generatorFn: GeneratorFunction<[K, T]>); public constructor(generatorFn: AsyncGeneratorFunction<[K, T]>); - public constructor(argument: MaybeAsyncIterLike<[K, T]>); - public constructor(argument: MaybeAsyncIterLike<[K, T]>) + public constructor(argument: MaybeAsyncIteratorLike<[K, T]> | MaybeAsyncGeneratorFunction<[K, T]>); + public constructor(argument: MaybeAsyncIteratorLike<[K, T]> | MaybeAsyncGeneratorFunction<[K, T]>) { this._elements = new SmartAsyncIterator(argument); } - public async every(predicate: MaybeAsyncKeyIteratee): Promise> + public async every(predicate: MaybeAsyncKeyedIteratee): Promise> { const indexes = new Map(); @@ -42,7 +48,7 @@ export default class AggregatedAsyncIterator } }); } - public async some(predicate: MaybeAsyncKeyIteratee): Promise> + public async some(predicate: MaybeAsyncKeyedIteratee): Promise> { const indexes = new Map(); @@ -64,9 +70,9 @@ export default class AggregatedAsyncIterator }); } - public filter(predicate: MaybeAsyncKeyIteratee): AggregatedAsyncIterator; - public filter(predicate: MaybeAsyncKeyTypeGuardIteratee): AggregatedAsyncIterator; - public filter(predicate: MaybeAsyncKeyIteratee): AggregatedAsyncIterator + public filter(predicate: MaybeAsyncKeyedIteratee): AggregatedAsyncIterator; + public filter(predicate: MaybeAsyncKeyedTypeGuardIteratee): AggregatedAsyncIterator; + public filter(predicate: MaybeAsyncKeyedIteratee): AggregatedAsyncIterator { const elements = this._elements; @@ -84,7 +90,7 @@ export default class AggregatedAsyncIterator } }); } - public map(iteratee: MaybeAsyncKeyIteratee): AggregatedAsyncIterator + public map(iteratee: MaybeAsyncKeyedIteratee): AggregatedAsyncIterator { const elements = this._elements; @@ -102,10 +108,10 @@ export default class AggregatedAsyncIterator } }); } - public async reduce(reducer: MaybeAsyncKeyReducer): Promise>; - public async reduce(reducer: MaybeAsyncKeyReducer, initialValue: (key: K) => MaybePromise) + public async reduce(reducer: MaybeAsyncKeyedReducer): Promise>; + public async reduce(reducer: MaybeAsyncKeyedReducer, initialValue: (key: K) => MaybePromise) : Promise>; - public async reduce(reducer: MaybeAsyncKeyReducer, initialValue?: (key: K) => MaybePromise) + public async reduce(reducer: MaybeAsyncKeyedReducer, initialValue?: (key: K) => MaybePromise) : Promise> { const accumulators = new Map(); diff --git a/src/models/aggregators/aggregated-iterator.ts b/src/models/aggregators/aggregated-iterator.ts index c36adf4..a1f4e04 100644 --- a/src/models/aggregators/aggregated-iterator.ts +++ b/src/models/aggregators/aggregated-iterator.ts @@ -1,8 +1,8 @@ import { SmartIterator } from "../iterators/index.js"; -import type { GeneratorFunction } from "../iterators/types.js"; +import type { GeneratorFunction, IteratorLike } from "../iterators/types.js"; import ReducedIterator from "./reduced-iterator.js"; -import type { KeyIteratee, KeyTypeGuardIteratee, KeyReducer } from "./types.js"; +import type { KeyedIteratee, KeyedTypeGuardIteratee, KeyedReducer } from "./types.js"; export default class AggregatedIterator { @@ -11,13 +11,13 @@ export default class AggregatedIterator public constructor(iterable: Iterable<[K, T]>); public constructor(iterator: Iterator<[K, T]>); public constructor(generatorFn: GeneratorFunction<[K, T]>); - public constructor(argument: Iterable<[K, T]> | Iterator<[K, T]> | GeneratorFunction<[K, T]>); - public constructor(argument: Iterable<[K, T]> | Iterator<[K, T]> | GeneratorFunction<[K, T]>) + public constructor(argument: IteratorLike<[K, T]> | GeneratorFunction<[K, T]>); + public constructor(argument: IteratorLike<[K, T]> | GeneratorFunction<[K, T]>) { this._elements = new SmartIterator(argument); } - public every(predicate: KeyIteratee): ReducedIterator + public every(predicate: KeyedIteratee): ReducedIterator { const indexes = new Map(); @@ -38,7 +38,7 @@ export default class AggregatedIterator } }); } - public some(predicate: KeyIteratee): ReducedIterator + public some(predicate: KeyedIteratee): ReducedIterator { const indexes = new Map(); @@ -60,9 +60,9 @@ export default class AggregatedIterator }); } - public filter(predicate: KeyIteratee): AggregatedIterator; - public filter(predicate: KeyTypeGuardIteratee): AggregatedIterator; - public filter(predicate: KeyIteratee): AggregatedIterator + public filter(predicate: KeyedIteratee): AggregatedIterator; + public filter(predicate: KeyedTypeGuardIteratee): AggregatedIterator; + public filter(predicate: KeyedIteratee): AggregatedIterator { const elements = this._elements; @@ -74,13 +74,13 @@ export default class AggregatedIterator { const index = indexes.get(key) ?? 0; - indexes.set(key, index + 1); - if (predicate(key, element, index)) { yield [key, element]; } + + indexes.set(key, index + 1); } }); } - public map(iteratee: KeyIteratee): AggregatedIterator + public map(iteratee: KeyedIteratee): AggregatedIterator { const elements = this._elements; @@ -92,15 +92,15 @@ export default class AggregatedIterator { const index = indexes.get(key) ?? 0; - indexes.set(key, index + 1); - yield [key, iteratee(key, element, index)]; + + indexes.set(key, index + 1); } }); } - public reduce(reducer: KeyReducer): ReducedIterator; - public reduce(reducer: KeyReducer, initialValue: (key: K) => A): ReducedIterator; - public reduce(reducer: KeyReducer, initialValue?: (key: K) => A): ReducedIterator + public reduce(reducer: KeyedReducer): ReducedIterator; + public reduce(reducer: KeyedReducer, initialValue: (key: K) => A): ReducedIterator; + public reduce(reducer: KeyedReducer, initialValue?: (key: K) => A): ReducedIterator { const accumulators = new Map(); @@ -109,12 +109,7 @@ export default class AggregatedIterator let index: number; let accumulator: A; - if (accumulators.has(key)) - { - [index, accumulator] = accumulators.get(key)!; - - index += 1; - } + if (accumulators.has(key)) { [index, accumulator] = accumulators.get(key)!; } else if (initialValue !== undefined) { index = 0; @@ -129,7 +124,7 @@ export default class AggregatedIterator accumulator = reducer(key, accumulator, element, index); - accumulators.set(key, [index, accumulator]); + accumulators.set(key, [index + 1, accumulator]); } return new ReducedIterator(function* () @@ -141,6 +136,107 @@ export default class AggregatedIterator }); } + public flatMap(iteratee: KeyedIteratee>): AggregatedIterator + { + const elements = this._elements; + + return new AggregatedIterator(function* () + { + const indexes = new Map(); + + for (const [key, element] of elements) + { + const index = indexes.get(key) ?? 0; + + for (const value of iteratee(key, element, index)) + { + yield [key, value]; + } + + indexes.set(key, index + 1); + } + }); + } + + public drop(count: number): AggregatedIterator + { + const elements = this._elements; + + return new AggregatedIterator(function* () + { + const indexes = new Map(); + + for (const [key, element] of elements) + { + const index = indexes.get(key) ?? 0; + if (index < count) + { + indexes.set(key, index + 1); + + continue; + } + + yield [key, element]; + } + }); + } + public take(limit: number): AggregatedIterator + { + const elements = this._elements; + + return new AggregatedIterator(function* () + { + const indexes = new Map(); + + for (const [key, element] of elements) + { + const index = indexes.get(key) ?? 0; + if (index >= limit) + { + if (indexes.values().every((value) => value >= limit)) { break; } + + continue; + } + + indexes.set(key, index + 1); + + yield [key, element]; + } + }); + } + + public find(predicate: KeyedIteratee): ReducedIterator; + public find(predicate: KeyedTypeGuardIteratee): ReducedIterator; + public find(predicate: KeyedIteratee): ReducedIterator + { + const elements = this._elements; + + return new ReducedIterator(function* () + { + const indexes = new Map(); + const findings = new Set(); + + for (const [key, element] of elements) + { + if (findings.has(key)) { continue; } + + const index = indexes.get(key) ?? 0; + if (predicate(key, element, index)) + { + yield [key, element]; + + findings.add(key); + } + + indexes.set(key, index + 1); + } + }); + } + + public enumerate(): AggregatedIterator + { + return this.map((_, value, index) => [index, value]); + } public unique(): AggregatedIterator { const elements = this._elements; @@ -182,6 +278,7 @@ export default class AggregatedIterator } }); } + public first(): ReducedIterator { const firsts = new Map(); diff --git a/src/models/aggregators/aggregator.ts b/src/models/aggregators/aggregator.ts deleted file mode 100644 index 476532d..0000000 --- a/src/models/aggregators/aggregator.ts +++ /dev/null @@ -1,46 +0,0 @@ -import AggregatedIterator from "./aggregated-iterator.js"; - -import { SmartIterator } from "../iterators/index.js"; -import type { GeneratorFunction, Iteratee, IterLike, TypeGuardIteratee } from "../iterators/types.js"; - -export default class Aggregator -{ - protected _elements: SmartIterator; - - public constructor(iterable: Iterable); - public constructor(iterator: Iterator); - public constructor(generatorFn: GeneratorFunction); - public constructor(argument: IterLike); - public constructor(argument: IterLike) - { - this._elements = new SmartIterator(argument); - } - - public filter(predicate: Iteratee): Aggregator; - public filter(predicate: TypeGuardIteratee): Aggregator; - public filter(predicate: Iteratee): Aggregator - { - return new Aggregator(this._elements.filter(predicate)); - } - public map(iteratee: Iteratee): Aggregator - { - return new Aggregator(this._elements.map(iteratee)); - } - - public unique(): Aggregator - { - return new Aggregator(this._elements.unique()); - } - - public groupBy(iteratee: Iteratee): AggregatedIterator - { - return new AggregatedIterator(this._elements.map((element, index) => - { - const key = iteratee(element, index); - - return [key, element] as [K, T]; - })); - } - - public get [Symbol.toStringTag]() { return "Aggregator"; } -} diff --git a/src/models/aggregators/async-aggregator.ts b/src/models/aggregators/async-aggregator.ts deleted file mode 100644 index 796a96e..0000000 --- a/src/models/aggregators/async-aggregator.ts +++ /dev/null @@ -1,56 +0,0 @@ -import AggregatedAsyncIterator from "./aggregated-async-iterator.js"; - -import { SmartAsyncIterator } from "../iterators/index.js"; -import type { - AsyncGeneratorFunction, - GeneratorFunction, - MaybeAsyncIterLike, - MaybeAsyncIteratee, - MaybeAsyncTypeGuardIteratee - -} from "../iterators/types.js"; - -export default class AsyncAggregator -{ - protected _elements: SmartAsyncIterator; - - public constructor(iterable: Iterable); - public constructor(iterable: AsyncIterable); - public constructor(iterator: Iterator); - public constructor(iterator: AsyncIterator); - public constructor(generatorFn: GeneratorFunction); - public constructor(generatorFn: AsyncGeneratorFunction); - public constructor(argument: MaybeAsyncIterLike); - public constructor(argument: MaybeAsyncIterLike) - { - this._elements = new SmartAsyncIterator(argument); - } - - public filter(predicate: MaybeAsyncIteratee): AsyncAggregator; - public filter(predicate: MaybeAsyncTypeGuardIteratee): AsyncAggregator; - public filter(predicate: MaybeAsyncIteratee): AsyncAggregator - { - return new AsyncAggregator(this._elements.filter(predicate)); - } - public map(iteratee: MaybeAsyncIteratee): AsyncAggregator - { - return new AsyncAggregator(this._elements.map(iteratee)); - } - - public unique(): AsyncAggregator - { - return new AsyncAggregator(this._elements.unique()); - } - - public groupBy(iteratee: MaybeAsyncIteratee): AggregatedAsyncIterator - { - return new AggregatedAsyncIterator(this._elements.map(async (element, index) => - { - const key = await iteratee(element, index); - - return [key, element] as [K, T]; - })); - } - - public get [Symbol.toStringTag]() { return "AsyncAggregator"; } -} diff --git a/src/models/aggregators/index.ts b/src/models/aggregators/index.ts index 4c623f6..3404dca 100644 --- a/src/models/aggregators/index.ts +++ b/src/models/aggregators/index.ts @@ -1,7 +1,5 @@ -import Aggregator from "./aggregator.js"; -import AsyncAggregator from "./async-aggregator.js"; import AggregatedIterator from "./aggregated-iterator.js"; import AggregatedAsyncIterator from "./aggregated-async-iterator.js"; import ReducedIterator from "./reduced-iterator.js"; -export { Aggregator, AsyncAggregator, AggregatedIterator, AggregatedAsyncIterator, ReducedIterator }; +export { AggregatedIterator, AggregatedAsyncIterator, ReducedIterator }; diff --git a/src/models/aggregators/reduced-iterator.ts b/src/models/aggregators/reduced-iterator.ts index 9d347af..b57678b 100644 --- a/src/models/aggregators/reduced-iterator.ts +++ b/src/models/aggregators/reduced-iterator.ts @@ -2,7 +2,7 @@ import { ValueException } from "../exceptions/index.js"; import { SmartIterator } from "../iterators/index.js"; import type { GeneratorFunction } from "../iterators/types.js"; -import type { KeyIteratee, KeyReducer, KeyTypeGuardIteratee } from "./types.js"; +import type { KeyedIteratee, KeyedReducer, KeyedTypeGuardIteratee } from "./types.js"; export default class ReducedIterator { @@ -17,9 +17,9 @@ export default class ReducedIterator this._elements = new SmartIterator(argument); } - public filter(predicate: KeyIteratee): ReducedIterator; - public filter(predicate: KeyTypeGuardIteratee): ReducedIterator; - public filter(predicate: KeyIteratee): ReducedIterator + public filter(predicate: KeyedIteratee): ReducedIterator; + public filter(predicate: KeyedTypeGuardIteratee): ReducedIterator; + public filter(predicate: KeyedIteratee): ReducedIterator { const elements = this._elements; @@ -34,7 +34,7 @@ export default class ReducedIterator } }); } - public map(iteratee: KeyIteratee): ReducedIterator + public map(iteratee: KeyedIteratee): ReducedIterator { const elements = this._elements; @@ -46,9 +46,9 @@ export default class ReducedIterator } }); } - public reduce(reducer: KeyReducer): T; - public reduce(reducer: KeyReducer, initialValue: A): A; - public reduce(reducer: KeyReducer, initialValue?: A): A + public reduce(reducer: KeyedReducer): T; + public reduce(reducer: KeyedReducer, initialValue: A): A; + public reduce(reducer: KeyedReducer, initialValue?: A): A { let index = 0; let accumulator: A; diff --git a/src/models/aggregators/types.ts b/src/models/aggregators/types.ts index 1d51ae8..7236482 100644 --- a/src/models/aggregators/types.ts +++ b/src/models/aggregators/types.ts @@ -1,14 +1,19 @@ +/* eslint-disable max-len */ + import type { MaybePromise } from "../promises/types.js"; -export type KeyIteratee = (key: K, value: T, index: number) => R; -export type MaybeAsyncKeyIteratee = (key: K, value: T, index: number) => - MaybePromise; +export type KeyedIteratee = (key: K, value: T, index: number) => R; +export type AsyncKeyedIteratee = (key: K, value: T, index: number) => Promise; +export type MaybeAsyncKeyedIteratee = (key: K, value: T, index: number) => MaybePromise; + +export type KeyedTypeGuardIteratee = (key: K, value: T, index: number) => value is R; + +// @ts-expect-error - This is an asyncronous type guard keyed-iteratee that guarantees the return value is a promise. +export type AsyncKeyedTypeGuardIteratee = (key: K, value: T, index: number) => value is Promise; -export type KeyTypeGuardIteratee = - (key: K, value: T, index: number) => value is R; -export type MaybeAsyncKeyTypeGuardIteratee = - (key: K, value: MaybePromise, index: number) => value is Awaited; +// @ts-expect-error - This may be an asyncronous type guard keyed-iteratee that guarantees the return value may be a promise. +export type MaybeAsyncKeyedTypeGuardIteratee = (key: K, value: T, index: number) => value is MaybePromise; -export type KeyReducer = (key: K, accumulator: A, value: T, index: number) => A; -export type MaybeAsyncKeyReducer = - (key: K, accumulator: A, value: T, index: number) => MaybePromise; +export type KeyedReducer = (key: K, accumulator: A, value: T, index: number) => A; +export type AsyncKeyedReducer = (key: K, accumulator: A, value: T, index: number) => Promise; +export type MaybeAsyncKeyedReducer = (key: K, accumulator: A, value: T, index: number) => MaybePromise; diff --git a/src/models/index.ts b/src/models/index.ts index 6bdd6e5..8b7a69e 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -1,6 +1,4 @@ export { - Aggregator, - AsyncAggregator, AggregatedIterator, AggregatedAsyncIterator, ReducedIterator diff --git a/src/models/iterators/smart-async-iterator.ts b/src/models/iterators/smart-async-iterator.ts index b57becd..faec0c7 100644 --- a/src/models/iterators/smart-async-iterator.ts +++ b/src/models/iterators/smart-async-iterator.ts @@ -1,11 +1,14 @@ +import AggregatedAsyncIterator from "../aggregators/aggregated-async-iterator.js"; import { ValueException } from "../exceptions/index.js"; import type { - AsyncGeneratorFunction, GeneratorFunction, + AsyncGeneratorFunction, + MaybeAsyncGeneratorFunction, MaybeAsyncIteratee, MaybeAsyncReducer, - MaybeAsyncIterLike, + MaybeAsyncIterable, + MaybeAsyncIteratorLike, MaybeAsyncTypeGuardIteratee } from "./types.js"; @@ -23,8 +26,8 @@ export default class SmartAsyncIterator implements A public constructor(iterator: AsyncIterator); public constructor(generatorFn: GeneratorFunction); public constructor(generatorFn: AsyncGeneratorFunction); - public constructor(argument: MaybeAsyncIterLike); - public constructor(argument: MaybeAsyncIterLike) + public constructor(argument: MaybeAsyncIteratorLike | MaybeAsyncGeneratorFunction); + public constructor(argument: MaybeAsyncIteratorLike | MaybeAsyncGeneratorFunction) { if (argument instanceof Function) { @@ -100,7 +103,7 @@ export default class SmartAsyncIterator implements A const result = await this._iterator.next(); if (result.done) { return true; } - if (!(predicate(result.value, index))) { return false; } + if (!(await predicate(result.value, index))) { return false; } index += 1; } @@ -115,7 +118,7 @@ export default class SmartAsyncIterator implements A const result = await this._iterator.next(); if (result.done) { return false; } - if (predicate(result.value, index)) { return true; } + if (await predicate(result.value, index)) { return true; } index += 1; } @@ -136,7 +139,7 @@ export default class SmartAsyncIterator implements A const result = await iterator.next(); if (result.done) { return result.value; } - if (predicate(result.value, index)) { yield result.value; } + if (await predicate(result.value, index)) { yield result.value; } index += 1; } @@ -155,7 +158,7 @@ export default class SmartAsyncIterator implements A const result = await iterator.next(); if (result.done) { return result.value; } - yield iteratee(result.value, index); + yield await iteratee(result.value, index); index += 1; } @@ -188,6 +191,94 @@ export default class SmartAsyncIterator implements A } } + public flatMap(iteratee: MaybeAsyncIteratee>): SmartAsyncIterator + { + const iterator = this._iterator; + + return new SmartAsyncIterator(async function* () + { + let index = 0; + + while (true) + { + const result = await iterator.next(); + if (result.done) { return result.value; } + + const elements = await iteratee(result.value, index); + + for await (const element of elements) + { + yield element; + } + + index += 1; + } + }); + } + + public drop(count: number): SmartAsyncIterator + { + const iterator = this._iterator; + + return new SmartAsyncIterator(async function* () + { + let index = 0; + + while (index < count) + { + const result = await iterator.next(); + if (result.done) { return; } + + index += 1; + } + + while (true) + { + const result = await iterator.next(); + if (result.done) { return result.value; } + + yield result.value; + } + }); + } + public take(limit: number): SmartAsyncIterator + { + const iterator = this._iterator; + + return new SmartAsyncIterator(async function* () + { + let index = 0; + + while (index < limit) + { + const result = await iterator.next(); + if (result.done) { return result.value; } + + yield result.value; + + index += 1; + } + + return; + }); + } + + public async find(predicate: MaybeAsyncIteratee): Promise + { + let index = 0; + + // eslint-disable-next-line no-constant-condition + while (true) + { + const result = await this._iterator.next(); + + if (result.done) { return; } + if (await predicate(result.value, index)) { return result.value; } + + index += 1; + } + } + public enumerate(): SmartAsyncIterator<[number, T], R> { return this.map((value, index) => [index, value]); @@ -248,18 +339,19 @@ export default class SmartAsyncIterator implements A return this._iterator.next(...values); } - public async toArray(): Promise + public groupBy(iteratee: MaybeAsyncIteratee): AggregatedAsyncIterator { - const elements: T[] = []; - - // eslint-disable-next-line no-constant-condition - while (true) + return new AggregatedAsyncIterator(this.map(async (element, index) => { - const result = await this._iterator.next(); - if (result.done) { return elements; } + const key = await iteratee(element, index); - elements.push(result.value); - } + return [key, element] as [K, T]; + })); + } + + public async toArray(): Promise + { + return Array.fromAsync(this as AsyncIterable); } public get [Symbol.toStringTag]() { return "SmartAsyncIterator"; } diff --git a/src/models/iterators/smart-iterator.ts b/src/models/iterators/smart-iterator.ts index 2fafc4b..c3214a8 100644 --- a/src/models/iterators/smart-iterator.ts +++ b/src/models/iterators/smart-iterator.ts @@ -1,6 +1,7 @@ +import AggregatedIterator from "../aggregators/aggregated-iterator.js"; import { ValueException } from "../exceptions/index.js"; -import type { GeneratorFunction, Iteratee, TypeGuardIteratee, Reducer, IterLike } from "./types.js"; +import type { GeneratorFunction, Iteratee, TypeGuardIteratee, Reducer, IteratorLike } from "./types.js"; export default class SmartIterator implements Iterator { @@ -9,11 +10,11 @@ export default class SmartIterator implements Iterat public return?: (value?: R) => IteratorResult; public throw?: (error?: unknown) => IteratorResult; - public constructor(iterable: Iterable); + public constructor(iterable: Iterable); public constructor(iterator: Iterator); public constructor(generatorFn: GeneratorFunction); - public constructor(argument: IterLike); - public constructor(argument: IterLike) + public constructor(argument: IteratorLike | GeneratorFunction); + public constructor(argument: IteratorLike | GeneratorFunction) { if (argument instanceof Function) { @@ -28,8 +29,8 @@ export default class SmartIterator implements Iterat this._iterator = argument; } - if (this._iterator.return) { this.return = (value?: R) => this._iterator.return!(value); } - if (this._iterator.throw) { this.throw = (error?: unknown) => this._iterator.throw!(error); } + if (this._iterator.return) { this.return = (value) => this._iterator.return!(value); } + if (this._iterator.throw) { this.throw = (error) => this._iterator.throw!(error); } } public every(predicate: Iteratee): boolean @@ -130,6 +131,93 @@ export default class SmartIterator implements Iterat } } + public flatMap(iteratee: Iteratee>): SmartIterator + { + const iterator = this._iterator; + + return new SmartIterator(function* () + { + let index = 0; + + while (true) + { + const result = iterator.next(); + if (result.done) { return result.value; } + + const iterable = iteratee(result.value, index); + for (const value of iterable) + { + yield value; + } + + index += 1; + } + }); + } + + public drop(count: number): SmartIterator + { + const iterator = this._iterator; + + return new SmartIterator(function* () + { + let index = 0; + while (index < count) + { + const result = iterator.next(); + if (result.done) { return; } + + index += 1; + } + + while (true) + { + const result = iterator.next(); + if (result.done) { return result.value; } + + yield result.value; + } + }); + } + public take(limit: number): SmartIterator + { + const iterator = this._iterator; + + return new SmartIterator(function* () + { + let index = 0; + while (index < limit) + { + const result = iterator.next(); + if (result.done) { return result.value; } + + yield result.value; + + index += 1; + } + + return; + }); + } + + public find(predicate: Iteratee): T | void; + public find(predicate: TypeGuardIteratee): S | void; + public find(predicate: Iteratee): T | void + { + let index = 0; + + // eslint-disable-next-line no-constant-condition + while (true) + { + const result = this._iterator.next(); + + if (result.done) { return; } + if (predicate(result.value, index)) { return result.value; } + + index += 1; + } + } + public enumerate(): SmartIterator<[number, T], R> { return this.map((value, index) => [index, value]); @@ -169,6 +257,7 @@ export default class SmartIterator implements Iterat index += 1; } } + public forEach(iteratee: Iteratee): void { let index = 0; @@ -190,6 +279,16 @@ export default class SmartIterator implements Iterat return this._iterator.next(...values); } + public groupBy(iteratee: Iteratee): AggregatedIterator + { + return new AggregatedIterator(this.map((element, index) => + { + const key = iteratee(element, index); + + return [key, element] as [K, T]; + })); + } + public toArray(): T[] { return Array.from(this as Iterable); diff --git a/src/models/iterators/types.ts b/src/models/iterators/types.ts index ae209e6..a9808cb 100644 --- a/src/models/iterators/types.ts +++ b/src/models/iterators/types.ts @@ -1,20 +1,31 @@ +/* eslint-disable max-len */ + import type { MaybePromise } from "../promises/types.js"; +export type MaybeAsyncIterable = Iterable | AsyncIterable; +export type MaybeAsyncIterator = Iterator | AsyncIterator; +export type MaybeAsyncGenerator = Generator | AsyncGenerator; + export type GeneratorFunction = () => Generator; export type AsyncGeneratorFunction = () => AsyncGenerator; +export type MaybeAsyncGeneratorFunction = () => MaybeAsyncGenerator; export type Iteratee = (value: T, index: number) => R; +export type AsyncIteratee = (value: T, index: number) => Promise; export type MaybeAsyncIteratee = (value: T, index: number) => MaybePromise; export type TypeGuardIteratee = (value: T, index: number) => value is R; -export type MaybeAsyncTypeGuardIteratee = (value: MaybePromise, index: number) => - value is MaybePromise; + +// @ts-expect-error - This is an asyncronous type guard iteratee that guarantees the return value is a promise. +export type AsyncTypeGuardIteratee = (value: T, index: number) => value is Promise; + +// @ts-expect-error - This may be an asyncronous type guard iteratee that guarantees the return value may be a promise. +export type MaybeAsyncTypeGuardIteratee = (value: T, index: number) => value is MaybePromise; export type Reducer = (accumulator: A, value: T, index: number) => A; +export type AsyncReducer = (accumulator: A, value: T, index: number) => Promise; export type MaybeAsyncReducer = (accumulator: A, value: T, index: number) => MaybePromise; -export type IterLike = Iterable | Iterator | GeneratorFunction; -export type AsyncIterLike = - AsyncIterable | AsyncIterator | AsyncGeneratorFunction; - -export type MaybeAsyncIterLike = IterLike | AsyncIterLike; +export type IteratorLike = Iterable | Iterator; +export type AsyncIteratorLike = AsyncIterable | AsyncIterator; +export type MaybeAsyncIteratorLike = IteratorLike | AsyncIteratorLike; diff --git a/src/models/types.ts b/src/models/types.ts index 40ecd4e..6c267e5 100644 --- a/src/models/types.ts +++ b/src/models/types.ts @@ -1,10 +1,10 @@ export type { - KeyIteratee, - MaybeAsyncKeyIteratee, - KeyTypeGuardIteratee, - MaybeAsyncKeyTypeGuardIteratee, - KeyReducer, - MaybeAsyncKeyReducer + KeyedIteratee, + MaybeAsyncKeyedIteratee, + KeyedTypeGuardIteratee, + MaybeAsyncKeyedTypeGuardIteratee, + KeyedReducer, + MaybeAsyncKeyedReducer } from "./aggregators/types.js"; @@ -17,9 +17,9 @@ export type { MaybeAsyncTypeGuardIteratee, Reducer, MaybeAsyncReducer, - IterLike, - AsyncIterLike, - MaybeAsyncIterLike + IteratorLike, + AsyncIteratorLike, + MaybeAsyncIteratorLike } from "./iterators/types.js"; From 9dc82549518047ecc1ad3e0c09cad0a6b976b452 Mon Sep 17 00:00:00 2001 From: Matteo Bilotta Date: Mon, 23 Sep 2024 11:39:22 +0200 Subject: [PATCH 2/3] feat(iter): Updated iterators with some new logics & functionalities. --- package.json | 8 +- pnpm-lock.yaml | 260 +++++++++--------- .../aggregators/aggregated-async-iterator.ts | 181 +++++++----- src/models/aggregators/aggregated-iterator.ts | 120 +++----- src/models/aggregators/reduced-iterator.ts | 130 +++++++-- src/models/iterators/smart-async-iterator.ts | 2 +- src/models/promises/smart-promise.ts | 5 + src/models/timers/clock.ts | 2 +- src/models/timers/countdown.ts | 2 +- src/utils/async.ts | 8 +- 10 files changed, 406 insertions(+), 312 deletions(-) diff --git a/package.json b/package.json index c09d787..d8035a8 100644 --- a/package.json +++ b/package.json @@ -56,14 +56,14 @@ "ci": "pnpm install --frozen-lockfile" }, "devDependencies": { - "@byloth/eslint-config-typescript": "^2.8.2", + "@byloth/eslint-config-typescript": "^2.8.3", "@types/node": "^20.16.5", "@typescript-eslint/eslint-plugin": "^7.18.0", "@typescript-eslint/parser": "^7.18.0", - "eslint": "^8.57.0", - "husky": "^9.1.5", + "eslint": "^8.57.1", + "husky": "^9.1.6", "typescript": "^5.6.2", - "vite": "^5.4.3" + "vite": "^5.4.6" }, "packageManager": "pnpm@9.3.0+sha512.ee7b93e0c2bd11409c6424f92b866f31d3ea1bef5fbe47d3c7500cdc3c9668833d2e55681ad66df5b640c61fa9dc25d546efa54d76d7f8bf54b13614ac293631" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eb402f2..3a86a68 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,40 +9,40 @@ importers: .: devDependencies: '@byloth/eslint-config-typescript': - specifier: ^2.8.2 - version: 2.8.2(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)(typescript@5.6.2))(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0) + specifier: ^2.8.3 + version: 2.8.3(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.6.2))(eslint@8.57.1)(typescript@5.6.2))(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.6.2))(eslint@8.57.1) '@types/node': specifier: ^20.16.5 version: 20.16.5 '@typescript-eslint/eslint-plugin': specifier: ^7.18.0 - version: 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)(typescript@5.6.2) + version: 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.6.2))(eslint@8.57.1)(typescript@5.6.2) '@typescript-eslint/parser': specifier: ^7.18.0 - version: 7.18.0(eslint@8.57.0)(typescript@5.6.2) + version: 7.18.0(eslint@8.57.1)(typescript@5.6.2) eslint: - specifier: ^8.57.0 - version: 8.57.0 + specifier: ^8.57.1 + version: 8.57.1 husky: - specifier: ^9.1.5 - version: 9.1.5 + specifier: ^9.1.6 + version: 9.1.6 typescript: specifier: ^5.6.2 version: 5.6.2 vite: - specifier: ^5.4.3 - version: 5.4.3(@types/node@20.16.5) + specifier: ^5.4.6 + version: 5.4.6(@types/node@20.16.5) packages: - '@byloth/eslint-config-typescript@2.8.2': - resolution: {integrity: sha512-kpBhUJLj5Ckb95nuztZ28mOz0YWsWbOtRZPXiyHduyeYuZQINWweXmE1EJ04KSiRo2CsCyKjWHucfjq2B+KfkA==} + '@byloth/eslint-config-typescript@2.8.3': + resolution: {integrity: sha512-ehhfL1ikSxx0BcRqZM8UbLgtpI22QRuSqbxkXKVNrM/7mEjF8WuD2yn2O2MMxACg+CLWvFDYgG4t2VFUf34S1w==} peerDependencies: '@typescript-eslint/eslint-plugin': ^7.18.0 '@typescript-eslint/parser': ^7.18.0 - '@byloth/eslint-config@2.8.2': - resolution: {integrity: sha512-f5eZYx3CM97ith3Sf32GBIRPp8YLbZWAYPEwI4lJleFaOJi6r4hdoIF4XUqV3HZpJVD1MoLrvXO6pgHUiawHkw==} + '@byloth/eslint-config@2.8.3': + resolution: {integrity: sha512-wJxNanreXPeIiVuQMnxjy7muvjRbiPM/xZ0YHiSnmJ35FOc0QjbjZFnvLhZPntkMOKMwA1/CGT1zKt48lBoVrw==} peerDependencies: eslint: ^8.57.0 @@ -190,20 +190,20 @@ packages: peerDependencies: eslint: ^6.0.0 || ^7.0.0 || >=8.0.0 - '@eslint-community/regexpp@4.11.0': - resolution: {integrity: sha512-G/M/tIiMrTAxEWRfLfQJMmGNX28IxBg4PBz8XqQhqUHLFI6TL2htpIB1iQCj144V5ee/JaKyT9/WZ0MGZWfA7A==} + '@eslint-community/regexpp@4.11.1': + resolution: {integrity: sha512-m4DVN9ZqskZoLU5GlWZadwDnYo3vAEydiUayB9widCl9ffWx2IvPnp6n3on5rJmziJSw9Bv+Z3ChDVdMwXCY8Q==} engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} '@eslint/eslintrc@2.1.4': resolution: {integrity: sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - '@eslint/js@8.57.0': - resolution: {integrity: sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==} + '@eslint/js@8.57.1': + resolution: {integrity: sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - '@humanwhocodes/config-array@0.11.14': - resolution: {integrity: sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==} + '@humanwhocodes/config-array@0.13.0': + resolution: {integrity: sha512-DZLEEqFWQFiyK6h5YIeynKx7JlvCYWL0cImfSRXZ9l4Sg2efkFGTuFf6vzXjK1cq6IYkU+Eg/JizXw+TD2vRNw==} engines: {node: '>=10.10.0'} deprecated: Use @eslint/config-array instead @@ -227,83 +227,83 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} - '@rollup/rollup-android-arm-eabi@4.21.2': - resolution: {integrity: sha512-fSuPrt0ZO8uXeS+xP3b+yYTCBUd05MoSp2N/MFOgjhhUhMmchXlpTQrTpI8T+YAwAQuK7MafsCOxW7VrPMrJcg==} + '@rollup/rollup-android-arm-eabi@4.21.3': + resolution: {integrity: sha512-MmKSfaB9GX+zXl6E8z4koOr/xU63AMVleLEa64v7R0QF/ZloMs5vcD1sHgM64GXXS1csaJutG+ddtzcueI/BLg==} cpu: [arm] os: [android] - '@rollup/rollup-android-arm64@4.21.2': - resolution: {integrity: sha512-xGU5ZQmPlsjQS6tzTTGwMsnKUtu0WVbl0hYpTPauvbRAnmIvpInhJtgjj3mcuJpEiuUw4v1s4BimkdfDWlh7gA==} + '@rollup/rollup-android-arm64@4.21.3': + resolution: {integrity: sha512-zrt8ecH07PE3sB4jPOggweBjJMzI1JG5xI2DIsUbkA+7K+Gkjys6eV7i9pOenNSDJH3eOr/jLb/PzqtmdwDq5g==} cpu: [arm64] os: [android] - '@rollup/rollup-darwin-arm64@4.21.2': - resolution: {integrity: sha512-99AhQ3/ZMxU7jw34Sq8brzXqWH/bMnf7ZVhvLk9QU2cOepbQSVTns6qoErJmSiAvU3InRqC2RRZ5ovh1KN0d0Q==} + '@rollup/rollup-darwin-arm64@4.21.3': + resolution: {integrity: sha512-P0UxIOrKNBFTQaXTxOH4RxuEBVCgEA5UTNV6Yz7z9QHnUJ7eLX9reOd/NYMO3+XZO2cco19mXTxDMXxit4R/eQ==} cpu: [arm64] os: [darwin] - '@rollup/rollup-darwin-x64@4.21.2': - resolution: {integrity: sha512-ZbRaUvw2iN/y37x6dY50D8m2BnDbBjlnMPotDi/qITMJ4sIxNY33HArjikDyakhSv0+ybdUxhWxE6kTI4oX26w==} + '@rollup/rollup-darwin-x64@4.21.3': + resolution: {integrity: sha512-L1M0vKGO5ASKntqtsFEjTq/fD91vAqnzeaF6sfNAy55aD+Hi2pBI5DKwCO+UNDQHWsDViJLqshxOahXyLSh3EA==} cpu: [x64] os: [darwin] - '@rollup/rollup-linux-arm-gnueabihf@4.21.2': - resolution: {integrity: sha512-ztRJJMiE8nnU1YFcdbd9BcH6bGWG1z+jP+IPW2oDUAPxPjo9dverIOyXz76m6IPA6udEL12reYeLojzW2cYL7w==} + '@rollup/rollup-linux-arm-gnueabihf@4.21.3': + resolution: {integrity: sha512-btVgIsCjuYFKUjopPoWiDqmoUXQDiW2A4C3Mtmp5vACm7/GnyuprqIDPNczeyR5W8rTXEbkmrJux7cJmD99D2g==} cpu: [arm] os: [linux] - '@rollup/rollup-linux-arm-musleabihf@4.21.2': - resolution: {integrity: sha512-flOcGHDZajGKYpLV0JNc0VFH361M7rnV1ee+NTeC/BQQ1/0pllYcFmxpagltANYt8FYf9+kL6RSk80Ziwyhr7w==} + '@rollup/rollup-linux-arm-musleabihf@4.21.3': + resolution: {integrity: sha512-zmjbSphplZlau6ZTkxd3+NMtE4UKVy7U4aVFMmHcgO5CUbw17ZP6QCgyxhzGaU/wFFdTfiojjbLG3/0p9HhAqA==} cpu: [arm] os: [linux] - '@rollup/rollup-linux-arm64-gnu@4.21.2': - resolution: {integrity: sha512-69CF19Kp3TdMopyteO/LJbWufOzqqXzkrv4L2sP8kfMaAQ6iwky7NoXTp7bD6/irKgknDKM0P9E/1l5XxVQAhw==} + '@rollup/rollup-linux-arm64-gnu@4.21.3': + resolution: {integrity: sha512-nSZfcZtAnQPRZmUkUQwZq2OjQciR6tEoJaZVFvLHsj0MF6QhNMg0fQ6mUOsiCUpTqxTx0/O6gX0V/nYc7LrgPw==} cpu: [arm64] os: [linux] - '@rollup/rollup-linux-arm64-musl@4.21.2': - resolution: {integrity: sha512-48pD/fJkTiHAZTnZwR0VzHrao70/4MlzJrq0ZsILjLW/Ab/1XlVUStYyGt7tdyIiVSlGZbnliqmult/QGA2O2w==} + '@rollup/rollup-linux-arm64-musl@4.21.3': + resolution: {integrity: sha512-MnvSPGO8KJXIMGlQDYfvYS3IosFN2rKsvxRpPO2l2cum+Z3exiExLwVU+GExL96pn8IP+GdH8Tz70EpBhO0sIQ==} cpu: [arm64] os: [linux] - '@rollup/rollup-linux-powerpc64le-gnu@4.21.2': - resolution: {integrity: sha512-cZdyuInj0ofc7mAQpKcPR2a2iu4YM4FQfuUzCVA2u4HI95lCwzjoPtdWjdpDKyHxI0UO82bLDoOaLfpZ/wviyQ==} + '@rollup/rollup-linux-powerpc64le-gnu@4.21.3': + resolution: {integrity: sha512-+W+p/9QNDr2vE2AXU0qIy0qQE75E8RTwTwgqS2G5CRQ11vzq0tbnfBd6brWhS9bCRjAjepJe2fvvkvS3dno+iw==} cpu: [ppc64] os: [linux] - '@rollup/rollup-linux-riscv64-gnu@4.21.2': - resolution: {integrity: sha512-RL56JMT6NwQ0lXIQmMIWr1SW28z4E4pOhRRNqwWZeXpRlykRIlEpSWdsgNWJbYBEWD84eocjSGDu/XxbYeCmwg==} + '@rollup/rollup-linux-riscv64-gnu@4.21.3': + resolution: {integrity: sha512-yXH6K6KfqGXaxHrtr+Uoy+JpNlUlI46BKVyonGiaD74ravdnF9BUNC+vV+SIuB96hUMGShhKV693rF9QDfO6nQ==} cpu: [riscv64] os: [linux] - '@rollup/rollup-linux-s390x-gnu@4.21.2': - resolution: {integrity: sha512-PMxkrWS9z38bCr3rWvDFVGD6sFeZJw4iQlhrup7ReGmfn7Oukrr/zweLhYX6v2/8J6Cep9IEA/SmjXjCmSbrMQ==} + '@rollup/rollup-linux-s390x-gnu@4.21.3': + resolution: {integrity: sha512-R8cwY9wcnApN/KDYWTH4gV/ypvy9yZUHlbJvfaiXSB48JO3KpwSpjOGqO4jnGkLDSk1hgjYkTbTt6Q7uvPf8eg==} cpu: [s390x] os: [linux] - '@rollup/rollup-linux-x64-gnu@4.21.2': - resolution: {integrity: sha512-B90tYAUoLhU22olrafY3JQCFLnT3NglazdwkHyxNDYF/zAxJt5fJUB/yBoWFoIQ7SQj+KLe3iL4BhOMa9fzgpw==} + '@rollup/rollup-linux-x64-gnu@4.21.3': + resolution: {integrity: sha512-kZPbX/NOPh0vhS5sI+dR8L1bU2cSO9FgxwM8r7wHzGydzfSjLRCFAT87GR5U9scj2rhzN3JPYVC7NoBbl4FZ0g==} cpu: [x64] os: [linux] - '@rollup/rollup-linux-x64-musl@4.21.2': - resolution: {integrity: sha512-7twFizNXudESmC9oneLGIUmoHiiLppz/Xs5uJQ4ShvE6234K0VB1/aJYU3f/4g7PhssLGKBVCC37uRkkOi8wjg==} + '@rollup/rollup-linux-x64-musl@4.21.3': + resolution: {integrity: sha512-S0Yq+xA1VEH66uiMNhijsWAafffydd2X5b77eLHfRmfLsRSpbiAWiRHV6DEpz6aOToPsgid7TI9rGd6zB1rhbg==} cpu: [x64] os: [linux] - '@rollup/rollup-win32-arm64-msvc@4.21.2': - resolution: {integrity: sha512-9rRero0E7qTeYf6+rFh3AErTNU1VCQg2mn7CQcI44vNUWM9Ze7MSRS/9RFuSsox+vstRt97+x3sOhEey024FRQ==} + '@rollup/rollup-win32-arm64-msvc@4.21.3': + resolution: {integrity: sha512-9isNzeL34yquCPyerog+IMCNxKR8XYmGd0tHSV+OVx0TmE0aJOo9uw4fZfUuk2qxobP5sug6vNdZR6u7Mw7Q+Q==} cpu: [arm64] os: [win32] - '@rollup/rollup-win32-ia32-msvc@4.21.2': - resolution: {integrity: sha512-5rA4vjlqgrpbFVVHX3qkrCo/fZTj1q0Xxpg+Z7yIo3J2AilW7t2+n6Q8Jrx+4MrYpAnjttTYF8rr7bP46BPzRw==} + '@rollup/rollup-win32-ia32-msvc@4.21.3': + resolution: {integrity: sha512-nMIdKnfZfzn1Vsk+RuOvl43ONTZXoAPUUxgcU0tXooqg4YrAqzfKzVenqqk2g5efWh46/D28cKFrOzDSW28gTA==} cpu: [ia32] os: [win32] - '@rollup/rollup-win32-x64-msvc@4.21.2': - resolution: {integrity: sha512-6UUxd0+SKomjdzuAcp+HAmxw1FlGBnl1v2yEPSabtx4lBfdXHDVsW7+lQkgz9cNFJGY3AWR7+V8P5BqkD9L9nA==} + '@rollup/rollup-win32-x64-msvc@4.21.3': + resolution: {integrity: sha512-fOvu7PCQjAj4eWDEuD8Xz5gpzFqXzGlxHZozHP4b9Jxv9APtdxL6STqztDzMLuRXEc4UpXGGhx029Xgm91QBeA==} cpu: [x64] os: [win32] @@ -474,8 +474,8 @@ packages: resolution: {integrity: sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - eslint@8.57.0: - resolution: {integrity: sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==} + eslint@8.57.1: + resolution: {integrity: sha512-ypowyDxpVSYpkXr9WPv2PAZCtNip1Mv5KTW0SCurXv/9iOpcrH9PaqUElksqEB6pChqHGDRCFTyrZlGhnLNGiA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} hasBin: true @@ -569,8 +569,8 @@ packages: resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} engines: {node: '>=8'} - husky@9.1.5: - resolution: {integrity: sha512-rowAVRUBfI0b4+niA4SJMhfQwc107VLkBUgEYYAOQAbqDCnra1nYh83hF/MDmhYs9t9n1E3DuKOrs2LYNC+0Ag==} + husky@9.1.6: + resolution: {integrity: sha512-sqbjZKK7kf44hfdE94EoX8MZNk0n7HeW37O4YrVGCF4wzgQjp+akPAkfUK5LZ6KuR/6sqeAVuXHji+RzQgOn5A==} engines: {node: '>=18'} hasBin: true @@ -707,8 +707,8 @@ packages: resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} engines: {node: '>=8.6'} - postcss@8.4.45: - resolution: {integrity: sha512-7KTLTdzdZZYscUc65XmjFiB73vBhBfbPztCYdUNvlaso9PrzjzcmjqBPR0lNGkcVlcO4BjiO5rK/qNz+XAen1Q==} + postcss@8.4.47: + resolution: {integrity: sha512-56rxCq7G/XfB4EkXq9Egn5GCqugWvDFjafDOThIdMBsI15iqPqR5r15TfSr1YPYeEI19YeaXMCbY6u88Y76GLQ==} engines: {node: ^10 || ^12 || >=14} prelude-ls@1.2.1: @@ -735,8 +735,8 @@ packages: deprecated: Rimraf versions prior to v4 are no longer supported hasBin: true - rollup@4.21.2: - resolution: {integrity: sha512-e3TapAgYf9xjdLvKQCkQTnbTKd4a6jwlpQSJJFokHGaX2IVjoEqkIIhiQfqsi0cdwlOD+tQGuOd5AJkc5RngBw==} + rollup@4.21.3: + resolution: {integrity: sha512-7sqRtBNnEbcBtMeRVc6VRsJMmpI+JU1z9VTvW8D4gXIYQFz0aLcsE6rRkyghZkLfEgUZgVvOG7A5CVz/VW5GIA==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} hasBin: true @@ -808,8 +808,8 @@ packages: uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} - vite@5.4.3: - resolution: {integrity: sha512-IH+nl64eq9lJjFqU+/yrRnrHPVTlgy42/+IzbOdaFDVlyLgI/wDlf+FCobXLX1cT0X5+7LMyH1mIy2xJdLfo8Q==} + vite@5.4.6: + resolution: {integrity: sha512-IeL5f8OO5nylsgzd9tq4qD2QqI0k2CQLGrWD0rCN0EQJZpBK5vJAx0I+GDkMOXxQX/OfFHMuLIx6ddAxGX/k+Q==} engines: {node: ^18.0.0 || >=20.0.0} hasBin: true peerDependencies: @@ -857,17 +857,17 @@ packages: snapshots: - '@byloth/eslint-config-typescript@2.8.2(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)(typescript@5.6.2))(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)': + '@byloth/eslint-config-typescript@2.8.3(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.6.2))(eslint@8.57.1)(typescript@5.6.2))(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.6.2))(eslint@8.57.1)': dependencies: - '@byloth/eslint-config': 2.8.2(eslint@8.57.0) - '@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)(typescript@5.6.2) - '@typescript-eslint/parser': 7.18.0(eslint@8.57.0)(typescript@5.6.2) + '@byloth/eslint-config': 2.8.3(eslint@8.57.1) + '@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.6.2))(eslint@8.57.1)(typescript@5.6.2) + '@typescript-eslint/parser': 7.18.0(eslint@8.57.1)(typescript@5.6.2) transitivePeerDependencies: - eslint - '@byloth/eslint-config@2.8.2(eslint@8.57.0)': + '@byloth/eslint-config@2.8.3(eslint@8.57.1)': dependencies: - eslint: 8.57.0 + eslint: 8.57.1 '@esbuild/aix-ppc64@0.21.5': optional: true @@ -938,12 +938,12 @@ snapshots: '@esbuild/win32-x64@0.21.5': optional: true - '@eslint-community/eslint-utils@4.4.0(eslint@8.57.0)': + '@eslint-community/eslint-utils@4.4.0(eslint@8.57.1)': dependencies: - eslint: 8.57.0 + eslint: 8.57.1 eslint-visitor-keys: 3.4.3 - '@eslint-community/regexpp@4.11.0': {} + '@eslint-community/regexpp@4.11.1': {} '@eslint/eslintrc@2.1.4': dependencies: @@ -959,9 +959,9 @@ snapshots: transitivePeerDependencies: - supports-color - '@eslint/js@8.57.0': {} + '@eslint/js@8.57.1': {} - '@humanwhocodes/config-array@0.11.14': + '@humanwhocodes/config-array@0.13.0': dependencies: '@humanwhocodes/object-schema': 2.0.3 debug: 4.3.7 @@ -985,52 +985,52 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.17.1 - '@rollup/rollup-android-arm-eabi@4.21.2': + '@rollup/rollup-android-arm-eabi@4.21.3': optional: true - '@rollup/rollup-android-arm64@4.21.2': + '@rollup/rollup-android-arm64@4.21.3': optional: true - '@rollup/rollup-darwin-arm64@4.21.2': + '@rollup/rollup-darwin-arm64@4.21.3': optional: true - '@rollup/rollup-darwin-x64@4.21.2': + '@rollup/rollup-darwin-x64@4.21.3': optional: true - '@rollup/rollup-linux-arm-gnueabihf@4.21.2': + '@rollup/rollup-linux-arm-gnueabihf@4.21.3': optional: true - '@rollup/rollup-linux-arm-musleabihf@4.21.2': + '@rollup/rollup-linux-arm-musleabihf@4.21.3': optional: true - '@rollup/rollup-linux-arm64-gnu@4.21.2': + '@rollup/rollup-linux-arm64-gnu@4.21.3': optional: true - '@rollup/rollup-linux-arm64-musl@4.21.2': + '@rollup/rollup-linux-arm64-musl@4.21.3': optional: true - '@rollup/rollup-linux-powerpc64le-gnu@4.21.2': + '@rollup/rollup-linux-powerpc64le-gnu@4.21.3': optional: true - '@rollup/rollup-linux-riscv64-gnu@4.21.2': + '@rollup/rollup-linux-riscv64-gnu@4.21.3': optional: true - '@rollup/rollup-linux-s390x-gnu@4.21.2': + '@rollup/rollup-linux-s390x-gnu@4.21.3': optional: true - '@rollup/rollup-linux-x64-gnu@4.21.2': + '@rollup/rollup-linux-x64-gnu@4.21.3': optional: true - '@rollup/rollup-linux-x64-musl@4.21.2': + '@rollup/rollup-linux-x64-musl@4.21.3': optional: true - '@rollup/rollup-win32-arm64-msvc@4.21.2': + '@rollup/rollup-win32-arm64-msvc@4.21.3': optional: true - '@rollup/rollup-win32-ia32-msvc@4.21.2': + '@rollup/rollup-win32-ia32-msvc@4.21.3': optional: true - '@rollup/rollup-win32-x64-msvc@4.21.2': + '@rollup/rollup-win32-x64-msvc@4.21.3': optional: true '@types/estree@1.0.5': {} @@ -1039,15 +1039,15 @@ snapshots: dependencies: undici-types: 6.19.8 - '@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)(typescript@5.6.2)': + '@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.6.2))(eslint@8.57.1)(typescript@5.6.2)': dependencies: - '@eslint-community/regexpp': 4.11.0 - '@typescript-eslint/parser': 7.18.0(eslint@8.57.0)(typescript@5.6.2) + '@eslint-community/regexpp': 4.11.1 + '@typescript-eslint/parser': 7.18.0(eslint@8.57.1)(typescript@5.6.2) '@typescript-eslint/scope-manager': 7.18.0 - '@typescript-eslint/type-utils': 7.18.0(eslint@8.57.0)(typescript@5.6.2) - '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.6.2) + '@typescript-eslint/type-utils': 7.18.0(eslint@8.57.1)(typescript@5.6.2) + '@typescript-eslint/utils': 7.18.0(eslint@8.57.1)(typescript@5.6.2) '@typescript-eslint/visitor-keys': 7.18.0 - eslint: 8.57.0 + eslint: 8.57.1 graphemer: 1.4.0 ignore: 5.3.2 natural-compare: 1.4.0 @@ -1057,14 +1057,14 @@ snapshots: transitivePeerDependencies: - supports-color - '@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.6.2)': + '@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.6.2)': dependencies: '@typescript-eslint/scope-manager': 7.18.0 '@typescript-eslint/types': 7.18.0 '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.6.2) '@typescript-eslint/visitor-keys': 7.18.0 debug: 4.3.7 - eslint: 8.57.0 + eslint: 8.57.1 optionalDependencies: typescript: 5.6.2 transitivePeerDependencies: @@ -1075,12 +1075,12 @@ snapshots: '@typescript-eslint/types': 7.18.0 '@typescript-eslint/visitor-keys': 7.18.0 - '@typescript-eslint/type-utils@7.18.0(eslint@8.57.0)(typescript@5.6.2)': + '@typescript-eslint/type-utils@7.18.0(eslint@8.57.1)(typescript@5.6.2)': dependencies: '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.6.2) - '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.6.2) + '@typescript-eslint/utils': 7.18.0(eslint@8.57.1)(typescript@5.6.2) debug: 4.3.7 - eslint: 8.57.0 + eslint: 8.57.1 ts-api-utils: 1.3.0(typescript@5.6.2) optionalDependencies: typescript: 5.6.2 @@ -1104,13 +1104,13 @@ snapshots: transitivePeerDependencies: - supports-color - '@typescript-eslint/utils@7.18.0(eslint@8.57.0)(typescript@5.6.2)': + '@typescript-eslint/utils@7.18.0(eslint@8.57.1)(typescript@5.6.2)': dependencies: - '@eslint-community/eslint-utils': 4.4.0(eslint@8.57.0) + '@eslint-community/eslint-utils': 4.4.0(eslint@8.57.1) '@typescript-eslint/scope-manager': 7.18.0 '@typescript-eslint/types': 7.18.0 '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.6.2) - eslint: 8.57.0 + eslint: 8.57.1 transitivePeerDependencies: - supports-color - typescript @@ -1230,13 +1230,13 @@ snapshots: eslint-visitor-keys@3.4.3: {} - eslint@8.57.0: + eslint@8.57.1: dependencies: - '@eslint-community/eslint-utils': 4.4.0(eslint@8.57.0) - '@eslint-community/regexpp': 4.11.0 + '@eslint-community/eslint-utils': 4.4.0(eslint@8.57.1) + '@eslint-community/regexpp': 4.11.1 '@eslint/eslintrc': 2.1.4 - '@eslint/js': 8.57.0 - '@humanwhocodes/config-array': 0.11.14 + '@eslint/js': 8.57.1 + '@humanwhocodes/config-array': 0.13.0 '@humanwhocodes/module-importer': 1.0.1 '@nodelib/fs.walk': 1.2.8 '@ungap/structured-clone': 1.2.0 @@ -1369,7 +1369,7 @@ snapshots: has-flag@4.0.0: {} - husky@9.1.5: {} + husky@9.1.6: {} ignore@5.3.2: {} @@ -1482,7 +1482,7 @@ snapshots: picomatch@2.3.1: {} - postcss@8.4.45: + postcss@8.4.47: dependencies: nanoid: 3.3.7 picocolors: 1.1.0 @@ -1502,26 +1502,26 @@ snapshots: dependencies: glob: 7.2.3 - rollup@4.21.2: + rollup@4.21.3: dependencies: '@types/estree': 1.0.5 optionalDependencies: - '@rollup/rollup-android-arm-eabi': 4.21.2 - '@rollup/rollup-android-arm64': 4.21.2 - '@rollup/rollup-darwin-arm64': 4.21.2 - '@rollup/rollup-darwin-x64': 4.21.2 - '@rollup/rollup-linux-arm-gnueabihf': 4.21.2 - '@rollup/rollup-linux-arm-musleabihf': 4.21.2 - '@rollup/rollup-linux-arm64-gnu': 4.21.2 - '@rollup/rollup-linux-arm64-musl': 4.21.2 - '@rollup/rollup-linux-powerpc64le-gnu': 4.21.2 - '@rollup/rollup-linux-riscv64-gnu': 4.21.2 - '@rollup/rollup-linux-s390x-gnu': 4.21.2 - '@rollup/rollup-linux-x64-gnu': 4.21.2 - '@rollup/rollup-linux-x64-musl': 4.21.2 - '@rollup/rollup-win32-arm64-msvc': 4.21.2 - '@rollup/rollup-win32-ia32-msvc': 4.21.2 - '@rollup/rollup-win32-x64-msvc': 4.21.2 + '@rollup/rollup-android-arm-eabi': 4.21.3 + '@rollup/rollup-android-arm64': 4.21.3 + '@rollup/rollup-darwin-arm64': 4.21.3 + '@rollup/rollup-darwin-x64': 4.21.3 + '@rollup/rollup-linux-arm-gnueabihf': 4.21.3 + '@rollup/rollup-linux-arm-musleabihf': 4.21.3 + '@rollup/rollup-linux-arm64-gnu': 4.21.3 + '@rollup/rollup-linux-arm64-musl': 4.21.3 + '@rollup/rollup-linux-powerpc64le-gnu': 4.21.3 + '@rollup/rollup-linux-riscv64-gnu': 4.21.3 + '@rollup/rollup-linux-s390x-gnu': 4.21.3 + '@rollup/rollup-linux-x64-gnu': 4.21.3 + '@rollup/rollup-linux-x64-musl': 4.21.3 + '@rollup/rollup-win32-arm64-msvc': 4.21.3 + '@rollup/rollup-win32-ia32-msvc': 4.21.3 + '@rollup/rollup-win32-x64-msvc': 4.21.3 fsevents: 2.3.3 run-parallel@1.2.0: @@ -1574,11 +1574,11 @@ snapshots: dependencies: punycode: 2.3.1 - vite@5.4.3(@types/node@20.16.5): + vite@5.4.6(@types/node@20.16.5): dependencies: esbuild: 0.21.5 - postcss: 8.4.45 - rollup: 4.21.2 + postcss: 8.4.47 + rollup: 4.21.3 optionalDependencies: '@types/node': 20.16.5 fsevents: 2.3.3 diff --git a/src/models/aggregators/aggregated-async-iterator.ts b/src/models/aggregators/aggregated-async-iterator.ts index 02bba39..d5b8ad8 100644 --- a/src/models/aggregators/aggregated-async-iterator.ts +++ b/src/models/aggregators/aggregated-async-iterator.ts @@ -29,44 +29,38 @@ export default class AggregatedAsyncIterator public async every(predicate: MaybeAsyncKeyedIteratee): Promise> { - const indexes = new Map(); + const values = new Map(); for await (const [key, element] of this._elements) { - const [index, result] = indexes.get(key) ?? [0, true]; + const [index, result] = values.get(key) ?? [0, true]; if (!(result)) { continue; } - indexes.set(key, [index + 1, await predicate(key, element, index)]); + values.set(key, [index + 1, await predicate(key, element, index)]); } return new ReducedIterator(function* () { - for (const [key, [_, result]] of indexes) - { - yield [key, result]; - } + for (const [key, [_, result]] of values) { yield [key, result]; } }); } public async some(predicate: MaybeAsyncKeyedIteratee): Promise> { - const indexes = new Map(); + const values = new Map(); for await (const [key, element] of this._elements) { - const [index, result] = indexes.get(key) ?? [0, false]; + const [index, result] = values.get(key) ?? [0, false]; if (result) { continue; } - indexes.set(key, [index + 1, await predicate(key, element, index)]); + values.set(key, [index + 1, await predicate(key, element, index)]); } return new ReducedIterator(function* () { - for (const [key, [_, result]] of indexes) - { - yield [key, result]; - } + for (const [key, [_, result]] of values) { yield [key, result]; } }); } @@ -84,9 +78,9 @@ export default class AggregatedAsyncIterator { const index = indexes.get(key) ?? 0; - indexes.set(key, index + 1); - if (await predicate(key, element, index)) { yield [key, element]; } + + indexes.set(key, index + 1); } }); } @@ -102,9 +96,9 @@ export default class AggregatedAsyncIterator { const index = indexes.get(key) ?? 0; - indexes.set(key, index + 1); - yield [key, await iteratee(key, element, index)]; + + indexes.set(key, index + 1); } }); } @@ -114,19 +108,14 @@ export default class AggregatedAsyncIterator public async reduce(reducer: MaybeAsyncKeyedReducer, initialValue?: (key: K) => MaybePromise) : Promise> { - const accumulators = new Map(); + const values = new Map(); for await (const [key, element] of this._elements) { let index: number; let accumulator: A; - if (accumulators.has(key)) - { - [index, accumulator] = accumulators.get(key)!; - - index += 1; - } + if (values.has(key)) { [index, accumulator] = values.get(key)!; } else if (initialValue !== undefined) { index = 0; @@ -134,103 +123,164 @@ export default class AggregatedAsyncIterator } else { - accumulators.set(key, [0, (element as unknown) as A]); + values.set(key, [0, (element as unknown) as A]); continue; } - accumulator = await reducer(key, accumulator, element, index); - - accumulators.set(key, [index, accumulator]); + values.set(key, [index + 1, await reducer(key, accumulator, element, index)]); } return new ReducedIterator(function* () { - for (const [key, [_, accumulator]] of accumulators) + for (const [key, [_, accumulator]] of values) { yield [key, accumulator]; } + }); + } + + public flatMap(iteratee: MaybeAsyncKeyedIteratee>): AggregatedAsyncIterator + { + const elements = this._elements; + + return new AggregatedAsyncIterator(async function* (): AsyncGenerator<[K, V]> + { + const indexes = new Map(); + + for await (const [key, element] of elements) { - yield [key, accumulator]; + const index = indexes.get(key) ?? 0; + const values = await iteratee(key, element, index); + + for await (const value of values) { yield [key, value]; } + + indexes.set(key, index + 1); } }); } - public unique(): AggregatedAsyncIterator + public drop(count: number): AggregatedAsyncIterator { const elements = this._elements; return new AggregatedAsyncIterator(async function* (): AsyncGenerator<[K, T]> { - const keys = new Map>(); + const indexes = new Map(); for await (const [key, element] of elements) { - const values = keys.get(key) ?? new Set(); - - if (values.has(element)) { continue; } + const index = indexes.get(key) ?? 0; + if (index < count) + { + indexes.set(key, index + 1); - values.add(element); - keys.set(key, values); + continue; + } yield [key, element]; } }); } - - public async count(): Promise> + public take(limit: number): AggregatedAsyncIterator { - const counters = new Map(); + const elements = this._elements; - for await (const [key] of this._elements) + return new AggregatedAsyncIterator(async function* (): AsyncGenerator<[K, T]> { - const count = counters.get(key) ?? 0; - - counters.set(key, count + 1); - } + const indexes = new Map(); - return new ReducedIterator(function* () - { - for (const [key, count] of counters) + for await (const [key, element] of elements) { - yield [key, count]; + const index = indexes.get(key) ?? 0; + if (index >= limit) + { + if (indexes.values().every((value) => value >= limit)) { break; } + + continue; + } + + yield [key, element]; + + indexes.set(key, index + 1); } }); } - public async first(): Promise> + + public async find(predicate: MaybeAsyncKeyedIteratee): Promise>; + public async find(predicate: MaybeAsyncKeyedTypeGuardIteratee) + : Promise>; + + public async find(predicate: MaybeAsyncKeyedIteratee): Promise> { - const firsts = new Map(); + const values = new Map(); for await (const [key, element] of this._elements) { - if (firsts.has(key)) { continue; } + let [index, finding] = values.get(key) ?? [0, undefined]; - firsts.set(key, element); + if (finding !== undefined) { continue; } + if (await predicate(key, element, index)) { finding = element; } + + values.set(key, [index + 1, finding]); } return new ReducedIterator(function* () { - for (const [key, element] of firsts) + for (const [key, [_, finding]] of values) { yield [key, finding]; } + }); + } + + public unique(): AggregatedAsyncIterator + { + const elements = this._elements; + + return new AggregatedAsyncIterator(async function* (): AsyncGenerator<[K, T]> + { + const keys = new Map>(); + + for await (const [key, element] of elements) { + const values = keys.get(key) ?? new Set(); + + if (values.has(element)) { continue; } + + values.add(element); + keys.set(key, values); + yield [key, element]; } }); } - public async last(): Promise> + + public async count(): Promise> { - const lasts = new Map(); + const counters = new Map(); - for await (const [key, element] of this._elements) + for await (const [key] of this._elements) { - lasts.set(key, element); + const count = counters.get(key) ?? 0; + + counters.set(key, count + 1); } return new ReducedIterator(function* () { - for (const [key, element] of lasts) - { - yield [key, element]; - } + for (const [key, count] of counters) { yield [key, count]; } }); } + public async forEach(iteratee: MaybeAsyncKeyedIteratee): Promise + { + const indexes = new Map(); + + for await (const [key, element] of this._elements) + { + const index = indexes.get(key) ?? 0; + + iteratee(key, element, index); + + indexes.set(key, index + 1); + } + } + public keys(): SmartAsyncIterator { const elements = this._elements; @@ -258,10 +308,7 @@ export default class AggregatedAsyncIterator return new SmartAsyncIterator(async function* () { - for await (const [_, element] of elements) - { - yield element; - } + for await (const [_, element] of elements) { yield element; } }); } diff --git a/src/models/aggregators/aggregated-iterator.ts b/src/models/aggregators/aggregated-iterator.ts index a1f4e04..97074fa 100644 --- a/src/models/aggregators/aggregated-iterator.ts +++ b/src/models/aggregators/aggregated-iterator.ts @@ -19,44 +19,38 @@ export default class AggregatedIterator public every(predicate: KeyedIteratee): ReducedIterator { - const indexes = new Map(); + const values = new Map(); for (const [key, element] of this._elements) { - const [index, result] = indexes.get(key) ?? [0, true]; + const [index, result] = values.get(key) ?? [0, true]; if (!(result)) { continue; } - indexes.set(key, [index + 1, predicate(key, element, index)]); + values.set(key, [index + 1, predicate(key, element, index)]); } return new ReducedIterator(function* () { - for (const [key, [_, result]] of indexes) - { - yield [key, result]; - } + for (const [key, [_, result]] of values) { yield [key, result]; } }); } public some(predicate: KeyedIteratee): ReducedIterator { - const indexes = new Map(); + const values = new Map(); for (const [key, element] of this._elements) { - const [index, result] = indexes.get(key) ?? [0, false]; + const [index, result] = values.get(key) ?? [0, false]; if (result) { continue; } - indexes.set(key, [index + 1, predicate(key, element, index)]); + values.set(key, [index + 1, predicate(key, element, index)]); } return new ReducedIterator(function* () { - for (const [key, [_, result]] of indexes) - { - yield [key, result]; - } + for (const [key, [_, result]] of values) { yield [key, result]; } }); } @@ -102,14 +96,14 @@ export default class AggregatedIterator public reduce(reducer: KeyedReducer, initialValue: (key: K) => A): ReducedIterator; public reduce(reducer: KeyedReducer, initialValue?: (key: K) => A): ReducedIterator { - const accumulators = new Map(); + const values = new Map(); for (const [key, element] of this._elements) { let index: number; let accumulator: A; - if (accumulators.has(key)) { [index, accumulator] = accumulators.get(key)!; } + if (values.has(key)) { [index, accumulator] = values.get(key)!; } else if (initialValue !== undefined) { index = 0; @@ -117,22 +111,17 @@ export default class AggregatedIterator } else { - accumulators.set(key, [0, (element as unknown) as A]); + values.set(key, [0, (element as unknown) as A]); continue; } - accumulator = reducer(key, accumulator, element, index); - - accumulators.set(key, [index + 1, accumulator]); + values.set(key, [index + 1, reducer(key, accumulator, element, index)]); } return new ReducedIterator(function* () { - for (const [key, [_, accumulator]] of accumulators) - { - yield [key, accumulator]; - } + for (const [key, [_, accumulator]] of values) { yield [key, accumulator]; } }); } @@ -147,11 +136,9 @@ export default class AggregatedIterator for (const [key, element] of elements) { const index = indexes.get(key) ?? 0; + const values = iteratee(key, element, index); - for (const value of iteratee(key, element, index)) - { - yield [key, value]; - } + for (const value of values) { yield [key, value]; } indexes.set(key, index + 1); } @@ -198,9 +185,9 @@ export default class AggregatedIterator continue; } - indexes.set(key, index + 1); - yield [key, element]; + + indexes.set(key, index + 1); } }); } @@ -209,27 +196,21 @@ export default class AggregatedIterator public find(predicate: KeyedTypeGuardIteratee): ReducedIterator; public find(predicate: KeyedIteratee): ReducedIterator { - const elements = this._elements; + const values = new Map(); - return new ReducedIterator(function* () + for (const [key, element] of this._elements) { - const indexes = new Map(); - const findings = new Set(); + let [index, finding] = values.get(key) ?? [0, undefined]; - for (const [key, element] of elements) - { - if (findings.has(key)) { continue; } + if (finding !== undefined) { continue; } + if (predicate(key, element, index)) { finding = element; } - const index = indexes.get(key) ?? 0; - if (predicate(key, element, index)) - { - yield [key, element]; - - findings.add(key); - } + values.set(key, [index + 1, finding]); + } - indexes.set(key, index + 1); - } + return new ReducedIterator(function* () + { + for (const [key, [_, finding]] of values) { yield [key, finding]; } }); } @@ -272,48 +253,22 @@ export default class AggregatedIterator return new ReducedIterator(function* () { - for (const [key, count] of counters) - { - yield [key, count]; - } + for (const [key, count] of counters) { yield [key, count]; } }); } - public first(): ReducedIterator + public forEach(iteratee: KeyedIteratee): void { - const firsts = new Map(); + const indexes = new Map(); for (const [key, element] of this._elements) { - if (firsts.has(key)) { continue; } + const index = indexes.get(key) ?? 0; - firsts.set(key, element); - } - - return new ReducedIterator(function* () - { - for (const [key, element] of firsts) - { - yield [key, element]; - } - }); - } - public last(): ReducedIterator - { - const lasts = new Map(); + iteratee(key, element, index); - for (const [key, element] of this._elements) - { - lasts.set(key, element); + indexes.set(key, index + 1); } - - return new ReducedIterator(function* () - { - for (const [key, element] of lasts) - { - yield [key, element]; - } - }); } public keys(): SmartIterator @@ -343,16 +298,15 @@ export default class AggregatedIterator return new SmartIterator(function* () { - for (const [_, element] of elements) - { - yield element; - } + for (const [_, element] of elements) { yield element; } }); } public toArray(): T[][] { - return Array.from(this.toMap().values()); + const map = this.toMap(); + + return Array.from(map.values()); } public toMap(): Map { diff --git a/src/models/aggregators/reduced-iterator.ts b/src/models/aggregators/reduced-iterator.ts index b57678b..e520273 100644 --- a/src/models/aggregators/reduced-iterator.ts +++ b/src/models/aggregators/reduced-iterator.ts @@ -2,6 +2,7 @@ import { ValueException } from "../exceptions/index.js"; import { SmartIterator } from "../iterators/index.js"; import type { GeneratorFunction } from "../iterators/types.js"; +import AggregatedIterator from "./aggregated-iterator.js"; import type { KeyedIteratee, KeyedReducer, KeyedTypeGuardIteratee } from "./types.js"; export default class ReducedIterator @@ -17,30 +18,46 @@ export default class ReducedIterator this._elements = new SmartIterator(argument); } + public every(predicate: KeyedIteratee): boolean + { + for (const [index, [key, element]] of this._elements.enumerate()) + { + if (!(predicate(key, element, index))) { return false; } + } + + return true; + } + public some(predicate: KeyedIteratee): boolean + { + for (const [index, [key, element]] of this._elements.enumerate()) + { + if (predicate(key, element, index)) { return true; } + } + + return false; + } + public filter(predicate: KeyedIteratee): ReducedIterator; public filter(predicate: KeyedTypeGuardIteratee): ReducedIterator; public filter(predicate: KeyedIteratee): ReducedIterator { - const elements = this._elements; + const elements = this._elements.enumerate(); return new ReducedIterator(function* () { - for (const [index, [key, element]] of elements.enumerate()) + for (const [index, [key, element]] of elements) { - if (predicate(key, element, index)) - { - yield [key, element]; - } + if (predicate(key, element, index)) { yield [key, element]; } } }); } public map(iteratee: KeyedIteratee): ReducedIterator { - const elements = this._elements; + const elements = this._elements.enumerate(); return new ReducedIterator(function* () { - for (const [index, [key, element]] of elements.enumerate()) + for (const [index, [key, element]] of elements) { yield [key, iteratee(key, element, index)]; } @@ -51,22 +68,14 @@ export default class ReducedIterator public reduce(reducer: KeyedReducer, initialValue?: A): A { let index = 0; - let accumulator: A; - - if (initialValue !== undefined) + let accumulator = initialValue; + if (accumulator === undefined) { - accumulator = initialValue; - } - else - { - const firstElement = this._elements.next(); - if (firstElement.done) - { - throw new ValueException("Cannot reduce an empty iterator without an initial value."); - } + const result = this._elements.next(); + if (result.done) { throw new ValueException("Cannot reduce an empty iterator without an initial value."); } + accumulator = (result.value[1] as unknown) as A; index += 1; - accumulator = (firstElement.value[1] as unknown) as A; } for (const [key, element] of this._elements) @@ -79,6 +88,85 @@ export default class ReducedIterator return accumulator; } + public flatMap(iteratee: KeyedIteratee>): AggregatedIterator + { + const elements = this._elements.enumerate(); + + return new AggregatedIterator(function* () + { + for (const [index, [key, element]] of elements) + { + for (const value of iteratee(key, element, index)) { yield [key, value]; } + } + }); + } + + public drop(count: number): ReducedIterator + { + const elements = this._elements.enumerate(); + + return new ReducedIterator(function* () + { + for (const [index, [key, element]] of elements) + { + if (index >= count) { yield [key, element]; } + } + }); + } + public take(count: number): ReducedIterator + { + const elements = this._elements.enumerate(); + + return new ReducedIterator(function* () + { + for (const [index, [key, element]] of elements) + { + if (index >= count) { break; } + + yield [key, element]; + } + }); + } + + public enumerate(): ReducedIterator + { + return this.map((_, element, index) => [index, element]); + } + public unique(): ReducedIterator + { + const elements = this._elements; + + return new ReducedIterator(function* () + { + const values = new Set(); + + for (const [key, element] of elements) + { + if (values.has(element)) { continue; } + values.add(element); + + yield [key, element]; + } + }); + } + + public count(): number + { + let index = 0; + + for (const _ of this._elements) { index += 1; } + + return index; + } + + public forEach(iteratee: KeyedIteratee): void + { + for (const [index, [key, element]] of this._elements.enumerate()) + { + iteratee(key, element, index); + } + } + public keys(): SmartIterator { const elements = this._elements; diff --git a/src/models/iterators/smart-async-iterator.ts b/src/models/iterators/smart-async-iterator.ts index faec0c7..c59de76 100644 --- a/src/models/iterators/smart-async-iterator.ts +++ b/src/models/iterators/smart-async-iterator.ts @@ -349,7 +349,7 @@ export default class SmartAsyncIterator implements A })); } - public async toArray(): Promise + public toArray(): Promise { return Array.fromAsync(this as AsyncIterable); } diff --git a/src/models/promises/smart-promise.ts b/src/models/promises/smart-promise.ts index de4f8be..cc0c338 100644 --- a/src/models/promises/smart-promise.ts +++ b/src/models/promises/smart-promise.ts @@ -2,6 +2,11 @@ import type { FulfilledHandler, PromiseExecutor, RejectedHandler } from "./types export default class SmartPromise implements Promise { + public static FromPromise(promise: Promise): SmartPromise + { + return new SmartPromise((resolve, reject) => promise.then(resolve, reject)); + } + protected _isPending: boolean; protected _isFulfilled: boolean; protected _isRejected: boolean; diff --git a/src/models/timers/clock.ts b/src/models/timers/clock.ts index e392a6e..6c4e0ba 100644 --- a/src/models/timers/clock.ts +++ b/src/models/timers/clock.ts @@ -6,7 +6,7 @@ import Publisher from "../publisher.js"; export default class Clock extends GameLoop { - protected _publisher: Publisher<[number], void>; + protected _publisher: Publisher<[number]>; public constructor(fpsIfNotBrowser = TimeUnit.Second) { diff --git a/src/models/timers/countdown.ts b/src/models/timers/countdown.ts index ea99d4f..e8fe0c1 100644 --- a/src/models/timers/countdown.ts +++ b/src/models/timers/countdown.ts @@ -9,7 +9,7 @@ import Publisher from "../publisher.js"; export default class Countdown extends GameLoop { protected _deferrer?: DeferredPromise; - protected _publisher: Publisher<[number], void>; + protected _publisher: Publisher<[number]>; protected _duration: number; public get duration(): number diff --git a/src/utils/async.ts b/src/utils/async.ts index 1727bfe..9c345bd 100644 --- a/src/utils/async.ts +++ b/src/utils/async.ts @@ -1,9 +1,9 @@ -export async function delay(milliseconds: number): Promise +export function delay(milliseconds: number): Promise { - return new Promise((resolve, reject) => setTimeout(resolve, milliseconds)); + return new Promise((resolve) => setTimeout(resolve, milliseconds)); } -export async function nextAnimationFrame(): Promise +export function nextAnimationFrame(): Promise { - return new Promise((resolve, reject) => requestAnimationFrame(() => resolve())); + return new Promise((resolve) => requestAnimationFrame(() => resolve())); } From d26502692d2ac6bb2ea2ae49783e0f8c945903ad Mon Sep 17 00:00:00 2001 From: Matteo Bilotta Date: Mon, 23 Sep 2024 11:42:42 +0200 Subject: [PATCH 3/3] =?UTF-8?q?build:=20Updated=20dependencies.=20?= =?UTF-8?q?=F0=9F=94=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- pnpm-lock.yaml | 146 ++++++++++++++++++++++++------------------------- 2 files changed, 74 insertions(+), 74 deletions(-) diff --git a/package.json b/package.json index d8035a8..e861a7f 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "eslint": "^8.57.1", "husky": "^9.1.6", "typescript": "^5.6.2", - "vite": "^5.4.6" + "vite": "^5.4.7" }, "packageManager": "pnpm@9.3.0+sha512.ee7b93e0c2bd11409c6424f92b866f31d3ea1bef5fbe47d3c7500cdc3c9668833d2e55681ad66df5b640c61fa9dc25d546efa54d76d7f8bf54b13614ac293631" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3a86a68..a17c2f2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^5.6.2 version: 5.6.2 vite: - specifier: ^5.4.6 - version: 5.4.6(@types/node@20.16.5) + specifier: ^5.4.7 + version: 5.4.7(@types/node@20.16.5) packages: @@ -227,83 +227,83 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} - '@rollup/rollup-android-arm-eabi@4.21.3': - resolution: {integrity: sha512-MmKSfaB9GX+zXl6E8z4koOr/xU63AMVleLEa64v7R0QF/ZloMs5vcD1sHgM64GXXS1csaJutG+ddtzcueI/BLg==} + '@rollup/rollup-android-arm-eabi@4.22.4': + resolution: {integrity: sha512-Fxamp4aEZnfPOcGA8KSNEohV8hX7zVHOemC8jVBoBUHu5zpJK/Eu3uJwt6BMgy9fkvzxDaurgj96F/NiLukF2w==} cpu: [arm] os: [android] - '@rollup/rollup-android-arm64@4.21.3': - resolution: {integrity: sha512-zrt8ecH07PE3sB4jPOggweBjJMzI1JG5xI2DIsUbkA+7K+Gkjys6eV7i9pOenNSDJH3eOr/jLb/PzqtmdwDq5g==} + '@rollup/rollup-android-arm64@4.22.4': + resolution: {integrity: sha512-VXoK5UMrgECLYaMuGuVTOx5kcuap1Jm8g/M83RnCHBKOqvPPmROFJGQaZhGccnsFtfXQ3XYa4/jMCJvZnbJBdA==} cpu: [arm64] os: [android] - '@rollup/rollup-darwin-arm64@4.21.3': - resolution: {integrity: sha512-P0UxIOrKNBFTQaXTxOH4RxuEBVCgEA5UTNV6Yz7z9QHnUJ7eLX9reOd/NYMO3+XZO2cco19mXTxDMXxit4R/eQ==} + '@rollup/rollup-darwin-arm64@4.22.4': + resolution: {integrity: sha512-xMM9ORBqu81jyMKCDP+SZDhnX2QEVQzTcC6G18KlTQEzWK8r/oNZtKuZaCcHhnsa6fEeOBionoyl5JsAbE/36Q==} cpu: [arm64] os: [darwin] - '@rollup/rollup-darwin-x64@4.21.3': - resolution: {integrity: sha512-L1M0vKGO5ASKntqtsFEjTq/fD91vAqnzeaF6sfNAy55aD+Hi2pBI5DKwCO+UNDQHWsDViJLqshxOahXyLSh3EA==} + '@rollup/rollup-darwin-x64@4.22.4': + resolution: {integrity: sha512-aJJyYKQwbHuhTUrjWjxEvGnNNBCnmpHDvrb8JFDbeSH3m2XdHcxDd3jthAzvmoI8w/kSjd2y0udT+4okADsZIw==} cpu: [x64] os: [darwin] - '@rollup/rollup-linux-arm-gnueabihf@4.21.3': - resolution: {integrity: sha512-btVgIsCjuYFKUjopPoWiDqmoUXQDiW2A4C3Mtmp5vACm7/GnyuprqIDPNczeyR5W8rTXEbkmrJux7cJmD99D2g==} + '@rollup/rollup-linux-arm-gnueabihf@4.22.4': + resolution: {integrity: sha512-j63YtCIRAzbO+gC2L9dWXRh5BFetsv0j0va0Wi9epXDgU/XUi5dJKo4USTttVyK7fGw2nPWK0PbAvyliz50SCQ==} cpu: [arm] os: [linux] - '@rollup/rollup-linux-arm-musleabihf@4.21.3': - resolution: {integrity: sha512-zmjbSphplZlau6ZTkxd3+NMtE4UKVy7U4aVFMmHcgO5CUbw17ZP6QCgyxhzGaU/wFFdTfiojjbLG3/0p9HhAqA==} + '@rollup/rollup-linux-arm-musleabihf@4.22.4': + resolution: {integrity: sha512-dJnWUgwWBX1YBRsuKKMOlXCzh2Wu1mlHzv20TpqEsfdZLb3WoJW2kIEsGwLkroYf24IrPAvOT/ZQ2OYMV6vlrg==} cpu: [arm] os: [linux] - '@rollup/rollup-linux-arm64-gnu@4.21.3': - resolution: {integrity: sha512-nSZfcZtAnQPRZmUkUQwZq2OjQciR6tEoJaZVFvLHsj0MF6QhNMg0fQ6mUOsiCUpTqxTx0/O6gX0V/nYc7LrgPw==} + '@rollup/rollup-linux-arm64-gnu@4.22.4': + resolution: {integrity: sha512-AdPRoNi3NKVLolCN/Sp4F4N1d98c4SBnHMKoLuiG6RXgoZ4sllseuGioszumnPGmPM2O7qaAX/IJdeDU8f26Aw==} cpu: [arm64] os: [linux] - '@rollup/rollup-linux-arm64-musl@4.21.3': - resolution: {integrity: sha512-MnvSPGO8KJXIMGlQDYfvYS3IosFN2rKsvxRpPO2l2cum+Z3exiExLwVU+GExL96pn8IP+GdH8Tz70EpBhO0sIQ==} + '@rollup/rollup-linux-arm64-musl@4.22.4': + resolution: {integrity: sha512-Gl0AxBtDg8uoAn5CCqQDMqAx22Wx22pjDOjBdmG0VIWX3qUBHzYmOKh8KXHL4UpogfJ14G4wk16EQogF+v8hmA==} cpu: [arm64] os: [linux] - '@rollup/rollup-linux-powerpc64le-gnu@4.21.3': - resolution: {integrity: sha512-+W+p/9QNDr2vE2AXU0qIy0qQE75E8RTwTwgqS2G5CRQ11vzq0tbnfBd6brWhS9bCRjAjepJe2fvvkvS3dno+iw==} + '@rollup/rollup-linux-powerpc64le-gnu@4.22.4': + resolution: {integrity: sha512-3aVCK9xfWW1oGQpTsYJJPF6bfpWfhbRnhdlyhak2ZiyFLDaayz0EP5j9V1RVLAAxlmWKTDfS9wyRyY3hvhPoOg==} cpu: [ppc64] os: [linux] - '@rollup/rollup-linux-riscv64-gnu@4.21.3': - resolution: {integrity: sha512-yXH6K6KfqGXaxHrtr+Uoy+JpNlUlI46BKVyonGiaD74ravdnF9BUNC+vV+SIuB96hUMGShhKV693rF9QDfO6nQ==} + '@rollup/rollup-linux-riscv64-gnu@4.22.4': + resolution: {integrity: sha512-ePYIir6VYnhgv2C5Xe9u+ico4t8sZWXschR6fMgoPUK31yQu7hTEJb7bCqivHECwIClJfKgE7zYsh1qTP3WHUA==} cpu: [riscv64] os: [linux] - '@rollup/rollup-linux-s390x-gnu@4.21.3': - resolution: {integrity: sha512-R8cwY9wcnApN/KDYWTH4gV/ypvy9yZUHlbJvfaiXSB48JO3KpwSpjOGqO4jnGkLDSk1hgjYkTbTt6Q7uvPf8eg==} + '@rollup/rollup-linux-s390x-gnu@4.22.4': + resolution: {integrity: sha512-GqFJ9wLlbB9daxhVlrTe61vJtEY99/xB3C8e4ULVsVfflcpmR6c8UZXjtkMA6FhNONhj2eA5Tk9uAVw5orEs4Q==} cpu: [s390x] os: [linux] - '@rollup/rollup-linux-x64-gnu@4.21.3': - resolution: {integrity: sha512-kZPbX/NOPh0vhS5sI+dR8L1bU2cSO9FgxwM8r7wHzGydzfSjLRCFAT87GR5U9scj2rhzN3JPYVC7NoBbl4FZ0g==} + '@rollup/rollup-linux-x64-gnu@4.22.4': + resolution: {integrity: sha512-87v0ol2sH9GE3cLQLNEy0K/R0pz1nvg76o8M5nhMR0+Q+BBGLnb35P0fVz4CQxHYXaAOhE8HhlkaZfsdUOlHwg==} cpu: [x64] os: [linux] - '@rollup/rollup-linux-x64-musl@4.21.3': - resolution: {integrity: sha512-S0Yq+xA1VEH66uiMNhijsWAafffydd2X5b77eLHfRmfLsRSpbiAWiRHV6DEpz6aOToPsgid7TI9rGd6zB1rhbg==} + '@rollup/rollup-linux-x64-musl@4.22.4': + resolution: {integrity: sha512-UV6FZMUgePDZrFjrNGIWzDo/vABebuXBhJEqrHxrGiU6HikPy0Z3LfdtciIttEUQfuDdCn8fqh7wiFJjCNwO+g==} cpu: [x64] os: [linux] - '@rollup/rollup-win32-arm64-msvc@4.21.3': - resolution: {integrity: sha512-9isNzeL34yquCPyerog+IMCNxKR8XYmGd0tHSV+OVx0TmE0aJOo9uw4fZfUuk2qxobP5sug6vNdZR6u7Mw7Q+Q==} + '@rollup/rollup-win32-arm64-msvc@4.22.4': + resolution: {integrity: sha512-BjI+NVVEGAXjGWYHz/vv0pBqfGoUH0IGZ0cICTn7kB9PyjrATSkX+8WkguNjWoj2qSr1im/+tTGRaY+4/PdcQw==} cpu: [arm64] os: [win32] - '@rollup/rollup-win32-ia32-msvc@4.21.3': - resolution: {integrity: sha512-nMIdKnfZfzn1Vsk+RuOvl43ONTZXoAPUUxgcU0tXooqg4YrAqzfKzVenqqk2g5efWh46/D28cKFrOzDSW28gTA==} + '@rollup/rollup-win32-ia32-msvc@4.22.4': + resolution: {integrity: sha512-SiWG/1TuUdPvYmzmYnmd3IEifzR61Tragkbx9D3+R8mzQqDBz8v+BvZNDlkiTtI9T15KYZhP0ehn3Dld4n9J5g==} cpu: [ia32] os: [win32] - '@rollup/rollup-win32-x64-msvc@4.21.3': - resolution: {integrity: sha512-fOvu7PCQjAj4eWDEuD8Xz5gpzFqXzGlxHZozHP4b9Jxv9APtdxL6STqztDzMLuRXEc4UpXGGhx029Xgm91QBeA==} + '@rollup/rollup-win32-x64-msvc@4.22.4': + resolution: {integrity: sha512-j8pPKp53/lq9lMXN57S8cFz0MynJk8OWNuUnXct/9KCpKU7DgU3bYMJhwWmcqC0UU29p8Lr0/7KEVcaM6bf47Q==} cpu: [x64] os: [win32] @@ -735,8 +735,8 @@ packages: deprecated: Rimraf versions prior to v4 are no longer supported hasBin: true - rollup@4.21.3: - resolution: {integrity: sha512-7sqRtBNnEbcBtMeRVc6VRsJMmpI+JU1z9VTvW8D4gXIYQFz0aLcsE6rRkyghZkLfEgUZgVvOG7A5CVz/VW5GIA==} + rollup@4.22.4: + resolution: {integrity: sha512-vD8HJ5raRcWOyymsR6Z3o6+RzfEPCnVLMFJ6vRslO1jt4LO6dUo5Qnpg7y4RkZFM2DMe3WUirkI5c16onjrc6A==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} hasBin: true @@ -808,8 +808,8 @@ packages: uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} - vite@5.4.6: - resolution: {integrity: sha512-IeL5f8OO5nylsgzd9tq4qD2QqI0k2CQLGrWD0rCN0EQJZpBK5vJAx0I+GDkMOXxQX/OfFHMuLIx6ddAxGX/k+Q==} + vite@5.4.7: + resolution: {integrity: sha512-5l2zxqMEPVENgvzTuBpHer2awaetimj2BGkhBPdnwKbPNOlHsODU+oiazEZzLK7KhAnOrO+XGYJYn4ZlUhDtDQ==} engines: {node: ^18.0.0 || >=20.0.0} hasBin: true peerDependencies: @@ -985,52 +985,52 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.17.1 - '@rollup/rollup-android-arm-eabi@4.21.3': + '@rollup/rollup-android-arm-eabi@4.22.4': optional: true - '@rollup/rollup-android-arm64@4.21.3': + '@rollup/rollup-android-arm64@4.22.4': optional: true - '@rollup/rollup-darwin-arm64@4.21.3': + '@rollup/rollup-darwin-arm64@4.22.4': optional: true - '@rollup/rollup-darwin-x64@4.21.3': + '@rollup/rollup-darwin-x64@4.22.4': optional: true - '@rollup/rollup-linux-arm-gnueabihf@4.21.3': + '@rollup/rollup-linux-arm-gnueabihf@4.22.4': optional: true - '@rollup/rollup-linux-arm-musleabihf@4.21.3': + '@rollup/rollup-linux-arm-musleabihf@4.22.4': optional: true - '@rollup/rollup-linux-arm64-gnu@4.21.3': + '@rollup/rollup-linux-arm64-gnu@4.22.4': optional: true - '@rollup/rollup-linux-arm64-musl@4.21.3': + '@rollup/rollup-linux-arm64-musl@4.22.4': optional: true - '@rollup/rollup-linux-powerpc64le-gnu@4.21.3': + '@rollup/rollup-linux-powerpc64le-gnu@4.22.4': optional: true - '@rollup/rollup-linux-riscv64-gnu@4.21.3': + '@rollup/rollup-linux-riscv64-gnu@4.22.4': optional: true - '@rollup/rollup-linux-s390x-gnu@4.21.3': + '@rollup/rollup-linux-s390x-gnu@4.22.4': optional: true - '@rollup/rollup-linux-x64-gnu@4.21.3': + '@rollup/rollup-linux-x64-gnu@4.22.4': optional: true - '@rollup/rollup-linux-x64-musl@4.21.3': + '@rollup/rollup-linux-x64-musl@4.22.4': optional: true - '@rollup/rollup-win32-arm64-msvc@4.21.3': + '@rollup/rollup-win32-arm64-msvc@4.22.4': optional: true - '@rollup/rollup-win32-ia32-msvc@4.21.3': + '@rollup/rollup-win32-ia32-msvc@4.22.4': optional: true - '@rollup/rollup-win32-x64-msvc@4.21.3': + '@rollup/rollup-win32-x64-msvc@4.22.4': optional: true '@types/estree@1.0.5': {} @@ -1502,26 +1502,26 @@ snapshots: dependencies: glob: 7.2.3 - rollup@4.21.3: + rollup@4.22.4: dependencies: '@types/estree': 1.0.5 optionalDependencies: - '@rollup/rollup-android-arm-eabi': 4.21.3 - '@rollup/rollup-android-arm64': 4.21.3 - '@rollup/rollup-darwin-arm64': 4.21.3 - '@rollup/rollup-darwin-x64': 4.21.3 - '@rollup/rollup-linux-arm-gnueabihf': 4.21.3 - '@rollup/rollup-linux-arm-musleabihf': 4.21.3 - '@rollup/rollup-linux-arm64-gnu': 4.21.3 - '@rollup/rollup-linux-arm64-musl': 4.21.3 - '@rollup/rollup-linux-powerpc64le-gnu': 4.21.3 - '@rollup/rollup-linux-riscv64-gnu': 4.21.3 - '@rollup/rollup-linux-s390x-gnu': 4.21.3 - '@rollup/rollup-linux-x64-gnu': 4.21.3 - '@rollup/rollup-linux-x64-musl': 4.21.3 - '@rollup/rollup-win32-arm64-msvc': 4.21.3 - '@rollup/rollup-win32-ia32-msvc': 4.21.3 - '@rollup/rollup-win32-x64-msvc': 4.21.3 + '@rollup/rollup-android-arm-eabi': 4.22.4 + '@rollup/rollup-android-arm64': 4.22.4 + '@rollup/rollup-darwin-arm64': 4.22.4 + '@rollup/rollup-darwin-x64': 4.22.4 + '@rollup/rollup-linux-arm-gnueabihf': 4.22.4 + '@rollup/rollup-linux-arm-musleabihf': 4.22.4 + '@rollup/rollup-linux-arm64-gnu': 4.22.4 + '@rollup/rollup-linux-arm64-musl': 4.22.4 + '@rollup/rollup-linux-powerpc64le-gnu': 4.22.4 + '@rollup/rollup-linux-riscv64-gnu': 4.22.4 + '@rollup/rollup-linux-s390x-gnu': 4.22.4 + '@rollup/rollup-linux-x64-gnu': 4.22.4 + '@rollup/rollup-linux-x64-musl': 4.22.4 + '@rollup/rollup-win32-arm64-msvc': 4.22.4 + '@rollup/rollup-win32-ia32-msvc': 4.22.4 + '@rollup/rollup-win32-x64-msvc': 4.22.4 fsevents: 2.3.3 run-parallel@1.2.0: @@ -1574,11 +1574,11 @@ snapshots: dependencies: punycode: 2.3.1 - vite@5.4.6(@types/node@20.16.5): + vite@5.4.7(@types/node@20.16.5): dependencies: esbuild: 0.21.5 postcss: 8.4.47 - rollup: 4.21.3 + rollup: 4.22.4 optionalDependencies: '@types/node': 20.16.5 fsevents: 2.3.3