linqx 0.2.0 → 0.3.2
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 +181 -87
- package/dist/core/dictionary.d.ts +14 -0
- package/dist/core/enumerable.d.ts +9 -0
- package/dist/core/enumerator.d.ts +10 -0
- package/dist/core/grouping.d.ts +11 -0
- package/dist/core/lookup.d.ts +12 -0
- package/dist/core/memoized-enumerable.d.ts +12 -0
- package/dist/core/ordered-enumerable.d.ts +14 -0
- package/dist/core/shared-enumerable.d.ts +10 -0
- package/dist/extensions.d.ts +18 -0
- package/dist/extensions.js +13 -0
- package/dist/factories/choice.d.ts +8 -0
- package/dist/factories/cycle.d.ts +8 -0
- package/dist/factories/defer.d.ts +8 -0
- package/dist/factories/empty.d.ts +3 -0
- package/dist/factories/from.d.ts +46 -0
- package/dist/factories/generate.d.ts +9 -0
- package/dist/factories/make.d.ts +8 -0
- package/dist/factories/matches.d.ts +14 -0
- package/dist/factories/range-down.d.ts +10 -0
- package/dist/factories/range-to.d.ts +12 -0
- package/dist/factories/range.d.ts +10 -0
- package/dist/factories/repeat-with-finalize.d.ts +9 -0
- package/dist/factories/repeat.d.ts +9 -0
- package/dist/factories/to-infinity.d.ts +9 -0
- package/dist/factories/to-negative-infinity.d.ts +9 -0
- package/dist/factories/unfold.d.ts +9 -0
- package/dist/index.d.ts +87 -3
- package/dist/index.js +2 -4
- package/dist/internal/create-enumerable.d.ts +3 -0
- package/dist/internal/functions.d.ts +6 -0
- package/dist/internal/to-iterable.d.ts +2 -0
- package/dist/operators/aggregate-by.d.ts +2 -0
- package/dist/operators/aggregate.d.ts +2 -0
- package/dist/operators/all.d.ts +2 -0
- package/dist/operators/alternate.d.ts +2 -0
- package/dist/operators/any.d.ts +2 -0
- package/dist/operators/append.d.ts +2 -0
- package/dist/operators/as-enumerable.d.ts +2 -0
- package/dist/operators/average.d.ts +2 -0
- package/dist/operators/buffer.d.ts +2 -0
- package/dist/operators/cast.d.ts +2 -0
- package/dist/operators/catch-error.d.ts +2 -0
- package/dist/operators/choose.d.ts +2 -0
- package/dist/operators/chunk.d.ts +2 -0
- package/dist/operators/concat.d.ts +2 -0
- package/dist/operators/contains.d.ts +2 -0
- package/dist/operators/count-by.d.ts +2 -0
- package/dist/operators/count.d.ts +2 -0
- package/dist/operators/create-ordered-enumerable.d.ts +2 -0
- package/dist/operators/default-if-empty.d.ts +2 -0
- package/dist/operators/distinct-by.d.ts +2 -0
- package/dist/operators/distinct-until-changed.d.ts +2 -0
- package/dist/operators/distinct.d.ts +2 -0
- package/dist/operators/do-action.d.ts +3 -0
- package/dist/operators/element-at-or-default.d.ts +2 -0
- package/dist/operators/element-at.d.ts +2 -0
- package/dist/operators/except-by.d.ts +2 -0
- package/dist/operators/except.d.ts +2 -0
- package/dist/operators/finally-action.d.ts +2 -0
- package/dist/operators/first-or-default.d.ts +2 -0
- package/dist/operators/first.d.ts +2 -0
- package/dist/operators/flatten.d.ts +2 -0
- package/dist/operators/for-each.d.ts +3 -0
- package/dist/operators/force.d.ts +2 -0
- package/dist/operators/group-by.d.ts +2 -0
- package/dist/operators/group-join.d.ts +2 -0
- package/dist/operators/index-of.d.ts +2 -0
- package/dist/operators/index.d.ts +2 -0
- package/dist/operators/insert.d.ts +2 -0
- package/dist/operators/intersect-by.d.ts +2 -0
- package/dist/operators/intersect.d.ts +2 -0
- package/dist/operators/is-empty.d.ts +2 -0
- package/dist/operators/join-with.d.ts +2 -0
- package/dist/operators/join.d.ts +2 -0
- package/dist/operators/last-index-of.d.ts +2 -0
- package/dist/operators/last-or-default.d.ts +2 -0
- package/dist/operators/last.d.ts +2 -0
- package/dist/operators/left-join.d.ts +2 -0
- package/dist/operators/let-bind.d.ts +2 -0
- package/dist/operators/log.d.ts +2 -0
- package/dist/operators/map.d.ts +2 -0
- package/dist/operators/max-by.d.ts +2 -0
- package/dist/operators/max.d.ts +2 -0
- package/dist/operators/memoize.d.ts +2 -0
- package/dist/operators/merge.d.ts +2 -0
- package/dist/operators/min-by.d.ts +2 -0
- package/dist/operators/min.d.ts +2 -0
- package/dist/operators/of-type.d.ts +2 -0
- package/dist/operators/operators.d.ts +208 -0
- package/dist/operators/order-by-descending.d.ts +2 -0
- package/dist/operators/order-by.d.ts +2 -0
- package/dist/operators/page.d.ts +2 -0
- package/dist/operators/pairwise.d.ts +2 -0
- package/dist/operators/partition-by.d.ts +2 -0
- package/dist/operators/position.d.ts +2 -0
- package/dist/operators/prepend.d.ts +2 -0
- package/dist/operators/reverse.d.ts +2 -0
- package/dist/operators/right-join.d.ts +2 -0
- package/dist/operators/scan.d.ts +2 -0
- package/dist/operators/select-many.d.ts +2 -0
- package/dist/operators/select.d.ts +2 -0
- package/dist/operators/sequence-equal.d.ts +2 -0
- package/dist/operators/share.d.ts +2 -0
- package/dist/operators/shuffle.d.ts +2 -0
- package/dist/operators/single-or-default.d.ts +2 -0
- package/dist/operators/single.d.ts +2 -0
- package/dist/operators/skip-last.d.ts +2 -0
- package/dist/operators/skip-while.d.ts +2 -0
- package/dist/operators/skip.d.ts +2 -0
- package/dist/operators/sum.d.ts +2 -0
- package/dist/operators/take-except-last.d.ts +2 -0
- package/dist/operators/take-from-last.d.ts +2 -0
- package/dist/operators/take-last.d.ts +2 -0
- package/dist/operators/take-while.d.ts +2 -0
- package/dist/operators/take.d.ts +2 -0
- package/dist/operators/then-by-descending.d.ts +2 -0
- package/dist/operators/then-by.d.ts +2 -0
- package/dist/operators/to-array.d.ts +2 -0
- package/dist/operators/to-dictionary.d.ts +2 -0
- package/dist/operators/to-joined-string.d.ts +2 -0
- package/dist/operators/to-json-string.d.ts +2 -0
- package/dist/operators/to-lookup.d.ts +2 -0
- package/dist/operators/to-map.d.ts +2 -0
- package/dist/operators/to-object.d.ts +2 -0
- package/dist/operators/to-set.d.ts +2 -0
- package/dist/operators/trace.d.ts +2 -0
- package/dist/operators/traverse-breadth-first.d.ts +2 -0
- package/dist/operators/traverse-depth-first.d.ts +2 -0
- package/dist/operators/union-by.d.ts +2 -0
- package/dist/operators/union.d.ts +2 -0
- package/dist/operators/weighted-sample.d.ts +2 -0
- package/dist/operators/where-if.d.ts +2 -0
- package/dist/operators/where.d.ts +2 -0
- package/dist/operators/with-neighbors.d.ts +2 -0
- package/dist/operators/zip.d.ts +2 -0
- package/dist/src-D_Mk3oMP.js +1597 -0
- package/dist/types.d.ts +1154 -0
- package/dist/utils.d.ts +56 -0
- package/package.json +18 -11
- package/dist/linq.d.ts +0 -256
- package/dist/linq.js +0 -3085
- package/dist/linqx.d.ts +0 -36
- package/dist/linqx.js +0 -153
package/README.md
CHANGED
|
@@ -1,151 +1,245 @@
|
|
|
1
1
|
# linqx
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Modern fork of the original [linq](https://github.com/mihaifm/linq) for JavaScript.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
linqx keeps the familiar LINQ-style API while adding modern exports, new utility methods, improved TypeScript support, and active maintenance.
|
|
6
6
|
|
|
7
|
-
Written in
|
|
7
|
+
Written in TypeScript with no runtime dependencies.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
---
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
// C# LINQ - delegate
|
|
13
|
-
Enumerable.Range(1, 10)
|
|
14
|
-
.Where(delegate(int i) { return i % 3 == 0; })
|
|
15
|
-
.Select(delegate(int i) { return i * 10; });
|
|
11
|
+
# Key Differences from linq
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.select(function(i) { return i * 10; });
|
|
21
|
-
```
|
|
13
|
+
## 1. Named Export Added
|
|
14
|
+
|
|
15
|
+
The original package only exposed a default export.
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
// C# LINQ - lambda
|
|
25
|
-
Enumerable.Range(1, 10).Where((i) => i % 3 == 0).Select((i) => i * 10);
|
|
17
|
+
linqx also provides:
|
|
26
18
|
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
```ts
|
|
20
|
+
export { Enumerable };
|
|
29
21
|
```
|
|
30
22
|
|
|
31
|
-
|
|
32
|
-
// C# LINQ - anonymous type
|
|
33
|
-
array.Select((val, i) => new { Value: val, Index: i }());
|
|
23
|
+
This makes extensions, wrappers, and custom integrations cleaner and more flexible for `typescript`.
|
|
34
24
|
|
|
35
|
-
|
|
36
|
-
Enumerable.from(array).select((val, i) => ({ value: val, index: i }));
|
|
37
|
-
```
|
|
25
|
+
Example:
|
|
38
26
|
|
|
39
|
-
|
|
27
|
+
```ts
|
|
28
|
+
// enumerable.extensions.ts
|
|
29
|
+
import { Enumerable } from "linqx";
|
|
40
30
|
|
|
41
|
-
|
|
31
|
+
declare module "linqx" {
|
|
32
|
+
namespace Enumerable {
|
|
33
|
+
export function crossJoin<T>(this: Enumerable.IEnumerable<T>): Enumerable.IEnumerable<{ left: T; right: T; }>;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Enumerable.prototype.crossJoin = function <T>(this: Enumerable.IEnumerable<T>): Enumerable.IEnumerable<{ left: T; right: T; }> {
|
|
38
|
+
return Enumerable.from(crossJoinIterator(this));
|
|
39
|
+
|
|
40
|
+
function* crossJoinIterator(enumerable: Enumerable.IEnumerable<T>): Iterable<{ left: T; right: T; }> {
|
|
41
|
+
for (const item of enumerable) {
|
|
42
|
+
for (const otherItem of enumerable) {
|
|
43
|
+
yield { left: item, right: otherItem };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
```
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
Useful when augmenting prototypes or writing reusable helpers.
|
|
44
51
|
|
|
45
|
-
|
|
52
|
+
---
|
|
46
53
|
|
|
47
|
-
|
|
54
|
+
## 2. Additional APIs
|
|
48
55
|
|
|
49
|
-
|
|
56
|
+
linqx adds practical methods not available in the original package.
|
|
50
57
|
|
|
51
|
-
```js
|
|
52
|
-
import Enumerable from 'linq'
|
|
53
58
|
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
```ts
|
|
60
|
+
whereIf(flag, predicate)
|
|
61
|
+
page(pageNumber, pageSize)
|
|
62
|
+
page({ pageNumber, pageSize })
|
|
63
|
+
joinWith(separator)
|
|
64
|
+
toMap(keySelector, valueSelector)
|
|
65
|
+
chunk(size)
|
|
66
|
+
index()
|
|
67
|
+
position()
|
|
68
|
+
withNeighbors()
|
|
69
|
+
append(element)
|
|
70
|
+
prepend(element)
|
|
71
|
+
skipLast(count)
|
|
72
|
+
takeLast(count)
|
|
73
|
+
distinctBy(keySelector)
|
|
74
|
+
exceptBy(keys, keySelector)
|
|
75
|
+
intersectBy(keys, keySelector)
|
|
76
|
+
unionBy(sequence, keySelector)
|
|
77
|
+
countBy(keySelector)
|
|
78
|
+
aggregateBy(keySelector, seed, accumulator)
|
|
79
|
+
rightJoin(sequence, outerKeySelector, innerKeySelector, resultSelector)
|
|
80
|
+
toSet()
|
|
56
81
|
```
|
|
57
82
|
|
|
58
|
-
|
|
83
|
+
---
|
|
59
84
|
|
|
60
|
-
|
|
61
|
-
|
|
85
|
+
# Installation
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npm install linqx
|
|
62
89
|
```
|
|
63
90
|
|
|
64
|
-
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
# Usage
|
|
94
|
+
|
|
95
|
+
## ES Modules
|
|
65
96
|
|
|
66
|
-
|
|
97
|
+
```ts
|
|
98
|
+
import Enumerable from "linqx";
|
|
67
99
|
|
|
68
|
-
|
|
100
|
+
const result = Enumerable
|
|
101
|
+
.range(1, 10)
|
|
102
|
+
.where(x => x % 3 === 0)
|
|
103
|
+
.select(x => x * 10)
|
|
104
|
+
.toArray();
|
|
105
|
+
```
|
|
69
106
|
|
|
70
|
-
|
|
107
|
+
---
|
|
71
108
|
|
|
72
|
-
|
|
109
|
+
## Named Export
|
|
73
110
|
|
|
74
|
-
```
|
|
75
|
-
|
|
111
|
+
```ts
|
|
112
|
+
import { Enumerable } from "linqx";
|
|
76
113
|
|
|
77
|
-
|
|
78
|
-
console.log(count) // 4
|
|
114
|
+
const values = Enumerable.from([1, 2, 3]);
|
|
79
115
|
```
|
|
80
116
|
|
|
81
|
-
|
|
117
|
+
---
|
|
82
118
|
|
|
83
119
|
## TypeScript
|
|
84
120
|
|
|
85
|
-
|
|
121
|
+
```ts
|
|
122
|
+
import Enumerable from "linqx";
|
|
86
123
|
|
|
87
|
-
|
|
124
|
+
const items: Enumerable.IEnumerable<number> = Enumerable.from([1, 2, 3]);
|
|
125
|
+
```
|
|
88
126
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
127
|
+
## Tutorial
|
|
128
|
+
|
|
129
|
+
Build the package and run the TypeScript tutorial:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
pnpm tutorial
|
|
94
133
|
```
|
|
95
134
|
|
|
96
|
-
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## New API Examples
|
|
97
138
|
|
|
98
139
|
```ts
|
|
99
|
-
|
|
140
|
+
// whereIf
|
|
141
|
+
Enumerable
|
|
142
|
+
.from([1, 2, 3, 4])
|
|
143
|
+
.whereIf(true, x => x > 2)
|
|
144
|
+
.toArray();
|
|
145
|
+
|
|
146
|
+
// chunk
|
|
147
|
+
Enumerable
|
|
148
|
+
.from([1, 2, 3, 4, 5])
|
|
149
|
+
.chunk(2)
|
|
150
|
+
.toArray();
|
|
151
|
+
// result: [[1, 2], [3, 4], [5]]
|
|
152
|
+
|
|
153
|
+
// withNeighbors
|
|
154
|
+
for (const { prev, item, next } of Enumerable.from([10, 20, 30]).withNeighbors()) {
|
|
155
|
+
}
|
|
100
156
|
|
|
101
|
-
|
|
102
|
-
|
|
157
|
+
// position
|
|
158
|
+
for (const { index, item, isFirst, isLast } of Enumerable.from(["a", "b", "c"]).position()) {
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Standard sequence helpers
|
|
162
|
+
Enumerable.from([2, 3]).prepend(1).append(4).toArray();
|
|
163
|
+
// result: [1, 2, 3, 4]
|
|
164
|
+
|
|
165
|
+
Enumerable.from([1, 2, 3, 4]).skipLast(2).toArray();
|
|
166
|
+
// result: [1, 2]
|
|
167
|
+
|
|
168
|
+
Enumerable.from([1, 2, 3, 4]).takeLast(2).toArray();
|
|
169
|
+
// result: [3, 4]
|
|
170
|
+
|
|
171
|
+
// Key-based set operations
|
|
172
|
+
Enumerable
|
|
173
|
+
.from([{ id: 1, name: "first" }, { id: 1, name: "second" }])
|
|
174
|
+
.distinctBy(item => item.id)
|
|
175
|
+
.toArray();
|
|
176
|
+
// result: [{ id: 1, name: "first" }]
|
|
177
|
+
|
|
178
|
+
Enumerable
|
|
179
|
+
.from([{ id: 1 }, { id: 2 }, { id: 3 }])
|
|
180
|
+
.exceptBy([2], item => item.id)
|
|
181
|
+
.toArray();
|
|
182
|
+
// result: [{ id: 1 }, { id: 3 }]
|
|
183
|
+
|
|
184
|
+
// Per-key aggregation
|
|
185
|
+
Enumerable
|
|
186
|
+
.from(["a", "b", "a"])
|
|
187
|
+
.countBy(value => value)
|
|
188
|
+
.toArray();
|
|
189
|
+
// result: [{ key: "a", value: 2 }, { key: "b", value: 1 }]
|
|
190
|
+
|
|
191
|
+
Enumerable
|
|
192
|
+
.from([{ category: "a", amount: 2 }, { category: "a", amount: 3 }])
|
|
193
|
+
.aggregateBy(item => item.category, 0, (sum, item) => sum + item.amount)
|
|
194
|
+
.toArray();
|
|
195
|
+
// result: [{ key: "a", value: 5 }]
|
|
196
|
+
|
|
197
|
+
// Native Set materialization
|
|
198
|
+
Enumerable.from([1, 1, 2]).toSet();
|
|
103
199
|
```
|
|
104
200
|
|
|
105
|
-
|
|
201
|
+
`countBy` and `aggregateBy` return
|
|
202
|
+
`Enumerable.IEnumerable<Enumerable.KeyValuePair<TKey, TValue>>`. Key-based methods accept an
|
|
203
|
+
optional final comparison selector when keys need normalization, such as
|
|
204
|
+
`key => key.toLowerCase()` for case-insensitive string keys.
|
|
106
205
|
|
|
107
|
-
|
|
206
|
+
---
|
|
108
207
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
208
|
+
# Migration from linq
|
|
209
|
+
|
|
210
|
+
Most projects can switch directly:
|
|
112
211
|
|
|
113
|
-
|
|
212
|
+
```diff
|
|
213
|
+
-import Enumerable from "linq";
|
|
214
|
+
+import Enumerable from "linqx";
|
|
114
215
|
```
|
|
115
216
|
|
|
116
|
-
|
|
217
|
+
The original string Lambda syntax is no longer supported. Pass JavaScript functions instead:
|
|
117
218
|
|
|
118
219
|
```ts
|
|
119
|
-
//
|
|
120
|
-
|
|
220
|
+
// supported
|
|
221
|
+
Enumerable.from([1, 2, 3, 4]).where(value => value % 2 === 0);
|
|
222
|
+
|
|
223
|
+
// not supported
|
|
224
|
+
Enumerable.from([1, 2, 3, 4]).where("value => value % 2 === 0");
|
|
121
225
|
```
|
|
122
226
|
|
|
123
|
-
|
|
227
|
+
---
|
|
124
228
|
|
|
125
|
-
|
|
229
|
+
# Repository
|
|
126
230
|
|
|
127
|
-
|
|
231
|
+
https://github.com/huoshan12345/linqx
|
|
128
232
|
|
|
129
|
-
|
|
130
|
-
<script type="module" src="./linq.min.js"></script>
|
|
131
|
-
<script type="module">
|
|
132
|
-
import Enumerable from './linq.min.js'
|
|
133
|
-
Enumerable.from([1, 2, 3]).forEach(x => console.log(x))
|
|
134
|
-
</script>
|
|
135
|
-
```
|
|
233
|
+
---
|
|
136
234
|
|
|
137
|
-
|
|
235
|
+
# Credits
|
|
138
236
|
|
|
139
|
-
|
|
140
|
-
| ---------: | :----------------------------------------- |
|
|
141
|
-
| unpkg | <https://unpkg.com/linq/> |
|
|
142
|
-
| jsDelivr | <https://jsdelivr.com/package/npm/linq> |
|
|
143
|
-
| packd | <https://bundle.run/linq@latest?name=linq> |
|
|
237
|
+
Based on the original work by Yoshifumi Kawai and later linq maintainers.
|
|
144
238
|
|
|
145
|
-
|
|
239
|
+
Independent community fork.
|
|
146
240
|
|
|
147
|
-
|
|
241
|
+
---
|
|
148
242
|
|
|
149
243
|
# License
|
|
150
244
|
|
|
151
|
-
|
|
245
|
+
MIT
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IDictionary, IEnumerable, KeyValuePair } from '../types.js';
|
|
2
|
+
export declare class Dictionary<TKey, TValue> implements IDictionary<TKey, TValue> {
|
|
3
|
+
private readonly compareSelector;
|
|
4
|
+
private readonly entries;
|
|
5
|
+
constructor(compareSelector?: (key: TKey) => unknown);
|
|
6
|
+
add(key: TKey, value: TValue): void;
|
|
7
|
+
get(key: TKey): TValue;
|
|
8
|
+
set(key: TKey, value: TValue): boolean;
|
|
9
|
+
contains(key: TKey): boolean;
|
|
10
|
+
clear(): void;
|
|
11
|
+
remove(key: TKey): void;
|
|
12
|
+
count(): number;
|
|
13
|
+
toEnumerable(): IEnumerable<KeyValuePair<TKey, TValue>>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IEnumerable, IEnumerator } from '../types.js';
|
|
2
|
+
export declare class EnumerableSequence<T> implements Iterable<T> {
|
|
3
|
+
private readonly iteratorFactory;
|
|
4
|
+
constructor(iteratorFactory: () => Iterator<T>);
|
|
5
|
+
[Symbol.iterator](): Iterator<T>;
|
|
6
|
+
getEnumerator(): IEnumerator<T>;
|
|
7
|
+
}
|
|
8
|
+
export interface EnumerableSequence<T> extends IEnumerable<T> {
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IEnumerator } from '../types.js';
|
|
2
|
+
export declare class Enumerator<T> implements IEnumerator<T> {
|
|
3
|
+
private readonly iterator;
|
|
4
|
+
private value;
|
|
5
|
+
private done;
|
|
6
|
+
constructor(iterator: Iterator<T>);
|
|
7
|
+
current(): T;
|
|
8
|
+
moveNext(): boolean;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EnumerableSequence } from './enumerable.js';
|
|
2
|
+
import type { IGrouping } from '../types.js';
|
|
3
|
+
export declare class Grouping<TKey, TElement> extends EnumerableSequence<TElement> {
|
|
4
|
+
private readonly groupKey;
|
|
5
|
+
private readonly source;
|
|
6
|
+
constructor(groupKey: TKey, source: TElement[]);
|
|
7
|
+
key(): TKey;
|
|
8
|
+
getSource(): TElement[];
|
|
9
|
+
}
|
|
10
|
+
export interface Grouping<TKey, TElement> extends IGrouping<TKey, TElement> {
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IEnumerable, ILookup } from '../types.js';
|
|
2
|
+
import { Grouping } from './grouping.js';
|
|
3
|
+
export declare class Lookup<TKey, TElement> implements ILookup<TKey, TElement> {
|
|
4
|
+
private readonly compareSelector;
|
|
5
|
+
private readonly entries;
|
|
6
|
+
constructor(compareSelector?: (key: TKey) => unknown);
|
|
7
|
+
add(key: TKey, element: TElement): void;
|
|
8
|
+
count(): number;
|
|
9
|
+
get(key: TKey): IEnumerable<TElement>;
|
|
10
|
+
contains(key: TKey): boolean;
|
|
11
|
+
toEnumerable(): IEnumerable<Grouping<TKey, TElement>>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IDisposableEnumerable } from '../types.js';
|
|
2
|
+
import { EnumerableSequence } from './enumerable.js';
|
|
3
|
+
export declare class MemoizedEnumerable<T> extends EnumerableSequence<T> {
|
|
4
|
+
private readonly sourceIterator;
|
|
5
|
+
private readonly cache;
|
|
6
|
+
private completed;
|
|
7
|
+
constructor(source: Iterable<T>);
|
|
8
|
+
private nextAt;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
}
|
|
11
|
+
export interface MemoizedEnumerable<T> extends IDisposableEnumerable<T> {
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Comparer, IOrderedEnumerable } from '../types.js';
|
|
2
|
+
import { EnumerableSequence } from './enumerable.js';
|
|
3
|
+
export interface SortCriterion<T> {
|
|
4
|
+
keySelector: (element: T) => unknown;
|
|
5
|
+
comparer: Comparer<unknown>;
|
|
6
|
+
descending: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class OrderedEnumerable<T> extends EnumerableSequence<T> {
|
|
9
|
+
readonly source: Iterable<T>;
|
|
10
|
+
readonly criteria: readonly SortCriterion<T>[];
|
|
11
|
+
constructor(source: Iterable<T>, criteria: readonly SortCriterion<T>[]);
|
|
12
|
+
}
|
|
13
|
+
export interface OrderedEnumerable<T> extends IOrderedEnumerable<T> {
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IDisposableEnumerable } from '../types.js';
|
|
2
|
+
import { EnumerableSequence } from './enumerable.js';
|
|
3
|
+
export declare class SharedEnumerable<T> extends EnumerableSequence<T> {
|
|
4
|
+
private readonly sourceIterator;
|
|
5
|
+
private disposed;
|
|
6
|
+
constructor(source: Iterable<T>);
|
|
7
|
+
dispose(): void;
|
|
8
|
+
}
|
|
9
|
+
export interface SharedEnumerable<T> extends IDisposableEnumerable<T> {
|
|
10
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Enumerable } from '.';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Map<K, V> {
|
|
4
|
+
asEnumerable(): Enumerable.IEnumerable<[K, V]>;
|
|
5
|
+
}
|
|
6
|
+
interface Array<T> {
|
|
7
|
+
asEnumerable(): Enumerable.IEnumerable<T>;
|
|
8
|
+
}
|
|
9
|
+
interface NamedNodeMap {
|
|
10
|
+
asEnumerable(): Enumerable.IEnumerable<Attr>;
|
|
11
|
+
}
|
|
12
|
+
interface NodeList {
|
|
13
|
+
asEnumerable(): Enumerable.IEnumerable<Node>;
|
|
14
|
+
}
|
|
15
|
+
interface HTMLCollection {
|
|
16
|
+
asEnumerable(): Enumerable.IEnumerable<Element>;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { n as e, t } from "./src-D_Mk3oMP.js";
|
|
2
|
+
e(Array.prototype, "asEnumerable", function() {
|
|
3
|
+
return t.from(this);
|
|
4
|
+
}), e(Map.prototype, "asEnumerable", function() {
|
|
5
|
+
return t.from(this);
|
|
6
|
+
}), typeof document < "u" && (e(NamedNodeMap.prototype, "asEnumerable", function() {
|
|
7
|
+
return t.from(this);
|
|
8
|
+
}), e(NodeList.prototype, "asEnumerable", function() {
|
|
9
|
+
return t.from(this);
|
|
10
|
+
}), e(HTMLCollection.prototype, "asEnumerable", function() {
|
|
11
|
+
return t.from(this);
|
|
12
|
+
}));
|
|
13
|
+
//#endregion
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a sequence that randomly selects from a fixed set with replacement.
|
|
4
|
+
*
|
|
5
|
+
* @param values The candidate values.
|
|
6
|
+
* @returns An infinite deferred sequence, or an empty sequence when no values are supplied.
|
|
7
|
+
*/
|
|
8
|
+
export declare function choice<T>(...values: T[]): IEnumerable<T>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a sequence that repeatedly emits a fixed set of values in order.
|
|
4
|
+
*
|
|
5
|
+
* @param values The values in each cycle.
|
|
6
|
+
* @returns An infinite deferred sequence, or an empty sequence when no values are supplied.
|
|
7
|
+
*/
|
|
8
|
+
export declare function cycle<T>(...values: T[]): IEnumerable<T>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Defers creation of a sequence until enumeration begins.
|
|
4
|
+
*
|
|
5
|
+
* @param factory Creates the sequence used by each enumeration.
|
|
6
|
+
* @returns A deferred sequence that invokes `factory` once per enumeration.
|
|
7
|
+
*/
|
|
8
|
+
export declare function defer<T>(factory: () => IEnumerable<T>): IEnumerable<T>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
/** @returns An empty sequence. */
|
|
3
|
+
export declare function from(): IEnumerable<unknown>;
|
|
4
|
+
/**
|
|
5
|
+
* Wraps a number as a single-element sequence.
|
|
6
|
+
*
|
|
7
|
+
* @param source The number to wrap.
|
|
8
|
+
* @returns A sequence containing `source`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function from(source: number): IEnumerable<number>;
|
|
11
|
+
/**
|
|
12
|
+
* Wraps a boolean as a single-element sequence.
|
|
13
|
+
*
|
|
14
|
+
* @param source The boolean to wrap.
|
|
15
|
+
* @returns A sequence containing `source`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function from(source: boolean): IEnumerable<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Enumerates the characters in a string.
|
|
20
|
+
*
|
|
21
|
+
* @param source The string to enumerate.
|
|
22
|
+
* @returns A reusable sequence of Unicode code-point strings.
|
|
23
|
+
*/
|
|
24
|
+
export declare function from(source: string): IEnumerable<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Converts an iterable, iterator, array-like object, or source factory to a linqx sequence.
|
|
27
|
+
*
|
|
28
|
+
* A source factory is called once per enumeration. A bare iterator is forward-only and is not
|
|
29
|
+
* reset between enumerations.
|
|
30
|
+
*
|
|
31
|
+
* @param source The source to adapt or a function that creates one.
|
|
32
|
+
* @returns A sequence over the source values.
|
|
33
|
+
*/
|
|
34
|
+
export declare function from<T>(source: Iterable<T> | Iterator<T> | ArrayLike<T> | (() => Iterable<T> | Iterator<T>)): IEnumerable<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Enumerates an object's own enumerable string-keyed, non-function properties.
|
|
37
|
+
*
|
|
38
|
+
* @param source The object whose properties will be enumerated.
|
|
39
|
+
* @returns A deferred sequence of key-value entries.
|
|
40
|
+
*/
|
|
41
|
+
export declare function from<TKey extends PropertyKey, TValue>(source: Record<TKey, TValue>): IEnumerable<{
|
|
42
|
+
/** The property's key. */
|
|
43
|
+
key: TKey;
|
|
44
|
+
/** The property's value. */
|
|
45
|
+
value: TValue;
|
|
46
|
+
}>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generates elements by repeatedly invoking a function.
|
|
4
|
+
*
|
|
5
|
+
* @param func Produces the next element.
|
|
6
|
+
* @param count The number of elements to produce. Omit it for an infinite sequence.
|
|
7
|
+
* @returns A deferred generated sequence.
|
|
8
|
+
*/
|
|
9
|
+
export declare function generate<T>(func: () => T, count?: number): IEnumerable<T>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a sequence containing exactly one element.
|
|
4
|
+
*
|
|
5
|
+
* @param element The element to contain.
|
|
6
|
+
* @returns A reusable single-element sequence.
|
|
7
|
+
*/
|
|
8
|
+
export declare function make<T>(element: T): IEnumerable<T>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Enumerates every regular-expression match in a string.
|
|
4
|
+
*
|
|
5
|
+
* A cloned expression is made global automatically, so the supplied `RegExp.lastIndex` is not
|
|
6
|
+
* read or modified.
|
|
7
|
+
*
|
|
8
|
+
* @param input The string to search.
|
|
9
|
+
* @param pattern A regular expression or pattern string.
|
|
10
|
+
* @param flags Flags used only when `pattern` is a string; `g` is added when absent.
|
|
11
|
+
* @returns A deferred sequence of regular-expression match arrays.
|
|
12
|
+
* @throws {SyntaxError} When a pattern string or its flags are invalid.
|
|
13
|
+
*/
|
|
14
|
+
export declare function matches<T extends RegExpMatchArray = RegExpMatchArray>(input: string, pattern: RegExp | string, flags?: string): IEnumerable<T>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a counted descending arithmetic sequence.
|
|
4
|
+
*
|
|
5
|
+
* @param start The first value.
|
|
6
|
+
* @param count The number of values; non-positive values produce an empty sequence.
|
|
7
|
+
* @param step The absolute decrement between consecutive values; defaults to one.
|
|
8
|
+
* @returns A deferred descending numeric sequence.
|
|
9
|
+
*/
|
|
10
|
+
export declare function rangeDown(start: number, count: number, step?: number): IEnumerable<number>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an arithmetic sequence between two inclusive endpoints.
|
|
4
|
+
*
|
|
5
|
+
* The direction is inferred from the endpoints and the absolute value of `step` is used.
|
|
6
|
+
*
|
|
7
|
+
* @param start The first value.
|
|
8
|
+
* @param to The inclusive endpoint.
|
|
9
|
+
* @param step The non-zero distance between consecutive values; defaults to one.
|
|
10
|
+
* @returns A deferred numeric sequence.
|
|
11
|
+
*/
|
|
12
|
+
export declare function rangeTo(start: number, to: number, step?: number): IEnumerable<number>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a counted arithmetic sequence.
|
|
4
|
+
*
|
|
5
|
+
* @param start The first value.
|
|
6
|
+
* @param count The number of values; non-positive values produce an empty sequence.
|
|
7
|
+
* @param step The difference between consecutive values; defaults to one.
|
|
8
|
+
* @returns A deferred numeric sequence.
|
|
9
|
+
*/
|
|
10
|
+
export declare function range(start: number, count: number, step?: number): IEnumerable<number>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Initializes one value, repeats it indefinitely, and finalizes it when enumeration stops.
|
|
4
|
+
*
|
|
5
|
+
* @param initializer Creates the value once per enumeration.
|
|
6
|
+
* @param finalizer Releases the value after completion, failure, or early termination.
|
|
7
|
+
* @returns An infinite deferred sequence with deterministic finalization.
|
|
8
|
+
*/
|
|
9
|
+
export declare function repeatWithFinalize<T>(initializer: () => T, finalizer: (element: T) => void): IEnumerable<T>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Repeats one element.
|
|
4
|
+
*
|
|
5
|
+
* @param element The value to repeat.
|
|
6
|
+
* @param count The number of repetitions. Omit it for an infinite sequence.
|
|
7
|
+
* @returns A deferred repeated sequence.
|
|
8
|
+
*/
|
|
9
|
+
export declare function repeat<T>(element: T, count?: number): IEnumerable<T>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an infinite ascending arithmetic sequence.
|
|
4
|
+
*
|
|
5
|
+
* @param start The first value; defaults to zero.
|
|
6
|
+
* @param step The amount added after each element; defaults to one.
|
|
7
|
+
* @returns An infinite deferred numeric sequence.
|
|
8
|
+
*/
|
|
9
|
+
export declare function toInfinity(start?: number, step?: number): IEnumerable<number>;
|