linqx 0.2.1 → 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 +79 -3
- 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
|
@@ -4,7 +4,7 @@ Modern fork of the original [linq](https://github.com/mihaifm/linq) for JavaScri
|
|
|
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
|
|
|
@@ -66,6 +66,18 @@ chunk(size)
|
|
|
66
66
|
index()
|
|
67
67
|
position()
|
|
68
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()
|
|
69
81
|
```
|
|
70
82
|
|
|
71
83
|
---
|
|
@@ -80,7 +92,7 @@ npm install linqx
|
|
|
80
92
|
|
|
81
93
|
# Usage
|
|
82
94
|
|
|
83
|
-
## ES Modules
|
|
95
|
+
## ES Modules
|
|
84
96
|
|
|
85
97
|
```ts
|
|
86
98
|
import Enumerable from "linqx";
|
|
@@ -111,6 +123,15 @@ import Enumerable from "linqx";
|
|
|
111
123
|
|
|
112
124
|
const items: Enumerable.IEnumerable<number> = Enumerable.from([1, 2, 3]);
|
|
113
125
|
```
|
|
126
|
+
|
|
127
|
+
## Tutorial
|
|
128
|
+
|
|
129
|
+
Build the package and run the TypeScript tutorial:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
pnpm tutorial
|
|
133
|
+
```
|
|
134
|
+
|
|
114
135
|
---
|
|
115
136
|
|
|
116
137
|
## New API Examples
|
|
@@ -134,9 +155,54 @@ for (const { prev, item, next } of Enumerable.from([10, 20, 30]).withNeighbors()
|
|
|
134
155
|
}
|
|
135
156
|
|
|
136
157
|
// position
|
|
137
|
-
for (const { index, item, isFirst, isLast } of Enumerable.from(["a", "b", "c"]).position()) {
|
|
158
|
+
for (const { index, item, isFirst, isLast } of Enumerable.from(["a", "b", "c"]).position()) {
|
|
138
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();
|
|
139
199
|
```
|
|
200
|
+
|
|
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.
|
|
205
|
+
|
|
140
206
|
---
|
|
141
207
|
|
|
142
208
|
# Migration from linq
|
|
@@ -148,6 +214,16 @@ Most projects can switch directly:
|
|
|
148
214
|
+import Enumerable from "linqx";
|
|
149
215
|
```
|
|
150
216
|
|
|
217
|
+
The original string Lambda syntax is no longer supported. Pass JavaScript functions instead:
|
|
218
|
+
|
|
219
|
+
```ts
|
|
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");
|
|
225
|
+
```
|
|
226
|
+
|
|
151
227
|
---
|
|
152
228
|
|
|
153
229
|
# Repository
|
|
@@ -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>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an infinite descending arithmetic sequence.
|
|
4
|
+
*
|
|
5
|
+
* @param start The first value; defaults to zero.
|
|
6
|
+
* @param step The amount subtracted after each element; defaults to one.
|
|
7
|
+
* @returns An infinite deferred numeric sequence.
|
|
8
|
+
*/
|
|
9
|
+
export declare function toNegativeInfinity(start?: number, step?: number): IEnumerable<number>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an infinite sequence by repeatedly transforming the previous value.
|
|
4
|
+
*
|
|
5
|
+
* @param seed The first value.
|
|
6
|
+
* @param func Produces the next value from the current value.
|
|
7
|
+
* @returns An infinite deferred sequence beginning with `seed`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function unfold<T>(seed: T, func: (value: T) => T): IEnumerable<T>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,88 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { choice } from './factories/choice.js';
|
|
2
|
+
import { cycle } from './factories/cycle.js';
|
|
3
|
+
import { defer } from './factories/defer.js';
|
|
4
|
+
import { empty } from './factories/empty.js';
|
|
5
|
+
import { from } from './factories/from.js';
|
|
6
|
+
import { generate } from './factories/generate.js';
|
|
7
|
+
import { make } from './factories/make.js';
|
|
8
|
+
import { matches } from './factories/matches.js';
|
|
9
|
+
import { range } from './factories/range.js';
|
|
10
|
+
import { rangeDown } from './factories/range-down.js';
|
|
11
|
+
import { rangeTo } from './factories/range-to.js';
|
|
12
|
+
import { repeat } from './factories/repeat.js';
|
|
13
|
+
import { repeatWithFinalize } from './factories/repeat-with-finalize.js';
|
|
14
|
+
import { toInfinity } from './factories/to-infinity.js';
|
|
15
|
+
import { toNegativeInfinity } from './factories/to-negative-infinity.js';
|
|
16
|
+
import { unfold } from './factories/unfold.js';
|
|
17
|
+
import type { IDictionary as DictionaryInterface, IDisposableEnumerable as DisposableEnumerableInterface, IEnumerable as EnumerableInterface, IEnumerator as EnumeratorInterface, IGrouping as GroupingInterface, ILookup as LookupInterface, IOrderedEnumerable as OrderedEnumerableInterface, IPageInfo as PageInfo, Indexed as IndexedValue, KeyValuePair as Pair, Neighbors as NeighborValues, Positioned as PositionedValue } from './types.js';
|
|
18
|
+
/** Entry point for creating and working with LINQ-style sequences. */
|
|
19
|
+
export declare class Enumerable {
|
|
20
|
+
/** Low-level helpers for creating enumerables and extending iterable prototypes. */
|
|
21
|
+
static readonly Utils: import("./utils.js").EnumerableUtils;
|
|
22
|
+
/** Creates an infinite sequence that randomly chooses from the supplied values. */
|
|
23
|
+
static readonly choice: typeof choice;
|
|
24
|
+
/** Creates an infinite sequence that repeatedly emits the supplied values in order. */
|
|
25
|
+
static readonly cycle: typeof cycle;
|
|
26
|
+
/** Defers sequence creation until each enumeration begins. */
|
|
27
|
+
static readonly defer: typeof defer;
|
|
28
|
+
/** Creates an empty sequence. */
|
|
29
|
+
static readonly empty: typeof empty;
|
|
30
|
+
/** Converts an enumerable source, iterator, array-like value, object, or scalar to a sequence. */
|
|
31
|
+
static readonly from: typeof from;
|
|
32
|
+
/** Generates values by repeatedly invoking a function. */
|
|
33
|
+
static readonly generate: typeof generate;
|
|
34
|
+
/** Creates a sequence containing one element. */
|
|
35
|
+
static readonly make: typeof make;
|
|
36
|
+
/** Enumerates all regular-expression matches in a string. */
|
|
37
|
+
static readonly matches: typeof matches;
|
|
38
|
+
/** Creates a counted numeric sequence. */
|
|
39
|
+
static readonly range: typeof range;
|
|
40
|
+
/** Creates a counted descending numeric sequence. */
|
|
41
|
+
static readonly rangeDown: typeof rangeDown;
|
|
42
|
+
/** Creates an inclusive numeric sequence between two endpoints. */
|
|
43
|
+
static readonly rangeTo: typeof rangeTo;
|
|
44
|
+
/** Repeats an element a specified number of times or indefinitely. */
|
|
45
|
+
static readonly repeat: typeof repeat;
|
|
46
|
+
/** Repeats an initialized resource until enumeration stops, then finalizes it. */
|
|
47
|
+
static readonly repeatWithFinalize: typeof repeatWithFinalize;
|
|
48
|
+
/** Creates an infinite ascending numeric sequence. */
|
|
49
|
+
static readonly toInfinity: typeof toInfinity;
|
|
50
|
+
/** Creates an infinite descending numeric sequence. */
|
|
51
|
+
static readonly toNegativeInfinity: typeof toNegativeInfinity;
|
|
52
|
+
/** Creates an infinite sequence by repeatedly transforming the previous value. */
|
|
53
|
+
static readonly unfold: typeof unfold;
|
|
54
|
+
}
|
|
55
|
+
/** Type contracts exposed through the `Enumerable` namespace. */
|
|
56
|
+
export declare namespace Enumerable {
|
|
57
|
+
/** A composable iterable sequence with LINQ-style query operators. */
|
|
58
|
+
type IEnumerable<T> = EnumerableInterface<T>;
|
|
59
|
+
/** An imperative cursor over a sequence. */
|
|
60
|
+
type IEnumerator<T> = EnumeratorInterface<T>;
|
|
61
|
+
/** A sequence with one or more stable ordering criteria. */
|
|
62
|
+
type IOrderedEnumerable<T> = OrderedEnumerableInterface<T>;
|
|
63
|
+
/** A sequence whose backing iterator can be explicitly released. */
|
|
64
|
+
type IDisposableEnumerable<T> = DisposableEnumerableInterface<T>;
|
|
65
|
+
/** A mutable key-value collection with optional normalized-key comparison. */
|
|
66
|
+
type IDictionary<TKey, TValue> = DictionaryInterface<TKey, TValue>;
|
|
67
|
+
/** A read-only one-to-many mapping. */
|
|
68
|
+
type ILookup<TKey, TElement> = LookupInterface<TKey, TElement>;
|
|
69
|
+
/** A sequence of elements associated with a key. */
|
|
70
|
+
type IGrouping<TKey, TElement> = GroupingInterface<TKey, TElement>;
|
|
71
|
+
/** A one-based page number and page size. */
|
|
72
|
+
type IPageInfo = PageInfo;
|
|
73
|
+
/** A key associated with one value. */
|
|
74
|
+
type KeyValuePair<TKey, TValue> = Pair<TKey, TValue>;
|
|
75
|
+
/** A sequence element paired with its zero-based index. */
|
|
76
|
+
type Indexed<T> = IndexedValue<T>;
|
|
77
|
+
/** A sequence element annotated with index and boundary information. */
|
|
78
|
+
type Positioned<T> = PositionedValue<T>;
|
|
79
|
+
/** A sequence element paired with its immediate neighbors. */
|
|
80
|
+
type Neighbors<T> = NeighborValues<T>;
|
|
81
|
+
/** @deprecated Use {@link Indexed} instead. */
|
|
82
|
+
type IndexedItem<T> = Indexed<T>;
|
|
83
|
+
/** @deprecated Use {@link Positioned} instead. */
|
|
84
|
+
type PositionedItem<T> = Positioned<T>;
|
|
85
|
+
/** @deprecated Use {@link Neighbors} instead. */
|
|
86
|
+
type ItemWithNeighbors<T> = Neighbors<T>;
|
|
87
|
+
}
|
|
3
88
|
export default Enumerable;
|
|
4
|
-
export { Enumerable };
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Comparer } from '../types.js';
|
|
2
|
+
export declare const identity: <T>(value: T) => T;
|
|
3
|
+
export declare function defaultComparer<T>(first: T, second: T): number;
|
|
4
|
+
export declare function reverseComparer<T>(comparer: Comparer<T>): Comparer<T>;
|
|
5
|
+
export declare function isIterable(value: unknown): value is Iterable<unknown>;
|
|
6
|
+
export declare function isArrayLike(value: unknown): value is ArrayLike<unknown>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { IEnumerable, KeyValuePair } from '../types.js';
|
|
2
|
+
export declare function aggregateBy<T, TKey, TAccumulate>(this: IEnumerable<T>, keySelector: (element: T) => TKey, seed: TAccumulate, accumulator: (accumulate: TAccumulate, element: T) => TAccumulate, compareSelector?: (key: TKey) => unknown): IEnumerable<KeyValuePair<TKey, TAccumulate>>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { IEnumerable } from '../types.js';
|
|
2
|
+
export declare function aggregate<T, TAccumulate, TResult>(this: IEnumerable<T>, seedOrFunc: TAccumulate | ((prev: T, current: T) => T), func?: (prev: TAccumulate, current: T) => TAccumulate, resultSelector?: (last: TAccumulate) => TResult): T | TAccumulate | TResult;
|