iterable-linq-utility 0.0.16 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -0
- package/dist/index.d.cts +875 -0
- package/dist/index.d.ts +875 -14
- package/dist/iterable-linq-utility.js +641 -0
- package/dist/iterable-linq-utility.umd.cjs +1 -0
- package/package.json +42 -24
- package/dist/collections/index.d.ts +0 -2
- package/dist/collections/linkedList.d.ts +0 -24
- package/dist/functions/collectToArray.d.ts +0 -1
- package/dist/functions/empty.d.ts +0 -1
- package/dist/functions/filter.d.ts +0 -9
- package/dist/functions/flatMap.d.ts +0 -8
- package/dist/functions/forEach.d.ts +0 -3
- package/dist/functions/index.d.ts +0 -23
- package/dist/functions/map.d.ts +0 -9
- package/dist/functions/materialize.d.ts +0 -7
- package/dist/functions/max.d.ts +0 -9
- package/dist/functions/memoize.d.ts +0 -11
- package/dist/functions/min.d.ts +0 -9
- package/dist/functions/range.d.ts +0 -7
- package/dist/functions/reduce.d.ts +0 -10
- package/dist/functions/repeat.d.ts +0 -1
- package/dist/functions/some.d.ts +0 -9
- package/dist/functions/tap.d.ts +0 -9
- package/dist/functions/tapChain.d.ts +0 -9
- package/dist/interable-linq-utility.js +0 -708
- package/dist/interable-linq-utility.umd.cjs +0 -1
- package/dist/linqIterable.d.ts +0 -45
- package/dist/types/action.d.ts +0 -3
- package/dist/types/comparer.d.ts +0 -4
- package/dist/types/index.d.ts +0 -7
- package/dist/types/mapper.d.ts +0 -1
- package/dist/types/predicate.d.ts +0 -1
- package/dist/types/reducer.d.ts +0 -1
- package/dist/types/tapper.d.ts +0 -2
- package/dist/types/unit.d.ts +0 -3
- package/dist/utils/index.d.ts +0 -4
- package/dist/utils/iteratorResults.d.ts +0 -4
- package/dist/utils/utils.d.ts +0 -56
- package/dist/utils/validations.d.ts +0 -5
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var e = Object.defineProperty, t = (t, n) => {
|
|
3
|
+
let r = {};
|
|
4
|
+
for (var i in t) e(r, i, {
|
|
5
|
+
get: t[i],
|
|
6
|
+
enumerable: !0
|
|
7
|
+
});
|
|
8
|
+
return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/utils/utils.ts
|
|
12
|
+
function n(e) {
|
|
13
|
+
return typeof e == "function";
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/utils/compare.ts
|
|
17
|
+
function r(e, t) {
|
|
18
|
+
return e < t ? -1 : e === t ? 0 : 1;
|
|
19
|
+
}
|
|
20
|
+
function i(e) {
|
|
21
|
+
if (e == null) return r;
|
|
22
|
+
if (n(e)) return e;
|
|
23
|
+
let t = Array.isArray(e) ? e : [e];
|
|
24
|
+
return (e, n) => {
|
|
25
|
+
for (let i of t) {
|
|
26
|
+
let t = r(e[i], n[i]);
|
|
27
|
+
if (t !== 0) return t;
|
|
28
|
+
}
|
|
29
|
+
return 0;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function a(e, t, n) {
|
|
33
|
+
let r, i = !1;
|
|
34
|
+
for (let a of e) !i || r == null && a != null ? (r = a, i = !0) : a != null && n * t(r, a) < 0 && (r = a);
|
|
35
|
+
return r;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/utils/iteratorResults.ts
|
|
39
|
+
function o(e) {
|
|
40
|
+
return {
|
|
41
|
+
done: !1,
|
|
42
|
+
value: e
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function s(e) {
|
|
46
|
+
return {
|
|
47
|
+
done: !0,
|
|
48
|
+
value: e
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/utils/validations.ts
|
|
53
|
+
function c(e) {
|
|
54
|
+
if (e == null) throw Error("The \"sourceIterable\" must be provided");
|
|
55
|
+
if (!n(e[Symbol.iterator])) throw Error("The provided \"sourceIterable\" does not conform to the iterator protocol https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol. It must implement the \"[Symbol.iterator]\" function.");
|
|
56
|
+
}
|
|
57
|
+
function l(e, t) {
|
|
58
|
+
if (!n(e)) throw Error(`The "${t}" function must be provided`);
|
|
59
|
+
}
|
|
60
|
+
function ee(e, t) {
|
|
61
|
+
if (!Number.isInteger(e) || e < 0) throw Error(`The "${t}" parameter must be a non-negative integer`);
|
|
62
|
+
}
|
|
63
|
+
function u(e, t) {
|
|
64
|
+
if (!Number.isFinite(e) || e === 0) throw Error(`The "${t}" parameter must be a finite number other than 0`);
|
|
65
|
+
}
|
|
66
|
+
function te(e, t) {
|
|
67
|
+
if (typeof e != "object" || !e) throw Error(`The "${t}" parameter must be an object`);
|
|
68
|
+
}
|
|
69
|
+
function ne(e, t) {
|
|
70
|
+
if (typeof e != "string" || e.length === 0) throw Error(`The "${t}" parameter must be a non-empty string`);
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/functions/collectToArray.ts
|
|
74
|
+
function d(e) {
|
|
75
|
+
if (c(e), Array.isArray(e) || e instanceof Set) return Array.from(e);
|
|
76
|
+
let t = [];
|
|
77
|
+
for (let n of e) t.push(n);
|
|
78
|
+
return t;
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/iterators/baseIterator.ts
|
|
82
|
+
var f = class {
|
|
83
|
+
done = !1;
|
|
84
|
+
next() {
|
|
85
|
+
if (this.done) return s();
|
|
86
|
+
let e = this.advance();
|
|
87
|
+
return e.done === !0 && (this.done = !0), e;
|
|
88
|
+
}
|
|
89
|
+
return(e) {
|
|
90
|
+
return this.done || (this.done = !0, this.onReturn(e)), s(e);
|
|
91
|
+
}
|
|
92
|
+
[Symbol.iterator]() {
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
onReturn(e) {}
|
|
96
|
+
closeAfterCallbackError() {
|
|
97
|
+
if (!this.done) {
|
|
98
|
+
this.done = !0;
|
|
99
|
+
try {
|
|
100
|
+
this.onReturn();
|
|
101
|
+
} catch {}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}, p = class {
|
|
105
|
+
createIterator;
|
|
106
|
+
constructor(e) {
|
|
107
|
+
this.createIterator = e;
|
|
108
|
+
}
|
|
109
|
+
[Symbol.iterator]() {
|
|
110
|
+
return this.createIterator();
|
|
111
|
+
}
|
|
112
|
+
}, m = class extends f {
|
|
113
|
+
source;
|
|
114
|
+
index = 0;
|
|
115
|
+
constructor(e) {
|
|
116
|
+
super(), this.source = e[Symbol.iterator]();
|
|
117
|
+
}
|
|
118
|
+
onReturn(e) {
|
|
119
|
+
this.source.return?.(e);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/iterators/unfold.ts
|
|
124
|
+
function h(e, t) {
|
|
125
|
+
return new p(() => new g(e, t));
|
|
126
|
+
}
|
|
127
|
+
var g = class extends f {
|
|
128
|
+
state;
|
|
129
|
+
step;
|
|
130
|
+
constructor(e, t) {
|
|
131
|
+
super(), this.state = e, this.step = t;
|
|
132
|
+
}
|
|
133
|
+
advance() {
|
|
134
|
+
let e = this.step(this.state);
|
|
135
|
+
return e === void 0 ? s() : (this.state = e[1], o(e[0]));
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/functions/empty.ts
|
|
140
|
+
function _() {
|
|
141
|
+
return h(void 0, () => void 0);
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/functions/filter.ts
|
|
145
|
+
function v(e, t) {
|
|
146
|
+
return c(e), l(t, "predicate"), new p(() => new y(e, t));
|
|
147
|
+
}
|
|
148
|
+
var y = class extends m {
|
|
149
|
+
predicate;
|
|
150
|
+
constructor(e, t) {
|
|
151
|
+
super(e), this.predicate = t;
|
|
152
|
+
}
|
|
153
|
+
advance() {
|
|
154
|
+
for (let e = this.source.next();; e = this.source.next()) {
|
|
155
|
+
if (e.done === !0) return e;
|
|
156
|
+
let t;
|
|
157
|
+
try {
|
|
158
|
+
t = this.predicate(e.value, this.index++);
|
|
159
|
+
} catch (e) {
|
|
160
|
+
throw this.closeAfterCallbackError(), e;
|
|
161
|
+
}
|
|
162
|
+
if (t) return e;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/functions/flatMap.ts
|
|
168
|
+
function b(e, t) {
|
|
169
|
+
return c(e), l(t, "mapper"), new p(() => new re(e, t));
|
|
170
|
+
}
|
|
171
|
+
var re = class e extends m {
|
|
172
|
+
mapper;
|
|
173
|
+
static steps = {
|
|
174
|
+
outer: (t) => {
|
|
175
|
+
let n = t.source.next();
|
|
176
|
+
if (n.done === !0) return n;
|
|
177
|
+
let r = e.mapNext(t, n.value);
|
|
178
|
+
if (r === void 0) {
|
|
179
|
+
t.state = "inner";
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (r.length !== 0) return t.array = r, t.position = 1, t.state = "array", o(r[0]);
|
|
183
|
+
},
|
|
184
|
+
inner: (t) => {
|
|
185
|
+
let n = e.nextInner(t);
|
|
186
|
+
if (n.done !== !0) return n;
|
|
187
|
+
t.inner = void 0, t.state = "outer";
|
|
188
|
+
},
|
|
189
|
+
array: (e) => {
|
|
190
|
+
if (e.position < e.array.length) return o(e.array[e.position++]);
|
|
191
|
+
e.array = void 0, e.state = "outer";
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
state = "outer";
|
|
195
|
+
inner;
|
|
196
|
+
array;
|
|
197
|
+
position = 0;
|
|
198
|
+
constructor(e, t) {
|
|
199
|
+
super(e), this.mapper = t;
|
|
200
|
+
}
|
|
201
|
+
advance() {
|
|
202
|
+
for (;;) {
|
|
203
|
+
let t = e.steps[this.state](this);
|
|
204
|
+
if (t !== void 0) return t;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
onReturn(e) {
|
|
208
|
+
this.array = void 0;
|
|
209
|
+
try {
|
|
210
|
+
this.inner?.return?.(e);
|
|
211
|
+
} finally {
|
|
212
|
+
super.onReturn(e);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
static mapNext(e, t) {
|
|
216
|
+
try {
|
|
217
|
+
let n = e.mapper(t, e.index++);
|
|
218
|
+
if (Array.isArray(n)) return n;
|
|
219
|
+
e.inner = n[Symbol.iterator]();
|
|
220
|
+
return;
|
|
221
|
+
} catch (t) {
|
|
222
|
+
throw e.closeAfterCallbackError(), t;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
static nextInner(e) {
|
|
226
|
+
try {
|
|
227
|
+
return e.inner.next();
|
|
228
|
+
} catch (t) {
|
|
229
|
+
throw e.inner = void 0, e.closeAfterCallbackError(), t;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}, x = class e {
|
|
233
|
+
static instance = e.createFrozen();
|
|
234
|
+
constructor() {}
|
|
235
|
+
static createFrozen() {
|
|
236
|
+
let t = new e();
|
|
237
|
+
return Object.freeze(t), t;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
function S() {
|
|
241
|
+
return x.instance;
|
|
242
|
+
}
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/functions/forEach.ts
|
|
245
|
+
function C(e, t) {
|
|
246
|
+
c(e), l(t, "action");
|
|
247
|
+
let n = 0;
|
|
248
|
+
for (let r of e) t(r, n++);
|
|
249
|
+
return S();
|
|
250
|
+
}
|
|
251
|
+
async function w(e, t) {
|
|
252
|
+
c(e), l(t, "action");
|
|
253
|
+
let n = 0;
|
|
254
|
+
for (let r of e) await t(r, n++);
|
|
255
|
+
return S();
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region src/functions/map.ts
|
|
259
|
+
function T(e, t) {
|
|
260
|
+
return c(e), l(t, "mapper"), new p(() => new E(e, t));
|
|
261
|
+
}
|
|
262
|
+
var E = class extends m {
|
|
263
|
+
mapper;
|
|
264
|
+
constructor(e, t) {
|
|
265
|
+
super(e), this.mapper = t;
|
|
266
|
+
}
|
|
267
|
+
advance() {
|
|
268
|
+
let e = this.source.next();
|
|
269
|
+
if (e.done === !0) return e;
|
|
270
|
+
let t;
|
|
271
|
+
try {
|
|
272
|
+
t = this.mapper(e.value, this.index++);
|
|
273
|
+
} catch (e) {
|
|
274
|
+
throw this.closeAfterCallbackError(), e;
|
|
275
|
+
}
|
|
276
|
+
return o(t);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/collections/linkedList.ts
|
|
281
|
+
function D(e) {
|
|
282
|
+
c(e);
|
|
283
|
+
let t = new ie();
|
|
284
|
+
for (let n of e) t.addLast(n);
|
|
285
|
+
return t;
|
|
286
|
+
}
|
|
287
|
+
var ie = class {
|
|
288
|
+
internalSize = 0;
|
|
289
|
+
head = null;
|
|
290
|
+
tail = null;
|
|
291
|
+
[Symbol.iterator]() {
|
|
292
|
+
return new ae(this.head);
|
|
293
|
+
}
|
|
294
|
+
addFirst(e) {
|
|
295
|
+
let t = {
|
|
296
|
+
data: e,
|
|
297
|
+
nextNode: this.head
|
|
298
|
+
};
|
|
299
|
+
return this.tail === null && (this.tail = t), this.head = t, this.internalSize++, this;
|
|
300
|
+
}
|
|
301
|
+
addLast(e) {
|
|
302
|
+
let t = {
|
|
303
|
+
data: e,
|
|
304
|
+
nextNode: null
|
|
305
|
+
};
|
|
306
|
+
return this.tail === null ? this.head = t : this.tail.nextNode = t, this.tail = t, this.internalSize++, this;
|
|
307
|
+
}
|
|
308
|
+
size() {
|
|
309
|
+
return this.internalSize;
|
|
310
|
+
}
|
|
311
|
+
}, ae = class extends f {
|
|
312
|
+
current;
|
|
313
|
+
constructor(e) {
|
|
314
|
+
super(), this.current = e;
|
|
315
|
+
}
|
|
316
|
+
advance() {
|
|
317
|
+
let e = this.current;
|
|
318
|
+
return e === null ? s() : (this.current = e.nextNode, o(e.data));
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
//#endregion
|
|
322
|
+
//#region src/functions/materialize.ts
|
|
323
|
+
function O(e) {
|
|
324
|
+
return c(e), e instanceof k ? e : new k(e);
|
|
325
|
+
}
|
|
326
|
+
var k = class {
|
|
327
|
+
source;
|
|
328
|
+
constructor(e) {
|
|
329
|
+
this.source = D(e);
|
|
330
|
+
}
|
|
331
|
+
[Symbol.iterator]() {
|
|
332
|
+
return this.source[Symbol.iterator]();
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region src/functions/max.ts
|
|
337
|
+
function A(e, t) {
|
|
338
|
+
return c(e), a(e, i(t), 1);
|
|
339
|
+
}
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region src/functions/memoize.ts
|
|
342
|
+
function j() {
|
|
343
|
+
return { allowPartialMemoization: !0 };
|
|
344
|
+
}
|
|
345
|
+
function M(e, t) {
|
|
346
|
+
c(e);
|
|
347
|
+
let n = {
|
|
348
|
+
...j(),
|
|
349
|
+
...t
|
|
350
|
+
}.allowPartialMemoization;
|
|
351
|
+
return e instanceof F ? n ? e.changePartialMemoizationBehaviour() : e : e instanceof I ? n ? e : e.changePartialMemoizationBehaviour() : n ? new I(e) : new F(e);
|
|
352
|
+
}
|
|
353
|
+
function N() {
|
|
354
|
+
return {
|
|
355
|
+
values: [],
|
|
356
|
+
finished: !1
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function P(e, t) {
|
|
360
|
+
if (t.error) throw t.error.value;
|
|
361
|
+
if (t.finished) return !1;
|
|
362
|
+
t.source ??= e[Symbol.iterator]();
|
|
363
|
+
let n;
|
|
364
|
+
try {
|
|
365
|
+
n = t.source.next();
|
|
366
|
+
} catch (e) {
|
|
367
|
+
throw t.error = { value: e }, t.source = void 0, e;
|
|
368
|
+
}
|
|
369
|
+
return n.done === !0 ? (t.finished = !0, t.source = void 0, !1) : (t.values.push(n.value), !0);
|
|
370
|
+
}
|
|
371
|
+
var F = class {
|
|
372
|
+
source;
|
|
373
|
+
cache = N();
|
|
374
|
+
constructor(e) {
|
|
375
|
+
this.source = e;
|
|
376
|
+
}
|
|
377
|
+
[Symbol.iterator]() {
|
|
378
|
+
return new L(this.source, this.cache, !0);
|
|
379
|
+
}
|
|
380
|
+
changePartialMemoizationBehaviour() {
|
|
381
|
+
return new I(this.source);
|
|
382
|
+
}
|
|
383
|
+
}, I = class {
|
|
384
|
+
source;
|
|
385
|
+
cache = N();
|
|
386
|
+
constructor(e) {
|
|
387
|
+
this.source = e;
|
|
388
|
+
}
|
|
389
|
+
[Symbol.iterator]() {
|
|
390
|
+
return new L(this.source, this.cache, !1);
|
|
391
|
+
}
|
|
392
|
+
changePartialMemoizationBehaviour() {
|
|
393
|
+
return new F(this.source);
|
|
394
|
+
}
|
|
395
|
+
}, L = class extends f {
|
|
396
|
+
source;
|
|
397
|
+
cache;
|
|
398
|
+
drainFirst;
|
|
399
|
+
index = 0;
|
|
400
|
+
constructor(e, t, n) {
|
|
401
|
+
super(), this.source = e, this.cache = t, this.drainFirst = n;
|
|
402
|
+
}
|
|
403
|
+
advance() {
|
|
404
|
+
if (this.drainFirst) for (; P(this.source, this.cache););
|
|
405
|
+
return this.index < this.cache.values.length || P(this.source, this.cache) ? o(this.cache.values[this.index++]) : s();
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
//#endregion
|
|
409
|
+
//#region src/functions/min.ts
|
|
410
|
+
function R(e, t) {
|
|
411
|
+
return c(e), a(e, i(t), -1);
|
|
412
|
+
}
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region src/functions/range.ts
|
|
415
|
+
function z(e, t, n) {
|
|
416
|
+
let r = typeof t == "number", i = r ? e : 0, a = r ? t : e;
|
|
417
|
+
if (!r && n !== void 0) throw Error("The \"options\" parameter must be the second argument when \"start\" is omitted");
|
|
418
|
+
let o = r ? n : t;
|
|
419
|
+
o !== void 0 && te(o, "options");
|
|
420
|
+
let { step: s = 1, reverse: c = !1 } = o ?? {};
|
|
421
|
+
u(s, "step");
|
|
422
|
+
let l = oe(i, a, Math.abs(s), c);
|
|
423
|
+
return l.length > 0 ? new p(() => new se(l.first, l.step, l.length)) : _();
|
|
424
|
+
}
|
|
425
|
+
function oe(e, t, n, r) {
|
|
426
|
+
let i = t < e ? -n : n, a = Math.ceil(Math.abs(t - e) / n);
|
|
427
|
+
return r ? {
|
|
428
|
+
first: e + (a - 1) * i,
|
|
429
|
+
step: -i,
|
|
430
|
+
length: a
|
|
431
|
+
} : {
|
|
432
|
+
first: e,
|
|
433
|
+
step: i,
|
|
434
|
+
length: a
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
var se = class extends f {
|
|
438
|
+
first;
|
|
439
|
+
step;
|
|
440
|
+
length;
|
|
441
|
+
index = 0;
|
|
442
|
+
constructor(e, t, n) {
|
|
443
|
+
super(), this.first = e, this.step = t, this.length = n;
|
|
444
|
+
}
|
|
445
|
+
advance() {
|
|
446
|
+
return this.index >= this.length ? s() : o(this.first + this.index++ * this.step);
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
//#endregion
|
|
450
|
+
//#region src/functions/reduce.ts
|
|
451
|
+
function B(e, ...t) {
|
|
452
|
+
if (c(e), t.length === 1) return V(e, t[0]);
|
|
453
|
+
let [n, r] = t;
|
|
454
|
+
l(r, "reducer");
|
|
455
|
+
let i = n, a = 0;
|
|
456
|
+
for (let t of e) i = r(i, t, a++);
|
|
457
|
+
return i;
|
|
458
|
+
}
|
|
459
|
+
function V(e, t) {
|
|
460
|
+
l(t, "reducer");
|
|
461
|
+
let n, r = 0;
|
|
462
|
+
for (let i of e) n = r === 0 ? i : t(n, i, r), r++;
|
|
463
|
+
if (r === 0) throw Error("The \"sourceIterable\" must not be empty when \"reduce\" has no seed");
|
|
464
|
+
return n;
|
|
465
|
+
}
|
|
466
|
+
//#endregion
|
|
467
|
+
//#region src/functions/repeat.ts
|
|
468
|
+
function H(e, t) {
|
|
469
|
+
return ee(t, "count"), h(t, (t) => t > 0 ? [e, t - 1] : void 0);
|
|
470
|
+
}
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region src/functions/some.ts
|
|
473
|
+
function U(e, t) {
|
|
474
|
+
c(e), l(t, "predicate");
|
|
475
|
+
let n = 0;
|
|
476
|
+
for (let r of e) if (t(r, n++)) return !0;
|
|
477
|
+
return !1;
|
|
478
|
+
}
|
|
479
|
+
//#endregion
|
|
480
|
+
//#region src/functions/tap.ts
|
|
481
|
+
function W(e, t) {
|
|
482
|
+
return c(e), l(t, "tapper"), new p(() => new G(e, t));
|
|
483
|
+
}
|
|
484
|
+
var G = class extends m {
|
|
485
|
+
tapper;
|
|
486
|
+
constructor(e, t) {
|
|
487
|
+
super(e), this.tapper = t;
|
|
488
|
+
}
|
|
489
|
+
advance() {
|
|
490
|
+
let e = this.source.next();
|
|
491
|
+
if (e.done === !0) return e;
|
|
492
|
+
try {
|
|
493
|
+
this.tapper(e.value, this.index++);
|
|
494
|
+
} catch (e) {
|
|
495
|
+
throw this.closeAfterCallbackError(), e;
|
|
496
|
+
}
|
|
497
|
+
return e;
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
//#endregion
|
|
501
|
+
//#region src/functions/tapChain.ts
|
|
502
|
+
function K(e, t) {
|
|
503
|
+
return c(e), l(t, "tapper"), new p(() => (t(e, 0), e[Symbol.iterator]()));
|
|
504
|
+
}
|
|
505
|
+
//#endregion
|
|
506
|
+
//#region src/functions/index.ts
|
|
507
|
+
var ce = /* @__PURE__ */ t({
|
|
508
|
+
collectToArray: () => d,
|
|
509
|
+
empty: () => _,
|
|
510
|
+
filter: () => v,
|
|
511
|
+
flatMap: () => b,
|
|
512
|
+
forEach: () => C,
|
|
513
|
+
forEachAsync: () => w,
|
|
514
|
+
getMemoizeDefaultOptions: () => j,
|
|
515
|
+
map: () => T,
|
|
516
|
+
materialize: () => O,
|
|
517
|
+
max: () => A,
|
|
518
|
+
memoize: () => M,
|
|
519
|
+
min: () => R,
|
|
520
|
+
range: () => z,
|
|
521
|
+
reduce: () => B,
|
|
522
|
+
repeat: () => H,
|
|
523
|
+
some: () => U,
|
|
524
|
+
tap: () => W,
|
|
525
|
+
tapChain: () => K
|
|
526
|
+
}), q = Symbol.for("iterable-linq-utility.IIterableLinq");
|
|
527
|
+
//#endregion
|
|
528
|
+
//#region src/linqIterable.ts
|
|
529
|
+
function J(e) {
|
|
530
|
+
return new Y(e);
|
|
531
|
+
}
|
|
532
|
+
var Y = class {
|
|
533
|
+
iterable;
|
|
534
|
+
constructor(e) {
|
|
535
|
+
this.iterable = e;
|
|
536
|
+
}
|
|
537
|
+
[Symbol.iterator]() {
|
|
538
|
+
return this.iterable[Symbol.iterator]();
|
|
539
|
+
}
|
|
540
|
+
collectToArray() {
|
|
541
|
+
return d(this.iterable);
|
|
542
|
+
}
|
|
543
|
+
filter(e) {
|
|
544
|
+
return J(v(this.iterable, e));
|
|
545
|
+
}
|
|
546
|
+
flatMap(e) {
|
|
547
|
+
return J(b(this.iterable, e));
|
|
548
|
+
}
|
|
549
|
+
forEach(e) {
|
|
550
|
+
return C(this.iterable, e);
|
|
551
|
+
}
|
|
552
|
+
forEachAsync(e) {
|
|
553
|
+
return w(this.iterable, e);
|
|
554
|
+
}
|
|
555
|
+
map(e) {
|
|
556
|
+
return J(T(this.iterable, e));
|
|
557
|
+
}
|
|
558
|
+
materialize() {
|
|
559
|
+
return J(O(this.iterable));
|
|
560
|
+
}
|
|
561
|
+
max(e) {
|
|
562
|
+
return A(this.iterable, e);
|
|
563
|
+
}
|
|
564
|
+
memoize(e) {
|
|
565
|
+
return J(M(this.iterable, e));
|
|
566
|
+
}
|
|
567
|
+
min(e) {
|
|
568
|
+
return R(this.iterable, e);
|
|
569
|
+
}
|
|
570
|
+
reduce(...e) {
|
|
571
|
+
return e.length === 1 ? B(this.iterable, e[0]) : B(this.iterable, e[0], e[1]);
|
|
572
|
+
}
|
|
573
|
+
some(e) {
|
|
574
|
+
return U(this.iterable, e);
|
|
575
|
+
}
|
|
576
|
+
tap(e) {
|
|
577
|
+
return J(W(this.iterable, e));
|
|
578
|
+
}
|
|
579
|
+
tapChain(e) {
|
|
580
|
+
return J(K(this.iterable, e));
|
|
581
|
+
}
|
|
582
|
+
tapChainCreation(e) {
|
|
583
|
+
l(e, "chainCreationTapper");
|
|
584
|
+
let t = this;
|
|
585
|
+
return e(t), t;
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
Object.defineProperty(Y.prototype, q, {
|
|
589
|
+
value: !0,
|
|
590
|
+
enumerable: !1,
|
|
591
|
+
writable: !1,
|
|
592
|
+
configurable: !1
|
|
593
|
+
});
|
|
594
|
+
//#endregion
|
|
595
|
+
//#region src/extension.ts
|
|
596
|
+
function X() {
|
|
597
|
+
return Y.prototype;
|
|
598
|
+
}
|
|
599
|
+
function le(e) {
|
|
600
|
+
return typeof e == "object" && !!e && e[q] === !0;
|
|
601
|
+
}
|
|
602
|
+
function Z(e, t) {
|
|
603
|
+
let n = Object.getOwnPropertyDescriptor(X(), e);
|
|
604
|
+
Object.defineProperty(X(), e, {
|
|
605
|
+
value: t,
|
|
606
|
+
enumerable: !1,
|
|
607
|
+
writable: n?.writable ?? !1,
|
|
608
|
+
configurable: !0
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
function Q(e, t) {
|
|
612
|
+
ne(e, "name"), l(t, "implementation");
|
|
613
|
+
}
|
|
614
|
+
function ue(e, t) {
|
|
615
|
+
if (Q(e, t), e in J([])) throw Error(`"${e}" already exists on IIterableLinq: use override() to replace it`);
|
|
616
|
+
Z(e, t);
|
|
617
|
+
}
|
|
618
|
+
function de(e, t) {
|
|
619
|
+
Q(e, t);
|
|
620
|
+
let n = e;
|
|
621
|
+
if (!(n !== "constructor" && Object.prototype.hasOwnProperty.call(X(), n))) throw Error(`"${n}" is not a method of IIterableLinq: use extend() to add it`);
|
|
622
|
+
Z(n, t);
|
|
623
|
+
}
|
|
624
|
+
//#endregion
|
|
625
|
+
//#region src/index.ts
|
|
626
|
+
function fe() {
|
|
627
|
+
return $(_());
|
|
628
|
+
}
|
|
629
|
+
function $(e) {
|
|
630
|
+
return c(e), J(e);
|
|
631
|
+
}
|
|
632
|
+
function pe(e, t, n) {
|
|
633
|
+
if (typeof t == "number") return $(z(e, t, n));
|
|
634
|
+
if (n !== void 0) throw Error("The \"options\" parameter must be the second argument when \"start\" is omitted");
|
|
635
|
+
return $(z(e, t));
|
|
636
|
+
}
|
|
637
|
+
function me(e, t) {
|
|
638
|
+
return $(H(e, t));
|
|
639
|
+
}
|
|
640
|
+
//#endregion
|
|
641
|
+
export { ce as Functions, x as Unit, fe as empty, ue as extend, $ as from, pe as fromRange, le as isIterableLinq, de as override, me as repeat, S as unit };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.IterableLinq={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.defineProperty,n=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r};function r(e){return typeof e==`function`}function i(e,t){return e<t?-1:e===t?0:1}function a(e){if(e==null)return i;if(r(e))return e;let t=Array.isArray(e)?e:[e];return(e,n)=>{for(let r of t){let t=i(e[r],n[r]);if(t!==0)return t}return 0}}function o(e,t,n){let r,i=!1;for(let a of e)!i||r==null&&a!=null?(r=a,i=!0):a!=null&&n*t(r,a)<0&&(r=a);return r}function s(e){return{done:!1,value:e}}function c(e){return{done:!0,value:e}}function l(e){if(e==null)throw Error(`The "sourceIterable" must be provided`);if(!r(e[Symbol.iterator]))throw Error(`The provided "sourceIterable" does not conform to the iterator protocol https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol. It must implement the "[Symbol.iterator]" function.`)}function u(e,t){if(!r(e))throw Error(`The "${t}" function must be provided`)}function d(e,t){if(!Number.isInteger(e)||e<0)throw Error(`The "${t}" parameter must be a non-negative integer`)}function ee(e,t){if(!Number.isFinite(e)||e===0)throw Error(`The "${t}" parameter must be a finite number other than 0`)}function te(e,t){if(typeof e!=`object`||!e)throw Error(`The "${t}" parameter must be an object`)}function ne(e,t){if(typeof e!=`string`||e.length===0)throw Error(`The "${t}" parameter must be a non-empty string`)}function f(e){if(l(e),Array.isArray(e)||e instanceof Set)return Array.from(e);let t=[];for(let n of e)t.push(n);return t}var p=class{done=!1;next(){if(this.done)return c();let e=this.advance();return e.done===!0&&(this.done=!0),e}return(e){return this.done||(this.done=!0,this.onReturn(e)),c(e)}[Symbol.iterator](){return this}onReturn(e){}closeAfterCallbackError(){if(!this.done){this.done=!0;try{this.onReturn()}catch{}}}},m=class{createIterator;constructor(e){this.createIterator=e}[Symbol.iterator](){return this.createIterator()}},h=class extends p{source;index=0;constructor(e){super(),this.source=e[Symbol.iterator]()}onReturn(e){this.source.return?.(e)}};function g(e,t){return new m(()=>new re(e,t))}var re=class extends p{state;step;constructor(e,t){super(),this.state=e,this.step=t}advance(){let e=this.step(this.state);return e===void 0?c():(this.state=e[1],s(e[0]))}};function _(){return g(void 0,()=>void 0)}function v(e,t){return l(e),u(t,`predicate`),new m(()=>new ie(e,t))}var ie=class extends h{predicate;constructor(e,t){super(e),this.predicate=t}advance(){for(let e=this.source.next();;e=this.source.next()){if(e.done===!0)return e;let t;try{t=this.predicate(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}if(t)return e}}};function y(e,t){return l(e),u(t,`mapper`),new m(()=>new ae(e,t))}var ae=class e extends h{mapper;static steps={outer:t=>{let n=t.source.next();if(n.done===!0)return n;let r=e.mapNext(t,n.value);if(r===void 0){t.state=`inner`;return}if(r.length!==0)return t.array=r,t.position=1,t.state=`array`,s(r[0])},inner:t=>{let n=e.nextInner(t);if(n.done!==!0)return n;t.inner=void 0,t.state=`outer`},array:e=>{if(e.position<e.array.length)return s(e.array[e.position++]);e.array=void 0,e.state=`outer`}};state=`outer`;inner;array;position=0;constructor(e,t){super(e),this.mapper=t}advance(){for(;;){let t=e.steps[this.state](this);if(t!==void 0)return t}}onReturn(e){this.array=void 0;try{this.inner?.return?.(e)}finally{super.onReturn(e)}}static mapNext(e,t){try{let n=e.mapper(t,e.index++);if(Array.isArray(n))return n;e.inner=n[Symbol.iterator]();return}catch(t){throw e.closeAfterCallbackError(),t}}static nextInner(e){try{return e.inner.next()}catch(t){throw e.inner=void 0,e.closeAfterCallbackError(),t}}},b=class e{static instance=e.createFrozen();constructor(){}static createFrozen(){let t=new e;return Object.freeze(t),t}};function x(){return b.instance}function S(e,t){l(e),u(t,`action`);let n=0;for(let r of e)t(r,n++);return x()}async function C(e,t){l(e),u(t,`action`);let n=0;for(let r of e)await t(r,n++);return x()}function w(e,t){return l(e),u(t,`mapper`),new m(()=>new T(e,t))}var T=class extends h{mapper;constructor(e,t){super(e),this.mapper=t}advance(){let e=this.source.next();if(e.done===!0)return e;let t;try{t=this.mapper(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}return s(t)}};function E(e){l(e);let t=new D;for(let n of e)t.addLast(n);return t}var D=class{internalSize=0;head=null;tail=null;[Symbol.iterator](){return new oe(this.head)}addFirst(e){let t={data:e,nextNode:this.head};return this.tail===null&&(this.tail=t),this.head=t,this.internalSize++,this}addLast(e){let t={data:e,nextNode:null};return this.tail===null?this.head=t:this.tail.nextNode=t,this.tail=t,this.internalSize++,this}size(){return this.internalSize}},oe=class extends p{current;constructor(e){super(),this.current=e}advance(){let e=this.current;return e===null?c():(this.current=e.nextNode,s(e.data))}};function O(e){return l(e),e instanceof k?e:new k(e)}var k=class{source;constructor(e){this.source=E(e)}[Symbol.iterator](){return this.source[Symbol.iterator]()}};function A(e,t){return l(e),o(e,a(t),1)}function j(){return{allowPartialMemoization:!0}}function M(e,t){l(e);let n={...j(),...t}.allowPartialMemoization;return e instanceof F?n?e.changePartialMemoizationBehaviour():e:e instanceof I?n?e:e.changePartialMemoizationBehaviour():n?new I(e):new F(e)}function N(){return{values:[],finished:!1}}function P(e,t){if(t.error)throw t.error.value;if(t.finished)return!1;t.source??=e[Symbol.iterator]();let n;try{n=t.source.next()}catch(e){throw t.error={value:e},t.source=void 0,e}return n.done===!0?(t.finished=!0,t.source=void 0,!1):(t.values.push(n.value),!0)}var F=class{source;cache=N();constructor(e){this.source=e}[Symbol.iterator](){return new L(this.source,this.cache,!0)}changePartialMemoizationBehaviour(){return new I(this.source)}},I=class{source;cache=N();constructor(e){this.source=e}[Symbol.iterator](){return new L(this.source,this.cache,!1)}changePartialMemoizationBehaviour(){return new F(this.source)}},L=class extends p{source;cache;drainFirst;index=0;constructor(e,t,n){super(),this.source=e,this.cache=t,this.drainFirst=n}advance(){if(this.drainFirst)for(;P(this.source,this.cache););return this.index<this.cache.values.length||P(this.source,this.cache)?s(this.cache.values[this.index++]):c()}};function R(e,t){return l(e),o(e,a(t),-1)}function z(e,t,n){let r=typeof t==`number`,i=r?e:0,a=r?t:e;if(!r&&n!==void 0)throw Error(`The "options" parameter must be the second argument when "start" is omitted`);let o=r?n:t;o!==void 0&&te(o,`options`);let{step:s=1,reverse:c=!1}=o??{};ee(s,`step`);let l=se(i,a,Math.abs(s),c);return l.length>0?new m(()=>new B(l.first,l.step,l.length)):_()}function se(e,t,n,r){let i=t<e?-n:n,a=Math.ceil(Math.abs(t-e)/n);return r?{first:e+(a-1)*i,step:-i,length:a}:{first:e,step:i,length:a}}var B=class extends p{first;step;length;index=0;constructor(e,t,n){super(),this.first=e,this.step=t,this.length=n}advance(){return this.index>=this.length?c():s(this.first+this.index++*this.step)}};function V(e,...t){if(l(e),t.length===1)return H(e,t[0]);let[n,r]=t;u(r,`reducer`);let i=n,a=0;for(let t of e)i=r(i,t,a++);return i}function H(e,t){u(t,`reducer`);let n,r=0;for(let i of e)n=r===0?i:t(n,i,r),r++;if(r===0)throw Error(`The "sourceIterable" must not be empty when "reduce" has no seed`);return n}function U(e,t){return d(t,`count`),g(t,t=>t>0?[e,t-1]:void 0)}function W(e,t){l(e),u(t,`predicate`);let n=0;for(let r of e)if(t(r,n++))return!0;return!1}function G(e,t){return l(e),u(t,`tapper`),new m(()=>new ce(e,t))}var ce=class extends h{tapper;constructor(e,t){super(e),this.tapper=t}advance(){let e=this.source.next();if(e.done===!0)return e;try{this.tapper(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}return e}};function K(e,t){return l(e),u(t,`tapper`),new m(()=>(t(e,0),e[Symbol.iterator]()))}var le=n({collectToArray:()=>f,empty:()=>_,filter:()=>v,flatMap:()=>y,forEach:()=>S,forEachAsync:()=>C,getMemoizeDefaultOptions:()=>j,map:()=>w,materialize:()=>O,max:()=>A,memoize:()=>M,min:()=>R,range:()=>z,reduce:()=>V,repeat:()=>U,some:()=>W,tap:()=>G,tapChain:()=>K}),q=Symbol.for(`iterable-linq-utility.IIterableLinq`);function J(e){return new Y(e)}var Y=class{iterable;constructor(e){this.iterable=e}[Symbol.iterator](){return this.iterable[Symbol.iterator]()}collectToArray(){return f(this.iterable)}filter(e){return J(v(this.iterable,e))}flatMap(e){return J(y(this.iterable,e))}forEach(e){return S(this.iterable,e)}forEachAsync(e){return C(this.iterable,e)}map(e){return J(w(this.iterable,e))}materialize(){return J(O(this.iterable))}max(e){return A(this.iterable,e)}memoize(e){return J(M(this.iterable,e))}min(e){return R(this.iterable,e)}reduce(...e){return e.length===1?V(this.iterable,e[0]):V(this.iterable,e[0],e[1])}some(e){return W(this.iterable,e)}tap(e){return J(G(this.iterable,e))}tapChain(e){return J(K(this.iterable,e))}tapChainCreation(e){u(e,`chainCreationTapper`);let t=this;return e(t),t}};Object.defineProperty(Y.prototype,q,{value:!0,enumerable:!1,writable:!1,configurable:!1});function X(){return Y.prototype}function ue(e){return typeof e==`object`&&!!e&&e[q]===!0}function Z(e,t){let n=Object.getOwnPropertyDescriptor(X(),e);Object.defineProperty(X(),e,{value:t,enumerable:!1,writable:n?.writable??!1,configurable:!0})}function Q(e,t){ne(e,`name`),u(t,`implementation`)}function de(e,t){if(Q(e,t),e in J([]))throw Error(`"${e}" already exists on IIterableLinq: use override() to replace it`);Z(e,t)}function fe(e,t){Q(e,t);let n=e;if(!(n!==`constructor`&&Object.prototype.hasOwnProperty.call(X(),n)))throw Error(`"${n}" is not a method of IIterableLinq: use extend() to add it`);Z(n,t)}function pe(){return $(_())}function $(e){return l(e),J(e)}function me(e,t,n){if(typeof t==`number`)return $(z(e,t,n));if(n!==void 0)throw Error(`The "options" parameter must be the second argument when "start" is omitted`);return $(z(e,t))}function he(e,t){return $(U(e,t))}Object.defineProperty(e,"Functions",{enumerable:!0,get:function(){return le}}),e.Unit=b,e.empty=pe,e.extend=de,e.from=$,e.fromRange=me,e.isIterableLinq=ue,e.override=fe,e.repeat=he,e.unit=x});
|