@daiso-tech/core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.changeset/sweet-peas-beg.md +5 -0
- package/.eslintignore +3 -0
- package/.eslintrc.json +50 -0
- package/.gitattributes +6 -0
- package/.github/workflows/main.yaml +54 -0
- package/.github/workflows/release.yaml +31 -0
- package/.prettierignore +4 -0
- package/.prettierrc.json +4 -0
- package/.vscode/settings.json +46 -0
- package/LICENSE.md +194 -0
- package/docs-api/.nojekyll +1 -0
- package/docs-api/assets/highlight.css +92 -0
- package/docs-api/assets/icons.js +18 -0
- package/docs-api/assets/icons.svg +1 -0
- package/docs-api/assets/main.js +60 -0
- package/docs-api/assets/navigation.js +1 -0
- package/docs-api/assets/search.js +1 -0
- package/docs-api/assets/style.css +1448 -0
- package/docs-api/classes/AsyncIterableCollection.html +437 -0
- package/docs-api/classes/CollectionError.html +12 -0
- package/docs-api/classes/IndexOverflowError.html +12 -0
- package/docs-api/classes/ItemNotFoundError.html +12 -0
- package/docs-api/classes/IterableCollection.html +434 -0
- package/docs-api/classes/ListCollection.html +434 -0
- package/docs-api/classes/MultipleItemsFoundError.html +12 -0
- package/docs-api/classes/UnexpectedCollectionError.html +12 -0
- package/docs-api/functions/isAsyncIterable.html +1 -0
- package/docs-api/functions/isIterable.html +1 -0
- package/docs-api/functions/range.html +4 -0
- package/docs-api/hierarchy.html +1 -0
- package/docs-api/index.html +1 -0
- package/docs-api/modules.html +60 -0
- package/docs-api/types/AsyncCollapse.html +1 -0
- package/docs-api/types/AsyncFilter.html +1 -0
- package/docs-api/types/AsyncFilter_.html +1 -0
- package/docs-api/types/AsyncFindOrSettings.html +1 -0
- package/docs-api/types/AsyncFindSettings.html +1 -0
- package/docs-api/types/AsyncForEach.html +1 -0
- package/docs-api/types/AsyncForEach_.html +1 -0
- package/docs-api/types/AsyncGroupBySettings.html +1 -0
- package/docs-api/types/AsyncIterableValue.html +1 -0
- package/docs-api/types/AsyncLazyable.html +1 -0
- package/docs-api/types/AsyncLazyable_.html +1 -0
- package/docs-api/types/AsyncMap.html +1 -0
- package/docs-api/types/AsyncMap_.html +1 -0
- package/docs-api/types/AsyncModifier.html +1 -0
- package/docs-api/types/AsyncModifier_.html +1 -0
- package/docs-api/types/AsyncReduce.html +1 -0
- package/docs-api/types/AsyncReduceSettings.html +1 -0
- package/docs-api/types/AsyncReduce_.html +1 -0
- package/docs-api/types/AsyncTap.html +1 -0
- package/docs-api/types/AsyncTap_.html +1 -0
- package/docs-api/types/AsyncTransform.html +1 -0
- package/docs-api/types/AsyncTransform_.html +1 -0
- package/docs-api/types/Collapse.html +1 -0
- package/docs-api/types/Comparator.html +1 -0
- package/docs-api/types/EnsureType.html +1 -0
- package/docs-api/types/Filter.html +1 -0
- package/docs-api/types/FilterGuard.html +1 -0
- package/docs-api/types/Filter_.html +1 -0
- package/docs-api/types/FindOrSettings.html +1 -0
- package/docs-api/types/FindSettings.html +1 -0
- package/docs-api/types/ForEach.html +1 -0
- package/docs-api/types/GroupBySettings.html +1 -0
- package/docs-api/types/IAsyncCollection.html +357 -0
- package/docs-api/types/ICollection.html +357 -0
- package/docs-api/types/JoinSettings.html +1 -0
- package/docs-api/types/Lazyable.html +1 -0
- package/docs-api/types/Map.html +1 -0
- package/docs-api/types/Modifier.html +1 -0
- package/docs-api/types/PageSettings.html +1 -0
- package/docs-api/types/RecordItem.html +1 -0
- package/docs-api/types/Reduce.html +1 -0
- package/docs-api/types/ReduceSettings.html +1 -0
- package/docs-api/types/ReverseSettings.html +1 -0
- package/docs-api/types/SliceSettings.html +1 -0
- package/docs-api/types/SlidingSettings.html +1 -0
- package/docs-api/types/Tap.html +1 -0
- package/docs-api/types/Transform.html +1 -0
- package/docs-api/types/UpdatedItem.html +1 -0
- package/package.json +47 -0
- package/src/_module.ts +2 -0
- package/src/collection/_module.ts +4 -0
- package/src/collection/_shared.ts +45 -0
- package/src/collection/async-iterable-collection/_module.ts +1 -0
- package/src/collection/async-iterable-collection/async-iterable-collection.test.ts +3195 -0
- package/src/collection/async-iterable-collection/async-iterable-collection.ts +1276 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/_module.ts +35 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-abort-iterable.ts +25 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-chunk-iterable.ts +57 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-chunk-whilte-iterable.ts +54 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-collapse-iterable.ts +40 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-count-by-iterable.ts +58 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-cross-join-iterable.ts +69 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-delay-iterable.ts +19 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-entries-iterable.ts +28 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-filter-iterable.ts +42 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-flat-map-iterable.ts +44 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-group-by-iterable.ts +48 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-insert-after-iterable.ts +57 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-insert-before-iterable.ts +57 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-map-iterable.ts +40 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-merge-iterable.ts +35 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-pad-end-iterable.ts +41 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-pad-start-iterable.ts +41 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-partion-iterable.ts +63 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-repeat-iterable.ts +40 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-reverse-iterable.ts +35 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-shuffle-iterable.ts +23 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-skip-iterable.ts +41 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-skip-until-iterable.ts +55 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-slice-iterable.ts +33 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-sliding-iterable.ts +54 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-sort-iterable.ts +18 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-split-iterable.ts +64 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-take-iterable.ts +41 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-take-until-iterable.ts +41 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-tap-iterable.ts +34 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-timeout-iterable.ts +20 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-unique-iterable.ts +49 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-update-iterable.ts +64 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-when-iterable.ts +43 -0
- package/src/collection/async-iterable-collection/async-iterable-helpers/async-zip-iterable.ts +45 -0
- package/src/collection/iterable-collection/_module.ts +1 -0
- package/src/collection/iterable-collection/iterable-collection.test.ts +2379 -0
- package/src/collection/iterable-collection/iterable-collection.ts +1317 -0
- package/src/collection/iterable-collection/iterable-helpers/_module.ts +32 -0
- package/src/collection/iterable-collection/iterable-helpers/chunk-iterable.ts +49 -0
- package/src/collection/iterable-collection/iterable-helpers/chunk-whilte-iterable.ts +51 -0
- package/src/collection/iterable-collection/iterable-helpers/collapse-iterable.ts +35 -0
- package/src/collection/iterable-collection/iterable-helpers/count-by-iterable.ts +49 -0
- package/src/collection/iterable-collection/iterable-helpers/cross-join-iterable.ts +57 -0
- package/src/collection/iterable-collection/iterable-helpers/entries-iterable.ts +42 -0
- package/src/collection/iterable-collection/iterable-helpers/filter-iterable.ts +39 -0
- package/src/collection/iterable-collection/iterable-helpers/flat-map-iterable.ts +35 -0
- package/src/collection/iterable-collection/iterable-helpers/group-by-iterable.ts +52 -0
- package/src/collection/iterable-collection/iterable-helpers/insert-after-iterable.ts +43 -0
- package/src/collection/iterable-collection/iterable-helpers/insert-before-iterable.ts +43 -0
- package/src/collection/iterable-collection/iterable-helpers/map-iterable.ts +35 -0
- package/src/collection/iterable-collection/iterable-helpers/merge-iterable.ts +31 -0
- package/src/collection/iterable-collection/iterable-helpers/pad-end-iterable.ts +52 -0
- package/src/collection/iterable-collection/iterable-helpers/pad-start-iterable.ts +52 -0
- package/src/collection/iterable-collection/iterable-helpers/partion-iterable.ts +46 -0
- package/src/collection/iterable-collection/iterable-helpers/repeat-iterable.ts +36 -0
- package/src/collection/iterable-collection/iterable-helpers/reverse-iterable.ts +46 -0
- package/src/collection/iterable-collection/iterable-helpers/shuffle-iterable.ts +36 -0
- package/src/collection/iterable-collection/iterable-helpers/skip-iterable.ts +37 -0
- package/src/collection/iterable-collection/iterable-helpers/skip-until-iterable.ts +41 -0
- package/src/collection/iterable-collection/iterable-helpers/slice-iterable.ts +47 -0
- package/src/collection/iterable-collection/iterable-helpers/sliding-iterable.ts +49 -0
- package/src/collection/iterable-collection/iterable-helpers/sort-iterable.ts +29 -0
- package/src/collection/iterable-collection/iterable-helpers/split-iterable.ts +58 -0
- package/src/collection/iterable-collection/iterable-helpers/take-iterable.ts +37 -0
- package/src/collection/iterable-collection/iterable-helpers/take-until-iterable.ts +38 -0
- package/src/collection/iterable-collection/iterable-helpers/tap-iterable.ts +31 -0
- package/src/collection/iterable-collection/iterable-helpers/unique-iterable.ts +43 -0
- package/src/collection/iterable-collection/iterable-helpers/update-iterable.ts +50 -0
- package/src/collection/iterable-collection/iterable-helpers/when-iterable.ts +37 -0
- package/src/collection/iterable-collection/iterable-helpers/zip-iterable.ts +41 -0
- package/src/collection/list-collection/_module.ts +1 -0
- package/src/collection/list-collection/list-collection.test.ts +2280 -0
- package/src/collection/list-collection/list-collection.ts +1883 -0
- package/src/contracts/_module.ts +1 -0
- package/src/contracts/collection/_module.ts +3 -0
- package/src/contracts/collection/_shared.ts +346 -0
- package/src/contracts/collection/async-collection.contract.ts +1028 -0
- package/src/contracts/collection/collection.contract.ts +978 -0
- package/src/types.ts +2 -0
- package/tsconfig.base.json +31 -0
- package/tsconfig.cjs.json +12 -0
- package/tsconfig.esm.json +12 -0
- package/tsconfig.json +10 -0
- package/tsconfig.types.json +12 -0
- package/vite.config.ts +6 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export * from "@/collection/iterable-collection/iterable-helpers/chunk-iterable";
|
|
2
|
+
export * from "@/collection/iterable-collection/iterable-helpers/chunk-whilte-iterable";
|
|
3
|
+
export * from "@/collection/iterable-collection/iterable-helpers/collapse-iterable";
|
|
4
|
+
export * from "@/collection/iterable-collection/iterable-helpers/count-by-iterable";
|
|
5
|
+
export * from "@/collection/iterable-collection/iterable-helpers/cross-join-iterable";
|
|
6
|
+
export * from "@/collection/iterable-collection/iterable-helpers/entries-iterable";
|
|
7
|
+
export * from "@/collection/iterable-collection/iterable-helpers/filter-iterable";
|
|
8
|
+
export * from "@/collection/iterable-collection/iterable-helpers/flat-map-iterable";
|
|
9
|
+
export * from "@/collection/iterable-collection/iterable-helpers/group-by-iterable";
|
|
10
|
+
export * from "@/collection/iterable-collection/iterable-helpers/insert-after-iterable";
|
|
11
|
+
export * from "@/collection/iterable-collection/iterable-helpers/insert-before-iterable";
|
|
12
|
+
export * from "@/collection/iterable-collection/iterable-helpers/map-iterable";
|
|
13
|
+
export * from "@/collection/iterable-collection/iterable-helpers/merge-iterable";
|
|
14
|
+
export * from "@/collection/iterable-collection/iterable-helpers/pad-end-iterable";
|
|
15
|
+
export * from "@/collection/iterable-collection/iterable-helpers/pad-start-iterable";
|
|
16
|
+
export * from "@/collection/iterable-collection/iterable-helpers/partion-iterable";
|
|
17
|
+
export * from "@/collection/iterable-collection/iterable-helpers/repeat-iterable";
|
|
18
|
+
export * from "@/collection/iterable-collection/iterable-helpers/reverse-iterable";
|
|
19
|
+
export * from "@/collection/iterable-collection/iterable-helpers/shuffle-iterable";
|
|
20
|
+
export * from "@/collection/iterable-collection/iterable-helpers/skip-iterable";
|
|
21
|
+
export * from "@/collection/iterable-collection/iterable-helpers/skip-until-iterable";
|
|
22
|
+
export * from "@/collection/iterable-collection/iterable-helpers/slice-iterable";
|
|
23
|
+
export * from "@/collection/iterable-collection/iterable-helpers/sliding-iterable";
|
|
24
|
+
export * from "@/collection/iterable-collection/iterable-helpers/sort-iterable";
|
|
25
|
+
export * from "@/collection/iterable-collection/iterable-helpers/split-iterable";
|
|
26
|
+
export * from "@/collection/iterable-collection/iterable-helpers/take-iterable";
|
|
27
|
+
export * from "@/collection/iterable-collection/iterable-helpers/take-until-iterable";
|
|
28
|
+
export * from "@/collection/iterable-collection/iterable-helpers/tap-iterable";
|
|
29
|
+
export * from "@/collection/iterable-collection/iterable-helpers/unique-iterable";
|
|
30
|
+
export * from "@/collection/iterable-collection/iterable-helpers/update-iterable";
|
|
31
|
+
export * from "@/collection/iterable-collection/iterable-helpers/when-iterable";
|
|
32
|
+
export * from "@/collection/iterable-collection/iterable-helpers/zip-iterable";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CollectionError,
|
|
3
|
+
type ICollection,
|
|
4
|
+
UnexpectedCollectionError,
|
|
5
|
+
} from "@/contracts/collection/_module";
|
|
6
|
+
|
|
7
|
+
export class ChunkIterable<TInput> implements Iterable<ICollection<TInput>> {
|
|
8
|
+
constructor(
|
|
9
|
+
private collection: ICollection<TInput>,
|
|
10
|
+
private chunkSize: number,
|
|
11
|
+
private readonly makeCollection: <TInput>(
|
|
12
|
+
iterable: Iterable<TInput>,
|
|
13
|
+
) => ICollection<TInput>,
|
|
14
|
+
) {}
|
|
15
|
+
|
|
16
|
+
*[Symbol.iterator](): Iterator<ICollection<TInput>> {
|
|
17
|
+
try {
|
|
18
|
+
let chunk: ICollection<TInput> = this.makeCollection<TInput>([]),
|
|
19
|
+
currentChunkSize = 0,
|
|
20
|
+
isFirstIteration = true;
|
|
21
|
+
for (const item of this.collection) {
|
|
22
|
+
currentChunkSize %= this.chunkSize;
|
|
23
|
+
const isFilled = currentChunkSize === 0;
|
|
24
|
+
if (!isFirstIteration && isFilled) {
|
|
25
|
+
yield chunk;
|
|
26
|
+
chunk = this.makeCollection<TInput>([]);
|
|
27
|
+
}
|
|
28
|
+
chunk = chunk.append([item]);
|
|
29
|
+
currentChunkSize++;
|
|
30
|
+
isFirstIteration = false;
|
|
31
|
+
}
|
|
32
|
+
const hasRest = currentChunkSize !== 0;
|
|
33
|
+
if (hasRest) {
|
|
34
|
+
yield chunk;
|
|
35
|
+
}
|
|
36
|
+
} catch (error: unknown) {
|
|
37
|
+
if (
|
|
38
|
+
error instanceof CollectionError ||
|
|
39
|
+
error instanceof TypeError
|
|
40
|
+
) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
throw new UnexpectedCollectionError(
|
|
44
|
+
`Unexpected error "${String(error)}" occured`,
|
|
45
|
+
error,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CollectionError,
|
|
3
|
+
type Filter,
|
|
4
|
+
type ICollection,
|
|
5
|
+
UnexpectedCollectionError,
|
|
6
|
+
} from "@/contracts/collection/_module";
|
|
7
|
+
|
|
8
|
+
export class ChunkWhileIterable<TInput>
|
|
9
|
+
implements Iterable<ICollection<TInput>>
|
|
10
|
+
{
|
|
11
|
+
constructor(
|
|
12
|
+
private collection: ICollection<TInput>,
|
|
13
|
+
private filter: Filter<TInput, ICollection<TInput>>,
|
|
14
|
+
private throwOnNumberLimit: boolean,
|
|
15
|
+
private makeCollection: <TInput>(
|
|
16
|
+
iterable: Iterable<TInput>,
|
|
17
|
+
) => ICollection<TInput>,
|
|
18
|
+
) {}
|
|
19
|
+
|
|
20
|
+
*[Symbol.iterator](): Iterator<ICollection<TInput>> {
|
|
21
|
+
try {
|
|
22
|
+
let collection: ICollection<TInput> = this.makeCollection<TInput>(
|
|
23
|
+
[],
|
|
24
|
+
);
|
|
25
|
+
for (const [index, item] of this.collection.entries(
|
|
26
|
+
this.throwOnNumberLimit,
|
|
27
|
+
)) {
|
|
28
|
+
if (index === 0) {
|
|
29
|
+
collection = collection.append([item]);
|
|
30
|
+
} else if (this.filter(item, index, collection)) {
|
|
31
|
+
collection = collection.append([item]);
|
|
32
|
+
} else {
|
|
33
|
+
yield collection;
|
|
34
|
+
collection = this.makeCollection<TInput>([item]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
yield collection;
|
|
38
|
+
} catch (error: unknown) {
|
|
39
|
+
if (
|
|
40
|
+
error instanceof CollectionError ||
|
|
41
|
+
error instanceof TypeError
|
|
42
|
+
) {
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
throw new UnexpectedCollectionError(
|
|
46
|
+
`Unexpected error "${String(error)}" occured`,
|
|
47
|
+
error,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isIterable } from "@/collection/_shared";
|
|
2
|
+
import {
|
|
3
|
+
type Collapse,
|
|
4
|
+
CollectionError,
|
|
5
|
+
type ICollection,
|
|
6
|
+
UnexpectedCollectionError,
|
|
7
|
+
} from "@/contracts/collection/_module";
|
|
8
|
+
|
|
9
|
+
export class CollapseIterable<TInput> implements Iterable<Collapse<TInput>> {
|
|
10
|
+
constructor(private collection: ICollection<TInput>) {}
|
|
11
|
+
|
|
12
|
+
*[Symbol.iterator](): Iterator<Collapse<TInput>> {
|
|
13
|
+
try {
|
|
14
|
+
for (const item of this.collection) {
|
|
15
|
+
if (isIterable<TInput>(item)) {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
yield* item as any;
|
|
18
|
+
} else {
|
|
19
|
+
yield item as Collapse<TInput>;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
} catch (error: unknown) {
|
|
23
|
+
if (
|
|
24
|
+
error instanceof CollectionError ||
|
|
25
|
+
error instanceof TypeError
|
|
26
|
+
) {
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
throw new UnexpectedCollectionError(
|
|
30
|
+
`Unexpected error "${String(error)}" occured`,
|
|
31
|
+
error,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CollectionError,
|
|
3
|
+
type ICollection,
|
|
4
|
+
type Map,
|
|
5
|
+
type RecordItem,
|
|
6
|
+
UnexpectedCollectionError,
|
|
7
|
+
} from "@/contracts/collection/_module";
|
|
8
|
+
|
|
9
|
+
export class CountByIterable<TInput, TOutput = TInput>
|
|
10
|
+
implements Iterable<RecordItem<TOutput, number>>
|
|
11
|
+
{
|
|
12
|
+
constructor(
|
|
13
|
+
private collection: ICollection<TInput>,
|
|
14
|
+
private callback: Map<TInput, ICollection<TInput>, TOutput> = (item) =>
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return
|
|
16
|
+
item as any,
|
|
17
|
+
private throwOnNumberLimit: boolean,
|
|
18
|
+
) {}
|
|
19
|
+
|
|
20
|
+
*[Symbol.iterator](): Iterator<RecordItem<TOutput, number>> {
|
|
21
|
+
try {
|
|
22
|
+
const map = new Map<TOutput, number>();
|
|
23
|
+
for (const [index, item] of this.collection.entries(
|
|
24
|
+
this.throwOnNumberLimit,
|
|
25
|
+
)) {
|
|
26
|
+
const key = this.callback(item, index, this.collection);
|
|
27
|
+
if (!map.has(key)) {
|
|
28
|
+
map.set(key, 0);
|
|
29
|
+
}
|
|
30
|
+
const counter = map.get(key);
|
|
31
|
+
if (counter !== undefined) {
|
|
32
|
+
map.set(key, counter + 1);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
yield* map;
|
|
36
|
+
} catch (error: unknown) {
|
|
37
|
+
if (
|
|
38
|
+
error instanceof CollectionError ||
|
|
39
|
+
error instanceof TypeError
|
|
40
|
+
) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
throw new UnexpectedCollectionError(
|
|
44
|
+
`Unexpected error "${String(error)}" occured`,
|
|
45
|
+
error,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CollectionError,
|
|
3
|
+
type ICollection,
|
|
4
|
+
UnexpectedCollectionError,
|
|
5
|
+
} from "@/contracts/collection/_module";
|
|
6
|
+
|
|
7
|
+
export class CrossJoinIterable<TInput, TExtended = TInput>
|
|
8
|
+
implements Iterable<ICollection<TInput | TExtended>>
|
|
9
|
+
{
|
|
10
|
+
constructor(
|
|
11
|
+
private collection: ICollection<TInput>,
|
|
12
|
+
private iterables: Array<Iterable<TExtended>>,
|
|
13
|
+
private makeCollection: <TInput>(
|
|
14
|
+
iterable: Iterable<TInput>,
|
|
15
|
+
) => ICollection<TInput>,
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
*[Symbol.iterator](): Iterator<ICollection<TInput | TExtended>> {
|
|
19
|
+
try {
|
|
20
|
+
yield* this.makeCollection<ICollection<TInput | TExtended>>([
|
|
21
|
+
this.collection,
|
|
22
|
+
...this.iterables.map<ICollection<TExtended>>((iterable) =>
|
|
23
|
+
this.makeCollection(iterable),
|
|
24
|
+
),
|
|
25
|
+
]).reduce<ICollection<ICollection<TInput | TExtended>>>({
|
|
26
|
+
reduceFn: (a, b) => {
|
|
27
|
+
return a
|
|
28
|
+
.map((x) =>
|
|
29
|
+
b.map((y) => {
|
|
30
|
+
return x.append([y]);
|
|
31
|
+
}),
|
|
32
|
+
)
|
|
33
|
+
.reduce<ICollection<ICollection<TInput | TExtended>>>({
|
|
34
|
+
reduceFn: (c, b) => c.append(b),
|
|
35
|
+
initialValue: this.makeCollection<
|
|
36
|
+
ICollection<TInput | TExtended>
|
|
37
|
+
>([]),
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
initialValue: this.makeCollection<
|
|
41
|
+
ICollection<TInput | TExtended>
|
|
42
|
+
>([this.makeCollection<TInput | TExtended>([])]),
|
|
43
|
+
});
|
|
44
|
+
} catch (error: unknown) {
|
|
45
|
+
if (
|
|
46
|
+
error instanceof CollectionError ||
|
|
47
|
+
error instanceof TypeError
|
|
48
|
+
) {
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
throw new UnexpectedCollectionError(
|
|
52
|
+
`Unexpected error "${String(error)}" occured`,
|
|
53
|
+
error,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type RecordItem,
|
|
3
|
+
CollectionError,
|
|
4
|
+
IndexOverflowError,
|
|
5
|
+
UnexpectedCollectionError,
|
|
6
|
+
} from "@/contracts/collection/_shared";
|
|
7
|
+
|
|
8
|
+
export class EntriesIterable<TInput>
|
|
9
|
+
implements Iterable<RecordItem<number, TInput>>
|
|
10
|
+
{
|
|
11
|
+
constructor(
|
|
12
|
+
private iterable: Iterable<TInput>,
|
|
13
|
+
private throwOnNumberLimit: boolean,
|
|
14
|
+
) {}
|
|
15
|
+
|
|
16
|
+
*[Symbol.iterator](): Iterator<RecordItem<number, TInput>> {
|
|
17
|
+
try {
|
|
18
|
+
let index = 0;
|
|
19
|
+
for (const item of this.iterable) {
|
|
20
|
+
if (
|
|
21
|
+
this.throwOnNumberLimit &&
|
|
22
|
+
index === Number.MAX_SAFE_INTEGER
|
|
23
|
+
) {
|
|
24
|
+
throw new IndexOverflowError("Index has overflowed");
|
|
25
|
+
}
|
|
26
|
+
yield [index, item];
|
|
27
|
+
index++;
|
|
28
|
+
}
|
|
29
|
+
} catch (error: unknown) {
|
|
30
|
+
if (
|
|
31
|
+
error instanceof CollectionError ||
|
|
32
|
+
error instanceof TypeError
|
|
33
|
+
) {
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
throw new UnexpectedCollectionError(
|
|
37
|
+
`Unexpected error "${String(error)}" occured`,
|
|
38
|
+
error,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CollectionError,
|
|
3
|
+
type Filter,
|
|
4
|
+
type ICollection,
|
|
5
|
+
UnexpectedCollectionError,
|
|
6
|
+
} from "@/contracts/collection/_module";
|
|
7
|
+
|
|
8
|
+
export class FilterIterable<TInput, TOutput extends TInput>
|
|
9
|
+
implements Iterable<TOutput>
|
|
10
|
+
{
|
|
11
|
+
constructor(
|
|
12
|
+
private collection: ICollection<TInput>,
|
|
13
|
+
private filter: Filter<TInput, ICollection<TInput>, TOutput>,
|
|
14
|
+
private throwOnNumberLimit: boolean,
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
*[Symbol.iterator](): Iterator<TOutput> {
|
|
18
|
+
try {
|
|
19
|
+
for (const [index, item] of this.collection.entries(
|
|
20
|
+
this.throwOnNumberLimit,
|
|
21
|
+
)) {
|
|
22
|
+
if (this.filter(item, index, this.collection)) {
|
|
23
|
+
yield item as TOutput;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} catch (error: unknown) {
|
|
27
|
+
if (
|
|
28
|
+
error instanceof CollectionError ||
|
|
29
|
+
error instanceof TypeError
|
|
30
|
+
) {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
throw new UnexpectedCollectionError(
|
|
34
|
+
`Unexpected error "${String(error)}" occured`,
|
|
35
|
+
error,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CollectionError,
|
|
3
|
+
type ICollection,
|
|
4
|
+
type Map,
|
|
5
|
+
UnexpectedCollectionError,
|
|
6
|
+
} from "@/contracts/collection/_module";
|
|
7
|
+
|
|
8
|
+
export class FlatMapIterable<TInput, TOutput> implements Iterable<TOutput> {
|
|
9
|
+
constructor(
|
|
10
|
+
private collection: ICollection<TInput>,
|
|
11
|
+
private map: Map<TInput, ICollection<TInput>, Iterable<TOutput>>,
|
|
12
|
+
private throwOnNumberLimit: boolean,
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
*[Symbol.iterator](): Iterator<TOutput> {
|
|
16
|
+
try {
|
|
17
|
+
for (const [index, item] of this.collection.entries(
|
|
18
|
+
this.throwOnNumberLimit,
|
|
19
|
+
)) {
|
|
20
|
+
yield* this.map(item, index, this.collection);
|
|
21
|
+
}
|
|
22
|
+
} catch (error: unknown) {
|
|
23
|
+
if (
|
|
24
|
+
error instanceof CollectionError ||
|
|
25
|
+
error instanceof TypeError
|
|
26
|
+
) {
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
throw new UnexpectedCollectionError(
|
|
30
|
+
`Unexpected error "${String(error)}" occured`,
|
|
31
|
+
error,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CollectionError,
|
|
3
|
+
UnexpectedCollectionError,
|
|
4
|
+
type ICollection,
|
|
5
|
+
type Map,
|
|
6
|
+
type RecordItem,
|
|
7
|
+
} from "@/contracts/collection/_module";
|
|
8
|
+
|
|
9
|
+
export class GroupByIterable<TInput, TOutput = TInput>
|
|
10
|
+
implements Iterable<RecordItem<TOutput, ICollection<TInput>>>
|
|
11
|
+
{
|
|
12
|
+
constructor(
|
|
13
|
+
private collection: ICollection<TInput>,
|
|
14
|
+
private callback: Map<TInput, ICollection<TInput>, TOutput> = (item) =>
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return
|
|
16
|
+
item as any,
|
|
17
|
+
private throwOnNumberLimit: boolean,
|
|
18
|
+
private makeCollection: <TInput>(
|
|
19
|
+
iterable: Iterable<TInput>,
|
|
20
|
+
) => ICollection<TInput>,
|
|
21
|
+
) {}
|
|
22
|
+
|
|
23
|
+
*[Symbol.iterator](): Iterator<RecordItem<TOutput, ICollection<TInput>>> {
|
|
24
|
+
try {
|
|
25
|
+
const map = new Map<TOutput, ICollection<TInput>>();
|
|
26
|
+
for (const [index, item] of this.collection.entries(
|
|
27
|
+
this.throwOnNumberLimit,
|
|
28
|
+
)) {
|
|
29
|
+
const key = this.callback(item, index, this.collection);
|
|
30
|
+
let collection: ICollection<TInput> | undefined = map.get(key);
|
|
31
|
+
if (collection === undefined) {
|
|
32
|
+
collection = this.makeCollection<TInput>([]);
|
|
33
|
+
map.set(key, collection);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
map.set(key, collection.append([item]));
|
|
37
|
+
}
|
|
38
|
+
yield* map;
|
|
39
|
+
} catch (error: unknown) {
|
|
40
|
+
if (
|
|
41
|
+
error instanceof CollectionError ||
|
|
42
|
+
error instanceof TypeError
|
|
43
|
+
) {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
throw new UnexpectedCollectionError(
|
|
47
|
+
`Unexpected error "${String(error)}" occured`,
|
|
48
|
+
error,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CollectionError,
|
|
3
|
+
type Filter,
|
|
4
|
+
type ICollection,
|
|
5
|
+
UnexpectedCollectionError,
|
|
6
|
+
} from "@/contracts/collection/_module";
|
|
7
|
+
|
|
8
|
+
export class InsertAfterIterable<TInput, TExtended>
|
|
9
|
+
implements Iterable<TInput | TExtended>
|
|
10
|
+
{
|
|
11
|
+
constructor(
|
|
12
|
+
private collection: ICollection<TInput>,
|
|
13
|
+
private filter: Filter<TInput, ICollection<TInput>>,
|
|
14
|
+
private iterable: Iterable<TInput | TExtended>,
|
|
15
|
+
private throwOnNumberLimit: boolean,
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
*[Symbol.iterator](): Iterator<TInput | TExtended> {
|
|
19
|
+
try {
|
|
20
|
+
let hasMatched = false;
|
|
21
|
+
for (const [index, item] of this.collection.entries(
|
|
22
|
+
this.throwOnNumberLimit,
|
|
23
|
+
)) {
|
|
24
|
+
yield item;
|
|
25
|
+
if (!hasMatched && this.filter(item, index, this.collection)) {
|
|
26
|
+
yield* this.iterable;
|
|
27
|
+
hasMatched = true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} catch (error: unknown) {
|
|
31
|
+
if (
|
|
32
|
+
error instanceof CollectionError ||
|
|
33
|
+
error instanceof TypeError
|
|
34
|
+
) {
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
throw new UnexpectedCollectionError(
|
|
38
|
+
`Unexpected error "${String(error)}" occured`,
|
|
39
|
+
error,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CollectionError,
|
|
3
|
+
type Filter,
|
|
4
|
+
type ICollection,
|
|
5
|
+
UnexpectedCollectionError,
|
|
6
|
+
} from "@/contracts/collection/_module";
|
|
7
|
+
|
|
8
|
+
export class InsertBeforeIterable<TInput, TExtended>
|
|
9
|
+
implements Iterable<TInput | TExtended>
|
|
10
|
+
{
|
|
11
|
+
constructor(
|
|
12
|
+
private collection: ICollection<TInput>,
|
|
13
|
+
private filter: Filter<TInput, ICollection<TInput>>,
|
|
14
|
+
private iterable: Iterable<TInput | TExtended>,
|
|
15
|
+
private throwOnNumberLimit: boolean,
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
*[Symbol.iterator](): Iterator<TInput | TExtended> {
|
|
19
|
+
try {
|
|
20
|
+
let hasMatched = false;
|
|
21
|
+
for (const [index, item] of this.collection.entries(
|
|
22
|
+
this.throwOnNumberLimit,
|
|
23
|
+
)) {
|
|
24
|
+
if (!hasMatched && this.filter(item, index, this.collection)) {
|
|
25
|
+
yield* this.iterable;
|
|
26
|
+
hasMatched = true;
|
|
27
|
+
}
|
|
28
|
+
yield item;
|
|
29
|
+
}
|
|
30
|
+
} catch (error: unknown) {
|
|
31
|
+
if (
|
|
32
|
+
error instanceof CollectionError ||
|
|
33
|
+
error instanceof TypeError
|
|
34
|
+
) {
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
throw new UnexpectedCollectionError(
|
|
38
|
+
`Unexpected error "${String(error)}" occured`,
|
|
39
|
+
error,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CollectionError,
|
|
3
|
+
type ICollection,
|
|
4
|
+
type Map,
|
|
5
|
+
UnexpectedCollectionError,
|
|
6
|
+
} from "@/contracts/collection/_module";
|
|
7
|
+
|
|
8
|
+
export class MapIterable<TInput, TOutput> implements Iterable<TOutput> {
|
|
9
|
+
constructor(
|
|
10
|
+
private collection: ICollection<TInput>,
|
|
11
|
+
private map: Map<TInput, ICollection<TInput>, TOutput>,
|
|
12
|
+
private throwOnNumberLimit: boolean,
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
*[Symbol.iterator](): Iterator<TOutput> {
|
|
16
|
+
try {
|
|
17
|
+
for (const [index, item] of this.collection.entries(
|
|
18
|
+
this.throwOnNumberLimit,
|
|
19
|
+
)) {
|
|
20
|
+
yield this.map(item, index, this.collection);
|
|
21
|
+
}
|
|
22
|
+
} catch (error: unknown) {
|
|
23
|
+
if (
|
|
24
|
+
error instanceof CollectionError ||
|
|
25
|
+
error instanceof TypeError
|
|
26
|
+
) {
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
throw new UnexpectedCollectionError(
|
|
30
|
+
`Unexpected error "${String(error)}" occured`,
|
|
31
|
+
error,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CollectionError,
|
|
3
|
+
UnexpectedCollectionError,
|
|
4
|
+
} from "@/contracts/collection/_module";
|
|
5
|
+
|
|
6
|
+
export class MergeIterable<TInput, TExtended>
|
|
7
|
+
implements Iterable<TInput | TExtended>
|
|
8
|
+
{
|
|
9
|
+
constructor(
|
|
10
|
+
private iterableA: Iterable<TInput>,
|
|
11
|
+
private iterableB: Iterable<TExtended>,
|
|
12
|
+
) {}
|
|
13
|
+
|
|
14
|
+
*[Symbol.iterator](): Iterator<TInput | TExtended> {
|
|
15
|
+
try {
|
|
16
|
+
yield* this.iterableA;
|
|
17
|
+
yield* this.iterableB;
|
|
18
|
+
} catch (error: unknown) {
|
|
19
|
+
if (
|
|
20
|
+
error instanceof CollectionError ||
|
|
21
|
+
error instanceof TypeError
|
|
22
|
+
) {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
throw new UnexpectedCollectionError(
|
|
26
|
+
`Unexpected error "${String(error)}" occured`,
|
|
27
|
+
error,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CollectionError,
|
|
3
|
+
UnexpectedCollectionError,
|
|
4
|
+
type ICollection,
|
|
5
|
+
} from "@/contracts/collection/_module";
|
|
6
|
+
|
|
7
|
+
export class PadEndIterable<TInput, TExtended>
|
|
8
|
+
implements Iterable<TInput | TExtended>
|
|
9
|
+
{
|
|
10
|
+
constructor(
|
|
11
|
+
private collection: ICollection<TInput>,
|
|
12
|
+
private maxLength: number,
|
|
13
|
+
private fillItems: Iterable<TExtended>,
|
|
14
|
+
private makeCollection: <TInput>(
|
|
15
|
+
iterable: Iterable<TInput | TExtended>,
|
|
16
|
+
) => ICollection<TInput | TExtended>,
|
|
17
|
+
) {}
|
|
18
|
+
|
|
19
|
+
*[Symbol.iterator](): Iterator<TInput | TExtended> {
|
|
20
|
+
try {
|
|
21
|
+
const fillCollections = this.makeCollection<TInput>(this.fillItems);
|
|
22
|
+
const fillSize = fillCollections.size();
|
|
23
|
+
const size = this.collection.size();
|
|
24
|
+
const repeat = Math.floor((this.maxLength - size) / fillSize);
|
|
25
|
+
let resultCollection: ICollection<TInput | TExtended> =
|
|
26
|
+
this.makeCollection<TInput>([]);
|
|
27
|
+
for (let index = 0; index < repeat; index++) {
|
|
28
|
+
resultCollection = resultCollection.append(fillCollections);
|
|
29
|
+
}
|
|
30
|
+
const restAmount = this.maxLength - (repeat * fillSize + size);
|
|
31
|
+
resultCollection = resultCollection.append(
|
|
32
|
+
fillCollections.slice({
|
|
33
|
+
start: 0,
|
|
34
|
+
end: restAmount,
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
resultCollection = resultCollection.prepend(this.collection);
|
|
38
|
+
yield* resultCollection;
|
|
39
|
+
} catch (error: unknown) {
|
|
40
|
+
if (
|
|
41
|
+
error instanceof CollectionError ||
|
|
42
|
+
error instanceof TypeError
|
|
43
|
+
) {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
throw new UnexpectedCollectionError(
|
|
47
|
+
`Unexpected error "${String(error)}" occured`,
|
|
48
|
+
error,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|