@the-w1zard/dx 1.0.11 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -3
- package/package.json +2 -2
- package/src/array.ts +301 -0
- package/src/boolean_byte.ts +23 -0
- package/src/class.ts +0 -0
- package/src/date.ts +660 -0
- package/src/dx.d.ts +7 -1
- package/src/error.ts +81 -0
- package/src/index.ts +45 -0
- package/src/iterator.ts +407 -0
- package/src/map.ts +513 -0
- package/src/map_bin.ts +179 -0
- package/src/map_byte.ts +418 -0
- package/src/map_dense.ts +167 -0
- package/src/map_rows.ts +145 -0
- package/src/number.ts +212 -0
- package/src/object.ts +291 -0
- package/src/promise.ts +309 -0
- package/src/reg_ex.ts +423 -0
- package/src/set.ts +198 -0
- package/src/set_byte.ts +223 -0
- package/src/soa_codec.ts +27 -0
- package/src/string.ts +175 -0
- package/src/unit8array.ts +374 -0
- package/src/url_search_params.ts +187 -0
- package/src/weak_map.ts +155 -0
- package/src/weak_set.ts +101 -0
package/src/error.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export class ER2I extends Error implements ER2 {
|
|
4
|
+
constructor(message = "", options?: ErrorOptions) {
|
|
5
|
+
super(message, options);
|
|
6
|
+
this.name = new.target.name;
|
|
7
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
clone(): ER2I {
|
|
11
|
+
const error = new ER2I(this.message, { cause: this.cause });
|
|
12
|
+
error.name = this.name;
|
|
13
|
+
error.stack = this.stack;
|
|
14
|
+
return error;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
toJSON(): {
|
|
18
|
+
name: string;
|
|
19
|
+
message: string;
|
|
20
|
+
stack?: string;
|
|
21
|
+
cause?: unknown;
|
|
22
|
+
} {
|
|
23
|
+
return {
|
|
24
|
+
name: this.name,
|
|
25
|
+
message: this.message,
|
|
26
|
+
stack: this.stack,
|
|
27
|
+
cause: this.cause,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override toString(): string {
|
|
32
|
+
return `${this.name}: ${this.message}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static is(value: unknown): value is Error {
|
|
36
|
+
return value instanceof Error;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static isER2(value: unknown): value is ER2I {
|
|
40
|
+
return value instanceof ER2I;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static from(value: unknown, fallback = "An unknown error occurred"): ER2I {
|
|
44
|
+
if (value instanceof ER2I) return value;
|
|
45
|
+
|
|
46
|
+
if (value instanceof Error) {
|
|
47
|
+
const error = new ER2I(value.message, { cause: value });
|
|
48
|
+
error.name = value.name;
|
|
49
|
+
error.stack = value.stack;
|
|
50
|
+
return error;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (typeof value === "string") {
|
|
54
|
+
return new ER2I(value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (value === null || value === undefined) {
|
|
58
|
+
return new ER2I(fallback);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
return new ER2I(String(value));
|
|
63
|
+
} catch {
|
|
64
|
+
return new ER2I(fallback);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static wrap(value: unknown, message?: string): ER2I {
|
|
69
|
+
const cause = ER2I.from(value);
|
|
70
|
+
return new ER2I(message ?? cause.message, { cause });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static aggregate(errors: Iterable<unknown>, message = "Multiple errors occurred"): AggregateError {
|
|
74
|
+
return new AggregateError(
|
|
75
|
+
Array.from(errors, error => ER2I.from(error)),
|
|
76
|
+
message,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
globalThis.ER2 = ER2I
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { A2I } from './array'
|
|
2
|
+
import { B2BI } from './boolean_byte'
|
|
3
|
+
import { D2I, R2I, R2II } from './date'
|
|
4
|
+
import { ER2I } from './error'
|
|
5
|
+
import { I2I } from './iterator'
|
|
6
|
+
import { M2BI } from './map_byte'
|
|
7
|
+
import { M2I } from './map'
|
|
8
|
+
import { N2I } from './number'
|
|
9
|
+
import { O2I } from './object'
|
|
10
|
+
import { P2I } from './promise'
|
|
11
|
+
import { REC2, RECC2 } from './reg_ex'
|
|
12
|
+
import { SET2I } from './set'
|
|
13
|
+
import { SET2BI } from './set_byte'
|
|
14
|
+
import { SOA_CODEC } from './soa_codec'
|
|
15
|
+
import { S2I } from './string'
|
|
16
|
+
import { U82I } from './unit8array'
|
|
17
|
+
import { USP2I } from './url_search_params'
|
|
18
|
+
import { WM2I } from './weak_map'
|
|
19
|
+
import { WS2I } from './weak_set'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
A2I as A2,
|
|
24
|
+
B2BI as B2B,
|
|
25
|
+
D2I as D2,
|
|
26
|
+
ER2I as ER2,
|
|
27
|
+
I2I as I2,
|
|
28
|
+
M2BI as M2B,
|
|
29
|
+
M2I as M2,
|
|
30
|
+
N2I as N2,
|
|
31
|
+
O2I as O2,
|
|
32
|
+
P2I as P2,
|
|
33
|
+
REC2 as REC,
|
|
34
|
+
SET2I as SET2,
|
|
35
|
+
SET2BI as SET2B,
|
|
36
|
+
SOA_CODEC ,
|
|
37
|
+
S2I as S2,
|
|
38
|
+
U82I as U82,
|
|
39
|
+
USP2I as USP2,
|
|
40
|
+
WM2I as WM2,
|
|
41
|
+
WS2I as WS2,
|
|
42
|
+
RECC2 as RECC,
|
|
43
|
+
R2I as R2,
|
|
44
|
+
R2II as R2I
|
|
45
|
+
}
|
package/src/iterator.ts
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export class I2I<T = A> implements I2<T> {
|
|
4
|
+
private source: Iterator<T>;
|
|
5
|
+
private index = 0;
|
|
6
|
+
private buffer: T[] = [];
|
|
7
|
+
private done = false;
|
|
8
|
+
|
|
9
|
+
constructor(source: Iterable<T> | Iterator<T>) {
|
|
10
|
+
this.source = Symbol.iterator in Object(source)
|
|
11
|
+
? (source as Iterable<T>)[Symbol.iterator]()
|
|
12
|
+
: source as Iterator<T>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
n = this.next;
|
|
16
|
+
r = this.return;
|
|
17
|
+
f = this.throw;
|
|
18
|
+
|
|
19
|
+
next(): IteratorResult<T> {
|
|
20
|
+
if (this.buffer.length) {
|
|
21
|
+
this.index++;
|
|
22
|
+
return { done: false, value: this.buffer.shift() as T };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (this.done) return { done: true, value: undefined };
|
|
26
|
+
|
|
27
|
+
const result = this.source.next();
|
|
28
|
+
if (result.done) this.done = true;
|
|
29
|
+
else this.index++;
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return(value?: A): IteratorResult<T> {
|
|
34
|
+
this.done = true;
|
|
35
|
+
this.buffer.length = 0;
|
|
36
|
+
return this.source.return
|
|
37
|
+
? this.source.return(value)
|
|
38
|
+
: { done: true, value: value as T };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
throw(error?: A): IteratorResult<T> {
|
|
42
|
+
this.done = true;
|
|
43
|
+
this.buffer.length = 0;
|
|
44
|
+
if (this.source.throw) return this.source.throw(error);
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
[Symbol.iterator](): this {
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
toArray(): AR<T> {
|
|
53
|
+
return Array.from(this);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
first(): T | UD {
|
|
57
|
+
return this.next().value;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
last(): T | UD {
|
|
61
|
+
let result: T | UD;
|
|
62
|
+
for (const value of this) result = value;
|
|
63
|
+
return result!;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
at(index: N): T | UD {
|
|
67
|
+
if (index < 0) {
|
|
68
|
+
const values = this.toArray();
|
|
69
|
+
return values[values.length + index];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let i = 0;
|
|
73
|
+
for (const value of this) {
|
|
74
|
+
if (i++ === index) return value;
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
peek(): T | UD {
|
|
80
|
+
if (!this.buffer.length && !this.done) {
|
|
81
|
+
const result = this.source.next();
|
|
82
|
+
if (result.done) this.done = true;
|
|
83
|
+
else this.buffer.push(result.value);
|
|
84
|
+
}
|
|
85
|
+
return this.buffer[0];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
nextValue(): T | UD {
|
|
89
|
+
return this.next().value;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
nextOr(value: T): T {
|
|
93
|
+
const result = this.next();
|
|
94
|
+
return result.done ? value : result.value;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
nextOrM(make: () => T): T {
|
|
98
|
+
const result = this.next();
|
|
99
|
+
return result.done ? make() : result.value;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
nextOrThrow(error: Error = new Error("Iterator exhausted")): T {
|
|
103
|
+
const result = this.next();
|
|
104
|
+
if (result.done) throw error;
|
|
105
|
+
return result.value;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
map<G>(fn: (value: T, index: N) => G): I2I<G> {
|
|
109
|
+
const source = this;
|
|
110
|
+
let index = 0;
|
|
111
|
+
return new I2I<G>({
|
|
112
|
+
next() {
|
|
113
|
+
const result = source.next();
|
|
114
|
+
return result.done ? result : { done: false, value: fn(result.value, index++) };
|
|
115
|
+
},
|
|
116
|
+
return: (value?: A): IteratorResult<G> => {
|
|
117
|
+
source.return?.();
|
|
118
|
+
return { done: true, value: value as G };
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
filter<S extends T>(pred: (value: T, index: N) => value is S): I2I<S>;
|
|
124
|
+
filter(pred: (value: T, index: N) => B): I2I<T>;
|
|
125
|
+
filter(pred: (value: T, index: N) => B): I2I<T> {
|
|
126
|
+
const source = this;
|
|
127
|
+
let index = 0;
|
|
128
|
+
return new I2I<T>({
|
|
129
|
+
next() {
|
|
130
|
+
let result: IteratorResult<T>;
|
|
131
|
+
while (!(result = source.next()).done) {
|
|
132
|
+
if (pred(result.value, index++)) return result;
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
},
|
|
136
|
+
return: (value?: A) => source.return(value),
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
flatMap<G>(fn: (value: T, index: N) => Iterable<G> | Iterator<G>): I2I<G> {
|
|
141
|
+
const source = this;
|
|
142
|
+
let index = 0;
|
|
143
|
+
let inner: Iterator<G> | undefined;
|
|
144
|
+
|
|
145
|
+
return new I2I<G>({
|
|
146
|
+
next() {
|
|
147
|
+
while (true) {
|
|
148
|
+
if (inner) {
|
|
149
|
+
const result = inner.next();
|
|
150
|
+
if (!result.done) return result;
|
|
151
|
+
inner = undefined;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const outer = source.next();
|
|
155
|
+
if (outer.done) return { done: true, value: undefined };
|
|
156
|
+
|
|
157
|
+
const mapped = fn(outer.value, index++);
|
|
158
|
+
inner = Symbol.iterator in Object(mapped)
|
|
159
|
+
? (mapped as Iterable<G>)[Symbol.iterator]()
|
|
160
|
+
: mapped as Iterator<G>;
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
return: (value?: A): IteratorResult<G> => {
|
|
164
|
+
source.return?.();
|
|
165
|
+
return { done: true, value: value as G };
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
flat<G>(this: I2I<Iterable<G> | Iterator<G>>): I2I<G> {
|
|
171
|
+
return this.flatMap(value => value);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
take(limit: N): I2I<T> {
|
|
175
|
+
const source = this;
|
|
176
|
+
let count = 0;
|
|
177
|
+
return new I2I<T>({
|
|
178
|
+
next() {
|
|
179
|
+
if (count >= limit) return { done: true, value: undefined };
|
|
180
|
+
const result = source.next();
|
|
181
|
+
if (!result.done) count++;
|
|
182
|
+
return result;
|
|
183
|
+
},
|
|
184
|
+
return: (value?: A) => source.return(value),
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
drop(limit: N): I2I<T> {
|
|
189
|
+
const source = this;
|
|
190
|
+
let dropped = false;
|
|
191
|
+
return new I2I<T>({
|
|
192
|
+
next() {
|
|
193
|
+
if (!dropped) {
|
|
194
|
+
for (let i = 0; i < limit; i++) {
|
|
195
|
+
if (source.next().done) return { done: true, value: undefined };
|
|
196
|
+
}
|
|
197
|
+
dropped = true;
|
|
198
|
+
}
|
|
199
|
+
return source.next();
|
|
200
|
+
},
|
|
201
|
+
return: (value?: A) => source.return(value),
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
unique<G = T>(fn?: (value: T, index: N) => G): I2I<T> {
|
|
206
|
+
const source = this;
|
|
207
|
+
const seen = new Set<G>();
|
|
208
|
+
let index = 0;
|
|
209
|
+
return new I2I<T>({
|
|
210
|
+
next() {
|
|
211
|
+
let result: IteratorResult<T>;
|
|
212
|
+
while (!(result = source.next()).done) {
|
|
213
|
+
const key = fn ? fn(result.value, index++) : result.value as unknown as G;
|
|
214
|
+
if (!seen.has(key)) {
|
|
215
|
+
seen.add(key);
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return result;
|
|
220
|
+
},
|
|
221
|
+
return: (value?: A) => source.return(value),
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
chunk<G>(size: N): I2I<AR<T>> {
|
|
226
|
+
if (!Number.isInteger(size) || size < 1) throw new RangeError("Chunk size must be a positive integer");
|
|
227
|
+
const source = this;
|
|
228
|
+
return new I2I<AR<T>>({
|
|
229
|
+
next() {
|
|
230
|
+
const chunk: T[] = [];
|
|
231
|
+
while (chunk.length < size) {
|
|
232
|
+
const result = source.next();
|
|
233
|
+
if (result.done) break;
|
|
234
|
+
chunk.push(result.value);
|
|
235
|
+
}
|
|
236
|
+
return chunk.length ? { done: false, value: chunk as AR<T> } : { done: true, value: undefined };
|
|
237
|
+
},
|
|
238
|
+
return: (value?: A): IteratorResult<AR<T>> => {
|
|
239
|
+
source.return?.();
|
|
240
|
+
return { done: true, value: value as AR<T> };
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
zip<G>(other: Iterable<G> | Iterator<G>): I2I<[T, G]> {
|
|
246
|
+
const left = this;
|
|
247
|
+
const right = new I2I(other);
|
|
248
|
+
return new I2I<[T, G]>({
|
|
249
|
+
next() {
|
|
250
|
+
const a = left.next();
|
|
251
|
+
const b = right.next();
|
|
252
|
+
if (a.done || b.done) {
|
|
253
|
+
left.return();
|
|
254
|
+
right.return();
|
|
255
|
+
return { done: true, value: undefined };
|
|
256
|
+
}
|
|
257
|
+
return { done: false, value: [a.value, b.value] };
|
|
258
|
+
},
|
|
259
|
+
return: (value?: A) => {
|
|
260
|
+
left.return();
|
|
261
|
+
right.return();
|
|
262
|
+
return { done: true, value: value as [T, G] };
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
concat(...others: (Iterable<T> | Iterator<T>)[]): I2I<T> {
|
|
268
|
+
const source = this;
|
|
269
|
+
let current: Iterator<T> = source;
|
|
270
|
+
let index = 0;
|
|
271
|
+
return new I2I<T>({
|
|
272
|
+
next() {
|
|
273
|
+
while (true) {
|
|
274
|
+
const result = current.next();
|
|
275
|
+
if (!result.done) return result;
|
|
276
|
+
if (index >= others.length) return { done: true, value: undefined };
|
|
277
|
+
const other = others[index++];
|
|
278
|
+
current = Symbol.iterator in Object(other)
|
|
279
|
+
? (other as Iterable<T>)[Symbol.iterator]()
|
|
280
|
+
: other as Iterator<T>;
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
return: (value?: A) => {
|
|
284
|
+
current.return?.(value);
|
|
285
|
+
return { done: true, value: value as T };
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
enumerate<G>(): I2I<[N, T]> {
|
|
291
|
+
const source = this;
|
|
292
|
+
let index = 0;
|
|
293
|
+
return new I2I<[N, T]>({
|
|
294
|
+
next() {
|
|
295
|
+
const result = source.next();
|
|
296
|
+
return result.done ? result : { done: false, value: [index++, result.value] };
|
|
297
|
+
},
|
|
298
|
+
return: (value?: A): IteratorResult<[N, T]> => {
|
|
299
|
+
source.return?.();
|
|
300
|
+
return { done: true, value: value as [N, T] };
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
find(pred: (value: T, index: N) => B): T | UD {
|
|
306
|
+
let index = 0;
|
|
307
|
+
for (const value of this) if (pred(value, index++)) return value;
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
findIndex(pred: (value: T, index: N) => B): N {
|
|
312
|
+
let index = 0;
|
|
313
|
+
for (const value of this) {
|
|
314
|
+
if (pred(value, index)) return index;
|
|
315
|
+
index++;
|
|
316
|
+
}
|
|
317
|
+
return -1 as N;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
some(pred: (value: T, index: N) => B): B {
|
|
321
|
+
let index = 0;
|
|
322
|
+
for (const value of this) if (pred(value, index++)) return true;
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
every(pred: (value: T, index: N) => B): B {
|
|
327
|
+
let index = 0;
|
|
328
|
+
for (const value of this) if (!pred(value, index++)) return false;
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
reduce<G>(fn: (acc: G, value: T, index: N) => G, initial: G): G {
|
|
333
|
+
let acc = initial;
|
|
334
|
+
let index = 0;
|
|
335
|
+
for (const value of this) acc = fn(acc, value, index++);
|
|
336
|
+
return acc;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
forEach(fn: (value: T, index: N) => void): void {
|
|
340
|
+
let index = 0;
|
|
341
|
+
for (const value of this) fn(value, index++);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
count(): N {
|
|
345
|
+
let count = 0;
|
|
346
|
+
for (const _ of this) count++;
|
|
347
|
+
return count as N;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
sum(fn?: (value: T) => N): N {
|
|
351
|
+
let sum = 0;
|
|
352
|
+
for (const value of this) sum += fn ? fn(value) : value as N;
|
|
353
|
+
return sum as N;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
join(separator: S = ","): S {
|
|
357
|
+
return this.toArray().join(separator) as S;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
partition(pred: (value: T, index: N) => B): [AR<T>, AR<T>] {
|
|
361
|
+
const yes: T[] = [];
|
|
362
|
+
const no: T[] = [];
|
|
363
|
+
let index = 0;
|
|
364
|
+
for (const value of this) (pred(value, index++) ? yes : no).push(value);
|
|
365
|
+
return [yes as AR<T>, no as AR<T>];
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
group<G>(fn: (value: T, index: N) => G): Map<G, AR<T>> {
|
|
369
|
+
const out = new Map<G, T[]>();
|
|
370
|
+
let index = 0;
|
|
371
|
+
for (const value of this) {
|
|
372
|
+
const key = fn(value, index++);
|
|
373
|
+
let group = out.get(key);
|
|
374
|
+
if (!group) out.set(key, group = []);
|
|
375
|
+
group.push(value);
|
|
376
|
+
}
|
|
377
|
+
return out as Map<G, AR<T>>;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
toSet(): Set<T> {
|
|
381
|
+
return new Set(this);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
toMap<K, V = T>(keyFn: (value: T, index: N) => K, valueFn?: (value: T, index: N) => V): Map<K, V> {
|
|
385
|
+
const out = new Map<K, V>();
|
|
386
|
+
let index = 0;
|
|
387
|
+
for (const value of this) {
|
|
388
|
+
out.set(keyFn(value, index), valueFn ? valueFn(value, index) : value as unknown as V);
|
|
389
|
+
index++;
|
|
390
|
+
}
|
|
391
|
+
return out;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
isEmpty(): B {
|
|
395
|
+
return this.peek() === undefined;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
exhaust(): void {
|
|
399
|
+
for (const _ of this) {}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
clone(): I2I<T> {
|
|
403
|
+
return new I2I(this.toArray());
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
globalThis.I2 = I2I;
|