tyneq 1.0.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/LICENSE +21 -0
- package/README.md +319 -0
- package/dist/Lazy.cjs +762 -0
- package/dist/Lazy.cjs.map +1 -0
- package/dist/Lazy.js +691 -0
- package/dist/Lazy.js.map +1 -0
- package/dist/TyneqCachedTerminalOperator.cjs +4950 -0
- package/dist/TyneqCachedTerminalOperator.cjs.map +1 -0
- package/dist/TyneqCachedTerminalOperator.d.cts +724 -0
- package/dist/TyneqCachedTerminalOperator.d.cts.map +1 -0
- package/dist/TyneqCachedTerminalOperator.d.ts +724 -0
- package/dist/TyneqCachedTerminalOperator.d.ts.map +1 -0
- package/dist/TyneqCachedTerminalOperator.js +4741 -0
- package/dist/TyneqCachedTerminalOperator.js.map +1 -0
- package/dist/ValidationBuilder.cjs +80 -0
- package/dist/ValidationBuilder.cjs.map +1 -0
- package/dist/ValidationBuilder.d.cts +319 -0
- package/dist/ValidationBuilder.d.cts.map +1 -0
- package/dist/ValidationBuilder.d.ts +319 -0
- package/dist/ValidationBuilder.d.ts.map +1 -0
- package/dist/ValidationBuilder.js +69 -0
- package/dist/ValidationBuilder.js.map +1 -0
- package/dist/core.d.cts +1393 -0
- package/dist/core.d.cts.map +1 -0
- package/dist/core.d.ts +1393 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/index.cjs +863 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1038 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +1038 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +809 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/index.cjs +24 -0
- package/dist/plugin/index.d.cts +89 -0
- package/dist/plugin/index.d.cts.map +1 -0
- package/dist/plugin/index.d.ts +89 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +2 -0
- package/dist/utility/index.cjs +9 -0
- package/dist/utility/index.d.cts +2 -0
- package/dist/utility/index.d.ts +2 -0
- package/dist/utility/index.js +3 -0
- package/package.json +96 -0
package/dist/core.d.cts
ADDED
|
@@ -0,0 +1,1393 @@
|
|
|
1
|
+
//#region src/core/ordering/BaseEnumerableSorter.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base for multi-key stable sorters used by the ordering infrastructure.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* `computeKeys()` pre-computes sort keys for each element; `compareKeys()` compares by index.
|
|
7
|
+
* Sorters chain together via the `next` field on {@link TyneqEnumerableSorter} to implement
|
|
8
|
+
* multi-key (thenBy) sorting.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
declare abstract class BaseEnumerableSorter<TSource> {
|
|
13
|
+
/** Pre-computes the sort key for each element in `source[0..count-1]`. */
|
|
14
|
+
abstract computeKeys(source: TSource[], count: number): void;
|
|
15
|
+
/** Compares the sort keys at indices `i` and `j`. Returns negative, zero, or positive. */
|
|
16
|
+
abstract compareKeys(i: number, j: number): number;
|
|
17
|
+
/**
|
|
18
|
+
* Returns a stable sorted index map for `source[0..count-1]`.
|
|
19
|
+
*
|
|
20
|
+
* @returns An array of indices sorted by the key order defined by this sorter chain.
|
|
21
|
+
*/
|
|
22
|
+
sort(source: TSource[], count: number): number[];
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/types/utility.d.ts
|
|
26
|
+
/** `T | null` */
|
|
27
|
+
type Nullable<T> = T | null;
|
|
28
|
+
/** `T | undefined` */
|
|
29
|
+
type Maybe<T> = T | undefined;
|
|
30
|
+
/** `T | null | undefined` */
|
|
31
|
+
type Optional<T> = T | null | undefined;
|
|
32
|
+
/** Any object with a `length` property. */
|
|
33
|
+
type HasLength = {
|
|
34
|
+
length: number;
|
|
35
|
+
};
|
|
36
|
+
/** Any function with any number of arguments. */
|
|
37
|
+
type GenericFunction = (...x: never[]) => unknown;
|
|
38
|
+
/** A constructor type that can be instantiated with `new`. */
|
|
39
|
+
type Constructor<TInstance = unknown, TArgs extends readonly any[] = any[]> = new (...args: TArgs) => TInstance;
|
|
40
|
+
/** A type that extracts the instance type from a constructor. */
|
|
41
|
+
type InstanceOf<C> = C extends Constructor<infer TInstance> ? TInstance : never;
|
|
42
|
+
/** A type that prevents inference of `T` in generic functions. */
|
|
43
|
+
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
44
|
+
/** A function that takes arguments of type `TArgs` (tuple) and returns void. */
|
|
45
|
+
type Action<TArgs extends readonly unknown[] = []> = (...args: TArgs) => void;
|
|
46
|
+
/** A function that takes arguments of type `TArgs` (tuple) and returns a boolean. */
|
|
47
|
+
type Predicate<TArgs extends readonly unknown[] = []> = (...args: TArgs) => boolean;
|
|
48
|
+
/** A predicate over a sequence element and its zero-based index. */
|
|
49
|
+
type ItemPredicate<T> = (item: T, index: number) => boolean;
|
|
50
|
+
/** A projection over a sequence element and its zero-based index. */
|
|
51
|
+
type ItemSelector<T, TResult> = (item: T, index: number) => TResult;
|
|
52
|
+
/** A side-effect action over a sequence element and its zero-based index. */
|
|
53
|
+
type ItemAction<T> = (item: T, index: number) => void;
|
|
54
|
+
/** A function that takes arguments of type `TArgs` (tuple) and returns a value of type `TResult`. */
|
|
55
|
+
type Func<TArgs extends readonly unknown[] = [], TResult = unknown> = (...args: TArgs) => TResult;
|
|
56
|
+
/** A method callable on a specific `this` context, returning `TReturn`. */
|
|
57
|
+
type BoundMethod<TThis = unknown, TReturn = unknown> = (this: TThis, ...args: any[]) => TReturn;
|
|
58
|
+
/** A method callable on any `this` context with unknown arguments. */
|
|
59
|
+
type Method = BoundMethod<unknown>;
|
|
60
|
+
/** A factory function that creates an instance of type `TInstance` given arguments of type `TArgs`. */
|
|
61
|
+
type Factory<TInstance = unknown, TArgs extends readonly any[] = any[]> = (...args: TArgs) => TInstance;
|
|
62
|
+
/**
|
|
63
|
+
* Narrows `T` to `U` if `T extends U`; otherwise falls back to `U`.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* Use this when you have a type variable `T` that you know satisfies `U` in context
|
|
67
|
+
* but TypeScript cannot prove it statically. `Assume<T, U>` resolves to `T` when the
|
|
68
|
+
* constraint holds and to `U` as a safe fallback when it does not - avoiding `any`.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* // Generic return type constrained to the concrete key type:
|
|
73
|
+
* type ValueAt<T, K extends keyof T> = Assume<T[K], string>;
|
|
74
|
+
* // T[K] is string -> resolves to T[K] (the specific type is kept)
|
|
75
|
+
* // T[K] is number -> resolves to string (falls back to the bound)
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @group Types
|
|
79
|
+
*/
|
|
80
|
+
type Assume<T, U> = T extends U ? T : U;
|
|
81
|
+
/**
|
|
82
|
+
* Identity type - preserves `T` as-is with no structural transformation.
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* Use `Cast<T>` as an explicit annotation in generic contexts where inference would
|
|
86
|
+
* widen or lose the type, or where you want to document that a type is intentionally
|
|
87
|
+
* passed through unchanged. It is a zero-cost no-op at both compile time and runtime.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* // Annotate a computed property type without changing it:
|
|
92
|
+
* type Passthrough<T> = Cast<{ [K in keyof T]: T[K] }>;
|
|
93
|
+
*
|
|
94
|
+
* // Use as a readable annotation instead of a bare type parameter:
|
|
95
|
+
* function identity<T>(value: Cast<T>): T { return value; }
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @group Types
|
|
99
|
+
*/
|
|
100
|
+
type Cast<T> = T;
|
|
101
|
+
/** A type representing an object with assignable properties. */
|
|
102
|
+
type WithProperties<K extends PropertyKey, V> = { [P in K]?: V } & Record<PropertyKey, unknown>;
|
|
103
|
+
/**
|
|
104
|
+
* Extracts the keys of `T` whose value type extends `Function` (i.e. methods).
|
|
105
|
+
*
|
|
106
|
+
* @group Types
|
|
107
|
+
*/
|
|
108
|
+
type MethodKeys<T> = { [K in keyof T]: T[K] extends ((...args: any[]) => any) ? K : never }[keyof T];
|
|
109
|
+
/**
|
|
110
|
+
* Extracts the keys of `T` whose value type does NOT extend `Function` (i.e. data fields).
|
|
111
|
+
*
|
|
112
|
+
* @group Types
|
|
113
|
+
*/
|
|
114
|
+
type FieldKeys<T> = { [K in keyof T]: T[K] extends ((...args: any[]) => any) ? never : K }[keyof T];
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/types/queryplan.d.ts
|
|
117
|
+
/**
|
|
118
|
+
* Symbol key used to access the {@link QueryPlanNode} on a `TyneqSequence`.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* import { tyneqQueryNode } from "tyneq";
|
|
123
|
+
* const node = seq[tyneqQueryNode]; // QueryPlanNode | null
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @group QueryPlan
|
|
127
|
+
*/
|
|
128
|
+
declare const tyneqQueryNode: unique symbol;
|
|
129
|
+
/**
|
|
130
|
+
* Categories of operators.
|
|
131
|
+
*
|
|
132
|
+
* @remarks
|
|
133
|
+
* String literal types used to classify operator behaviour.
|
|
134
|
+
*
|
|
135
|
+
* @group QueryPlan
|
|
136
|
+
*/
|
|
137
|
+
type OperatorCategory = "source" | "streaming" | "buffer" | "terminal";
|
|
138
|
+
/**
|
|
139
|
+
* The JavaScript collection type that backs a source node.
|
|
140
|
+
*
|
|
141
|
+
* @group QueryPlan
|
|
142
|
+
*/
|
|
143
|
+
type SourceKind = "array" | "set" | "map" | "string" | "other";
|
|
144
|
+
/**
|
|
145
|
+
* A node in the query plan tree representing one operator in a pipeline.
|
|
146
|
+
*
|
|
147
|
+
* @remarks
|
|
148
|
+
* Nodes form a linked list via `source`. The head node has `source === null` and represents the data source.
|
|
149
|
+
*
|
|
150
|
+
* @group QueryPlan
|
|
151
|
+
*/
|
|
152
|
+
interface QueryPlanNode {
|
|
153
|
+
/** The operator name as registered with the registry. */
|
|
154
|
+
readonly operatorName: string;
|
|
155
|
+
/** The arguments passed to the operator. Functions render as `<fn>` in printed output. */
|
|
156
|
+
readonly args: readonly unknown[];
|
|
157
|
+
/** The upstream node, or `null` for source nodes. */
|
|
158
|
+
readonly source: Nullable<QueryPlanNode>;
|
|
159
|
+
/**
|
|
160
|
+
* Operator category describing behaviour (`"source" | "streaming" | "buffer" | "terminal").
|
|
161
|
+
*/
|
|
162
|
+
readonly category: OperatorCategory;
|
|
163
|
+
/**
|
|
164
|
+
* The backing JavaScript collection type for source nodes.
|
|
165
|
+
*
|
|
166
|
+
* @remarks
|
|
167
|
+
* Only meaningful when `category === "source"`. For all other categories this field is
|
|
168
|
+
* `undefined`. Use {@link isSourceNode} to narrow the type before reading this field.
|
|
169
|
+
*/
|
|
170
|
+
readonly sourceKind?: SourceKind;
|
|
171
|
+
/**
|
|
172
|
+
* Accepts a visitor and returns its result.
|
|
173
|
+
*
|
|
174
|
+
* @param visitor - The visitor to invoke.
|
|
175
|
+
*/
|
|
176
|
+
accept<T>(visitor: QueryPlanVisitor<T>): T;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Narrows a `QueryPlanNode` to one that is guaranteed to have a `sourceKind`.
|
|
180
|
+
*
|
|
181
|
+
* @remarks
|
|
182
|
+
* `sourceKind` is only present on source nodes (`category === "source"`). Reading it on any
|
|
183
|
+
* other node returns `undefined`. Use this guard before accessing `node.sourceKind` to get
|
|
184
|
+
* proper type narrowing and avoid ambiguous `undefined`.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* if (isSourceNode(node)) {
|
|
189
|
+
* console.log(node.sourceKind); // "array" | "set" | "map" | "string" | "other"
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @group QueryPlan
|
|
194
|
+
*/
|
|
195
|
+
declare function isSourceNode(node: QueryPlanNode): node is QueryPlanNode & {
|
|
196
|
+
sourceKind: SourceKind;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Traversal direction for {@link QueryPlanWalker}.
|
|
200
|
+
*
|
|
201
|
+
* - `"source-to-terminal"` - visits from the source node up to the terminal (bottom-up).
|
|
202
|
+
* `from` is visited before `where`, `where` before `select`. This is the default.
|
|
203
|
+
* - `"terminal-to-source"` - visits from the terminal node down to the source (top-down).
|
|
204
|
+
* `select` is visited before `where`, `where` before `from`.
|
|
205
|
+
*
|
|
206
|
+
* @group QueryPlan
|
|
207
|
+
*/
|
|
208
|
+
type QueryPlanTraversalDirection = "source-to-terminal" | "terminal-to-source";
|
|
209
|
+
/**
|
|
210
|
+
* Options for {@link QueryPlanWalker}.
|
|
211
|
+
*
|
|
212
|
+
* @group QueryPlan
|
|
213
|
+
*/
|
|
214
|
+
interface QueryPlanWalkerOptions {
|
|
215
|
+
/**
|
|
216
|
+
* Callback invoked by the default `visitNode` implementation for each node.
|
|
217
|
+
* Ignored when `visitNode` is overridden in a subclass without calling `super.visitNode`.
|
|
218
|
+
*/
|
|
219
|
+
callback?: (node: QueryPlanNode) => void;
|
|
220
|
+
/**
|
|
221
|
+
* Traversal direction. Defaults to `"source-to-terminal"`.
|
|
222
|
+
*/
|
|
223
|
+
direction?: QueryPlanTraversalDirection;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Visitor for traversing a query plan tree.
|
|
227
|
+
*
|
|
228
|
+
* @typeParam T - The value produced by visiting a node.
|
|
229
|
+
* @group QueryPlan
|
|
230
|
+
*/
|
|
231
|
+
interface QueryPlanVisitor<T> {
|
|
232
|
+
/** Called for each node during traversal. */
|
|
233
|
+
visit(node: QueryPlanNode): T;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Options for {@link QueryPlanPrinter}.
|
|
237
|
+
*
|
|
238
|
+
* @group QueryPlan
|
|
239
|
+
*/
|
|
240
|
+
interface QueryPlanPrinterOptions {
|
|
241
|
+
/** Indentation string per nesting level. Defaults to `" "` (two spaces). */
|
|
242
|
+
indent?: string;
|
|
243
|
+
/** Arrow string between levels. Defaults to `"->"`. */
|
|
244
|
+
arrow?: string;
|
|
245
|
+
/** Maximum number of array items to render inline. Defaults to `3`. */
|
|
246
|
+
maxInlineArrayItems?: number;
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region src/queryplan/QueryNode.d.ts
|
|
250
|
+
/**
|
|
251
|
+
* Concrete `QueryPlanNode` implementation.
|
|
252
|
+
* One node is created per operator call and linked to its upstream source node,
|
|
253
|
+
* forming a singly-linked list that represents the full query plan.
|
|
254
|
+
*
|
|
255
|
+
* @group QueryPlan
|
|
256
|
+
* @internal
|
|
257
|
+
*/
|
|
258
|
+
declare class QueryNode implements QueryPlanNode {
|
|
259
|
+
readonly operatorName: string;
|
|
260
|
+
readonly args: readonly unknown[];
|
|
261
|
+
readonly source: Nullable<QueryPlanNode>;
|
|
262
|
+
readonly category: OperatorCategory;
|
|
263
|
+
readonly sourceKind?: SourceKind | undefined;
|
|
264
|
+
constructor(operatorName: string, args: readonly unknown[], source: Nullable<QueryPlanNode>, category: OperatorCategory, sourceKind?: SourceKind | undefined);
|
|
265
|
+
accept<T>(visitor: QueryPlanVisitor<T>): T;
|
|
266
|
+
}
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region src/core/TyneqEnumerableCore.d.ts
|
|
269
|
+
/**
|
|
270
|
+
* Abstract base that adds `orderBy`, `orderByDescending`, `memoize`, and `pipe` to a sequence.
|
|
271
|
+
*
|
|
272
|
+
* @remarks
|
|
273
|
+
* All four methods build `QueryNode`s and delegate to abstract factory methods, allowing
|
|
274
|
+
* subclasses to control which concrete sequence types are produced.
|
|
275
|
+
*
|
|
276
|
+
* @internal
|
|
277
|
+
*/
|
|
278
|
+
declare abstract class TyneqEnumerableCore<TSource> {
|
|
279
|
+
abstract readonly [tyneqQueryNode]: Nullable<QueryPlanNode>;
|
|
280
|
+
[Symbol.iterator](): Enumerator<TSource>;
|
|
281
|
+
abstract getEnumerator(): Enumerator<TSource>;
|
|
282
|
+
orderBy<TKey>(keySelector: (item: TSource) => TKey, comparer?: Comparer<TKey>): TyneqOrderedSequence<TSource>;
|
|
283
|
+
orderByDescending<TKey>(keySelector: (item: TSource) => TKey, comparer?: Comparer<TKey>): TyneqOrderedSequence<TSource>;
|
|
284
|
+
memoize(): TyneqCachedSequence<TSource>;
|
|
285
|
+
pipe<TResult>(factory: (source: Iterable<TSource>) => Enumerator<TResult> | IterableIterator<TResult>): TyneqSequence<TResult>;
|
|
286
|
+
/**
|
|
287
|
+
* Helper that creates a new sequence with the provided enumerator factory and query node.
|
|
288
|
+
* @param factory The factory function that produces an enumerator for the new sequence.
|
|
289
|
+
* @param node The query plan node associated with the new sequence.
|
|
290
|
+
* @returns A new TyneqSequence instance.
|
|
291
|
+
*/
|
|
292
|
+
protected createSequence<TResult>(factory: () => Enumerator<TResult>, node: QueryPlanNode): TyneqSequence<TResult>;
|
|
293
|
+
/**
|
|
294
|
+
* Helper for creating a query node with the current sequence's node as its parent.
|
|
295
|
+
* @param name The name of the query node.
|
|
296
|
+
* @param category The category of the operator.
|
|
297
|
+
* @param args The arguments for the query node.
|
|
298
|
+
* @returns A new QueryNode instance.
|
|
299
|
+
*/
|
|
300
|
+
protected createNode(name: string, category: OperatorCategory, args?: unknown[]): QueryNode;
|
|
301
|
+
protected abstract createEnumerable<TResult>(factory: EnumeratorFactory<TResult>, node: Nullable<QueryPlanNode>): TyneqSequence<TResult>;
|
|
302
|
+
protected abstract createOrderedEnumerable<TKey>(keySelector: (x: TSource) => TKey, comparer: Comparer<TKey>, descending: boolean, node: Nullable<QueryPlanNode>): TyneqOrderedSequence<TSource>;
|
|
303
|
+
protected abstract createCachedEnumerable(source: TyneqSequence<TSource>, node: Nullable<QueryPlanNode>): TyneqCachedSequence<TSource>;
|
|
304
|
+
}
|
|
305
|
+
//#endregion
|
|
306
|
+
//#region src/core/TyneqEnumerableBase.d.ts
|
|
307
|
+
/**
|
|
308
|
+
* Abstract base class that implements all {@link TyneqSequence} operator methods.
|
|
309
|
+
*
|
|
310
|
+
* @remarks
|
|
311
|
+
* All operator methods delegate to the corresponding operator class registered via
|
|
312
|
+
* `@operator`, `@terminal`, or the functional registration APIs.
|
|
313
|
+
* Subclasses implement `createEnumerable`, `createOrderedEnumerable`, and `createCachedEnumerable`
|
|
314
|
+
* to control which concrete sequence types are returned.
|
|
315
|
+
*
|
|
316
|
+
* @internal
|
|
317
|
+
*/
|
|
318
|
+
declare abstract class TyneqEnumerableBase<TSource> extends TyneqEnumerableCore<TSource> implements TyneqSequence<TSource> {
|
|
319
|
+
aggregate<UAccumulate, VResult>(seed: UAccumulate, func: (accumulate: UAccumulate, item: TSource) => UAccumulate, resultSelector: (accumulate: UAccumulate) => VResult): VResult;
|
|
320
|
+
all(predicate: ItemPredicate<TSource>): boolean;
|
|
321
|
+
any(predicate: ItemPredicate<TSource>): boolean;
|
|
322
|
+
average(selector: (item: TSource) => number): number;
|
|
323
|
+
consume(): void;
|
|
324
|
+
contains(value: TSource, equalityComparer?: EqualityComparer<TSource>): boolean;
|
|
325
|
+
count(): number;
|
|
326
|
+
countBy(predicate: ItemPredicate<TSource>): number;
|
|
327
|
+
elementAt(index: number): TSource;
|
|
328
|
+
elementAtOrDefault(index: number, defaultValue: TSource): TSource;
|
|
329
|
+
first(predicate: ItemPredicate<TSource>): TSource;
|
|
330
|
+
firstOrDefault(predicate: ItemPredicate<TSource>, defaultValue: TSource): TSource;
|
|
331
|
+
indexOf(predicate: ItemPredicate<TSource>, startIndex?: number): number;
|
|
332
|
+
isNullOrEmpty(): boolean;
|
|
333
|
+
last(predicate: ItemPredicate<TSource>): TSource;
|
|
334
|
+
lastOrDefault(predicate: ItemPredicate<TSource>, defaultValue: TSource): TSource;
|
|
335
|
+
max(comparer?: Comparer<TSource>): TSource;
|
|
336
|
+
maxBy<TKey>(keySelector: (element: TSource) => TKey, comparer?: Comparer<TKey>): TSource;
|
|
337
|
+
min(comparer?: Comparer<TSource>): TSource;
|
|
338
|
+
minBy<TKey>(keySelector: (element: TSource) => TKey, comparer?: Comparer<TKey>): TSource;
|
|
339
|
+
minMax(comparer?: Comparer<TSource>): MinMaxResult<TSource>;
|
|
340
|
+
sequenceEqual(other: Iterable<TSource>, equalityComparer?: EqualityComparer<TSource>): boolean;
|
|
341
|
+
single(predicate: ItemPredicate<TSource>): TSource;
|
|
342
|
+
singleOrDefault(predicate: ItemPredicate<TSource>, defaultValue: TSource): TSource;
|
|
343
|
+
endsWith(sequence: Iterable<TSource>, equalityComparer?: EqualityComparer<TSource>): boolean;
|
|
344
|
+
startsWith(sequence: Iterable<TSource>, equalityComparer?: EqualityComparer<TSource>): boolean;
|
|
345
|
+
sum(selector: (item: TSource) => number): number;
|
|
346
|
+
toArray(): TSource[];
|
|
347
|
+
toAsync(): AsyncIterable<TSource>;
|
|
348
|
+
toMap<TKey, TValue>(selector: (item: TSource) => KeyValuePair<TKey, TValue>): Map<TKey, TValue>;
|
|
349
|
+
toRecord<TKey extends string | number | symbol, TValue>(selector: (item: TSource) => KeyValuePair<TKey, TValue>): Record<TKey, TValue>;
|
|
350
|
+
toSet(): Set<TSource>;
|
|
351
|
+
ofType<U extends TSource>(guard: (value: TSource) => value is U): TyneqSequence<U>;
|
|
352
|
+
append(item: TSource): TyneqSequence<TSource>;
|
|
353
|
+
chunk(size: number): TyneqSequence<TSource[]>;
|
|
354
|
+
concat(other: Iterable<TSource>): TyneqSequence<TSource>;
|
|
355
|
+
defaultIfEmpty(defaultValue: TSource): TyneqSequence<TSource>;
|
|
356
|
+
flatten<TInner>(): TyneqSequence<TInner>;
|
|
357
|
+
pairwise(): TyneqSequence<[TSource, TSource]>;
|
|
358
|
+
populate<TValue>(value: TValue): TyneqSequence<TValue>;
|
|
359
|
+
prepend(item: TSource): TyneqSequence<TSource>;
|
|
360
|
+
scan<TResult>(seed: TResult, accumulator: (acc: TResult, item: TSource) => TResult): TyneqSequence<TResult>;
|
|
361
|
+
select<TResult>(selector: ItemSelector<TSource, TResult>): TyneqSequence<TResult>;
|
|
362
|
+
selectMany<TResult>(selector: (item: TSource) => Iterable<TResult>): TyneqSequence<TResult>;
|
|
363
|
+
window(size: number, step?: number): TyneqSequence<TSource[]>;
|
|
364
|
+
repeat(count: number): TyneqSequence<TSource>;
|
|
365
|
+
skip(count: number): TyneqSequence<TSource>;
|
|
366
|
+
skipLast(count: number): TyneqSequence<TSource>;
|
|
367
|
+
skipUntil(predicate: ItemPredicate<TSource>): TyneqSequence<TSource>;
|
|
368
|
+
skipWhile(predicate: ItemPredicate<TSource>): TyneqSequence<TSource>;
|
|
369
|
+
slice(start: number, end?: number): TyneqSequence<TSource>;
|
|
370
|
+
split(splitOn: (item: TSource) => boolean): TyneqSequence<TSource[]>;
|
|
371
|
+
take(count: number): TyneqSequence<TSource>;
|
|
372
|
+
takeUntil(predicate: ItemPredicate<TSource>): TyneqSequence<TSource>;
|
|
373
|
+
takeWhile(predicate: ItemPredicate<TSource>): TyneqSequence<TSource>;
|
|
374
|
+
tap(action: ItemAction<TSource>): TyneqSequence<TSource>;
|
|
375
|
+
tapIf(action: ItemAction<TSource>, predicate: () => boolean): TyneqSequence<TSource>;
|
|
376
|
+
throttle(count: number): TyneqSequence<TSource>;
|
|
377
|
+
where(predicate: ItemPredicate<TSource>): TyneqSequence<TSource>;
|
|
378
|
+
zip<TOther, TResult>(other: Iterable<TOther>, selector: (first: TSource, second: TOther) => TResult): TyneqSequence<TResult>;
|
|
379
|
+
backsert(index: number, other: Iterable<TSource>): TyneqSequence<TSource>;
|
|
380
|
+
distinct(): TyneqSequence<TSource>;
|
|
381
|
+
distinctBy<TKey>(keySelector: (item: TSource) => TKey): TyneqSequence<TSource>;
|
|
382
|
+
except(excludedValues: Iterable<TSource>): TyneqSequence<TSource>;
|
|
383
|
+
exceptBy<TKey>(excludedKeys: Iterable<TKey>, keySelector: (item: TSource) => TKey): TyneqSequence<TSource>;
|
|
384
|
+
groupBy<TKey, TValue, TResult>(keySelector: (item: TSource) => TKey, valueSelector: (item: TSource) => TValue, resultSelector: (key: TKey, values: TyneqSequence<TValue>) => TResult): TyneqSequence<TResult>;
|
|
385
|
+
groupJoin<TInner, TKey, TResult>(inner: Iterable<TInner>, outerKeySelector: (outer: TSource) => TKey, innerKeySelector: (inner: TInner) => TKey, resultSelector: (outer: TSource, group: TyneqSequence<TInner>) => TResult): TyneqSequence<TResult>;
|
|
386
|
+
intersect(intersectedValues: Iterable<TSource>): TyneqSequence<TSource>;
|
|
387
|
+
intersectBy<TKey>(intersectedKeys: Iterable<TKey>, keySelector: (item: TSource) => TKey): TyneqSequence<TSource>;
|
|
388
|
+
join<TInner, TKey, TResult>(inner: Iterable<TInner>, outerKeySelector: (outer: TSource) => TKey, innerKeySelector: (inner: TInner) => TKey, resultSelector: (outer: TSource, inner: TInner) => TResult): TyneqSequence<TResult>;
|
|
389
|
+
permutations(): TyneqSequence<TSource[]>;
|
|
390
|
+
reverse(): TyneqSequence<TSource>;
|
|
391
|
+
shuffle(): TyneqSequence<TSource>;
|
|
392
|
+
union(otherValues: Iterable<TSource>): TyneqSequence<TSource>;
|
|
393
|
+
unionBy<TKey>(otherValues: Iterable<TSource>, keySelector: (item: TSource) => TKey): TyneqSequence<TSource>;
|
|
394
|
+
}
|
|
395
|
+
//#endregion
|
|
396
|
+
//#region src/core/OperatorMetadata.d.ts
|
|
397
|
+
/**
|
|
398
|
+
* Metadata describing a registered operator.
|
|
399
|
+
*
|
|
400
|
+
* @group Classes
|
|
401
|
+
*/
|
|
402
|
+
declare class OperatorMetadata {
|
|
403
|
+
readonly name: string;
|
|
404
|
+
readonly kind: OperatorKind;
|
|
405
|
+
readonly source: OperatorSource;
|
|
406
|
+
readonly targetClass: Maybe<SequenceConstructor>;
|
|
407
|
+
readonly extensions: Readonly<Record<string, unknown>>;
|
|
408
|
+
constructor(name: string, kind: OperatorKind, source?: OperatorSource, targetClass?: Maybe<SequenceConstructor>, extensions?: Readonly<Record<string, unknown>>);
|
|
409
|
+
/**
|
|
410
|
+
* Creates metadata for a source operator.
|
|
411
|
+
*
|
|
412
|
+
* @remarks
|
|
413
|
+
* `targetClass` is always `undefined` for source operators - they are static
|
|
414
|
+
* factories with no prototype and are never patched onto a class instance.
|
|
415
|
+
*/
|
|
416
|
+
static source(name: string, src?: OperatorSource): OperatorMetadata;
|
|
417
|
+
/** Creates metadata for a streaming operator. Defaults targetClass to TyneqEnumerableBase. */
|
|
418
|
+
static streaming(name: string, targetClass?: SequenceConstructor, source?: OperatorSource, extensions?: Record<string, unknown>): OperatorMetadata;
|
|
419
|
+
/** Creates metadata for a buffering operator. Defaults targetClass to TyneqEnumerableBase. */
|
|
420
|
+
static buffer(name: string, targetClass?: SequenceConstructor, source?: OperatorSource, extensions?: Record<string, unknown>): OperatorMetadata;
|
|
421
|
+
/** Creates metadata for a terminal operator. Defaults targetClass to TyneqEnumerableBase. */
|
|
422
|
+
static terminal(name: string, targetClass?: SequenceConstructor, source?: OperatorSource, extensions?: Record<string, unknown>): OperatorMetadata;
|
|
423
|
+
/**
|
|
424
|
+
* Creates metadata for a streaming or buffer operator determined at runtime.
|
|
425
|
+
*
|
|
426
|
+
* @remarks
|
|
427
|
+
* Use when the category is a variable rather than a compile-time literal --
|
|
428
|
+
* for example in `@operator` and `@orderedOperator` whose `category` parameter
|
|
429
|
+
* is provided by the caller. For compile-time-known categories prefer the
|
|
430
|
+
* dedicated {@link streaming} / {@link buffer} / {@link terminal} statics.
|
|
431
|
+
*
|
|
432
|
+
* Only `"streaming"` and `"buffer"` are valid; passing `"terminal"` or `"source"` throws.
|
|
433
|
+
*/
|
|
434
|
+
static forCategory(category: "streaming" | "buffer", name: string, targetClass?: SequenceConstructor, source?: OperatorSource, extensions?: Record<string, unknown>): OperatorMetadata;
|
|
435
|
+
}
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/types/core.d.ts
|
|
438
|
+
/**
|
|
439
|
+
* A pull-based iterator over a sequence.
|
|
440
|
+
*
|
|
441
|
+
* @remarks
|
|
442
|
+
* Extends the native `Iterator<T>` protocol. `return()` disposes the iterator early;
|
|
443
|
+
* `throw()` is not supported and throws {@link NotSupportedError} if called.
|
|
444
|
+
*
|
|
445
|
+
* @typeParam T - Element type.
|
|
446
|
+
* @group Interfaces
|
|
447
|
+
*/
|
|
448
|
+
interface Enumerator<T> extends Iterator<T> {
|
|
449
|
+
next(): IteratorResult<T>;
|
|
450
|
+
/**
|
|
451
|
+
* Terminates the iterator early and releases resources.
|
|
452
|
+
*
|
|
453
|
+
* @remarks
|
|
454
|
+
* Idempotent - safe to call multiple times. Calling `next()` after `return()` returns `{ done: true }`.
|
|
455
|
+
*/
|
|
456
|
+
return?(value?: unknown): IteratorResult<T>;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* A factory that produces a fresh {@link Enumerator} on demand.
|
|
460
|
+
*
|
|
461
|
+
* @typeParam T - Element type.
|
|
462
|
+
* @group Interfaces
|
|
463
|
+
*/
|
|
464
|
+
interface EnumeratorFactory<T> {
|
|
465
|
+
/** Returns a new, independent enumerator starting at the beginning of the sequence. */
|
|
466
|
+
getEnumerator(): Enumerator<T>;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* A function that compares two values for ordering.
|
|
470
|
+
*
|
|
471
|
+
* @remarks
|
|
472
|
+
* Must return a negative number when `a < b`, a positive number when `a > b`, and `0` when equal.
|
|
473
|
+
* Matches the signature expected by `Array.prototype.sort`.
|
|
474
|
+
*
|
|
475
|
+
* @typeParam T - The type of values being compared.
|
|
476
|
+
* @group Types
|
|
477
|
+
*/
|
|
478
|
+
type Comparer<T> = (a: T, b: T) => number;
|
|
479
|
+
/**
|
|
480
|
+
* A function that tests two values for equality.
|
|
481
|
+
*
|
|
482
|
+
* @typeParam T - The type of values being compared.
|
|
483
|
+
* @group Types
|
|
484
|
+
*/
|
|
485
|
+
type EqualityComparer<T> = (a: T, b: T) => boolean;
|
|
486
|
+
/**
|
|
487
|
+
* A lazy, re-iterable sequence.
|
|
488
|
+
*
|
|
489
|
+
* @remarks
|
|
490
|
+
* Each call to `[Symbol.iterator]()` or `getEnumerator()` produces a fresh enumerator with
|
|
491
|
+
* independent state, allowing the same sequence to be iterated multiple times.
|
|
492
|
+
*
|
|
493
|
+
* @typeParam T - Element type.
|
|
494
|
+
* @group Interfaces
|
|
495
|
+
*/
|
|
496
|
+
interface Enumerable<T> extends Iterable<T>, EnumeratorFactory<T> {
|
|
497
|
+
[Symbol.iterator](): Enumerator<T>;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Function that produces a fresh {@link Enumerator} each time it is called.
|
|
501
|
+
*
|
|
502
|
+
* @group Types
|
|
503
|
+
*/
|
|
504
|
+
type IteratorFactory<T> = () => Enumerator<T>;
|
|
505
|
+
/**
|
|
506
|
+
* Function that wraps an iterator factory in a concrete `TyneqSequence` subclass.
|
|
507
|
+
*
|
|
508
|
+
* @group Types
|
|
509
|
+
* @internal
|
|
510
|
+
*/
|
|
511
|
+
type TyneqEnumerableFactory<TSource, TEnumerable extends TyneqSequence<TSource>> = (iteratorFactory: IteratorFactory<TSource>) => TEnumerable;
|
|
512
|
+
/**
|
|
513
|
+
* The primary public API for a lazy sequence - the type returned by all Tyneq operators.
|
|
514
|
+
*
|
|
515
|
+
* @remarks
|
|
516
|
+
* Every operator method returns a new `TyneqSequence` without consuming the source.
|
|
517
|
+
* The source is not iterated until the returned sequence is iterated.
|
|
518
|
+
*
|
|
519
|
+
* @typeParam TSource - Element type.
|
|
520
|
+
* @group Interfaces
|
|
521
|
+
*/
|
|
522
|
+
interface TyneqSequence<TSource> extends Enumerable<TSource> {
|
|
523
|
+
/**
|
|
524
|
+
* The query plan node for this sequence, or `null` if no plan is available.
|
|
525
|
+
*
|
|
526
|
+
* @remarks
|
|
527
|
+
* Use {@link QueryPlanPrinter} to render this as a string.
|
|
528
|
+
* Sequences created via `pipe()` always have `null` here.
|
|
529
|
+
*/
|
|
530
|
+
readonly [tyneqQueryNode]: Nullable<QueryPlanNode>;
|
|
531
|
+
/**
|
|
532
|
+
* Returns `true` if any element satisfies the predicate.
|
|
533
|
+
*
|
|
534
|
+
* @remarks
|
|
535
|
+
* Returns `false` for an empty sequence.
|
|
536
|
+
* The predicate receives each element and its zero-based index.
|
|
537
|
+
*
|
|
538
|
+
* @throws {ArgumentNullError} When `predicate` is null.
|
|
539
|
+
* @throws {ArgumentError} When `predicate` is undefined.
|
|
540
|
+
*/
|
|
541
|
+
any(predicate: ItemPredicate<TSource>): boolean;
|
|
542
|
+
/**
|
|
543
|
+
* Returns `true` if all elements satisfy the predicate.
|
|
544
|
+
*
|
|
545
|
+
* @remarks
|
|
546
|
+
* Returns `true` for an empty sequence (vacuous truth).
|
|
547
|
+
* The predicate receives each element and its zero-based index.
|
|
548
|
+
*
|
|
549
|
+
* @throws {ArgumentNullError} When `predicate` is null.
|
|
550
|
+
* @throws {ArgumentError} When `predicate` is undefined.
|
|
551
|
+
*/
|
|
552
|
+
all(predicate: ItemPredicate<TSource>): boolean;
|
|
553
|
+
/**
|
|
554
|
+
* Returns `true` if the source sequence contains `value`.
|
|
555
|
+
*
|
|
556
|
+
* @remarks
|
|
557
|
+
* Uses `equalityComparer` for element comparison, or `===` when omitted.
|
|
558
|
+
* Returns `false` for an empty sequence.
|
|
559
|
+
* Enumerates the source until a match is found or the sequence is exhausted.
|
|
560
|
+
*
|
|
561
|
+
* @throws {ArgumentNullError} When `equalityComparer` is null (undefined is allowed).
|
|
562
|
+
*/
|
|
563
|
+
contains(value: TSource, equalityComparer?: EqualityComparer<TSource>): boolean;
|
|
564
|
+
/**
|
|
565
|
+
* Returns the number of elements.
|
|
566
|
+
*
|
|
567
|
+
* @remarks
|
|
568
|
+
* Returns `0` for an empty sequence.
|
|
569
|
+
*/
|
|
570
|
+
count(): number;
|
|
571
|
+
/**
|
|
572
|
+
* Returns the number of elements that satisfy the predicate.
|
|
573
|
+
*
|
|
574
|
+
* @remarks
|
|
575
|
+
* Returns `0` if no elements match or the sequence is empty.
|
|
576
|
+
* The predicate receives each element and its zero-based index.
|
|
577
|
+
*
|
|
578
|
+
* @throws {ArgumentNullError} When `predicate` is null.
|
|
579
|
+
* @throws {ArgumentError} When `predicate` is undefined.
|
|
580
|
+
*/
|
|
581
|
+
countBy(predicate: ItemPredicate<TSource>): number;
|
|
582
|
+
/**
|
|
583
|
+
* Iterates the entire sequence and discards all elements.
|
|
584
|
+
*
|
|
585
|
+
* @remarks
|
|
586
|
+
* Useful for triggering side effects (e.g., after `tap`).
|
|
587
|
+
*/
|
|
588
|
+
consume(): void;
|
|
589
|
+
/**
|
|
590
|
+
* Returns `true` if the sequence is empty or if the first element is `null` or `undefined`.
|
|
591
|
+
*/
|
|
592
|
+
isNullOrEmpty(): boolean;
|
|
593
|
+
/**
|
|
594
|
+
* Returns the element at `index`.
|
|
595
|
+
*
|
|
596
|
+
* @throws {ArgumentError} When `index` is not a safe integer.
|
|
597
|
+
* @throws {ArgumentOutOfRangeError} When `index` is negative or greater than or equal to the sequence length.
|
|
598
|
+
*/
|
|
599
|
+
elementAt(index: number): TSource;
|
|
600
|
+
/**
|
|
601
|
+
* Returns the element at `index`, or `defaultValue` if the index is out of range.
|
|
602
|
+
*
|
|
603
|
+
* @throws {ArgumentError} When `index` is not a safe integer.
|
|
604
|
+
* @throws {ArgumentOutOfRangeError} When `index` is negative.
|
|
605
|
+
*/
|
|
606
|
+
elementAtOrDefault(index: number, defaultValue: TSource): TSource;
|
|
607
|
+
/**
|
|
608
|
+
* Returns the first element that satisfies the predicate.
|
|
609
|
+
*
|
|
610
|
+
* @remarks
|
|
611
|
+
* The predicate receives each element and its zero-based index.
|
|
612
|
+
*
|
|
613
|
+
* @throws {ArgumentNullError} When `predicate` is null.
|
|
614
|
+
* @throws {ArgumentError} When `predicate` is undefined.
|
|
615
|
+
* @throws {InvalidOperationError} When no element satisfies the predicate.
|
|
616
|
+
*/
|
|
617
|
+
first(predicate: ItemPredicate<TSource>): TSource;
|
|
618
|
+
/**
|
|
619
|
+
* Returns the first element that satisfies the predicate, or `defaultValue` if none does.
|
|
620
|
+
*
|
|
621
|
+
* @remarks
|
|
622
|
+
* The predicate receives each element and its zero-based index.
|
|
623
|
+
*
|
|
624
|
+
* @throws {ArgumentNullError} When `predicate` is null.
|
|
625
|
+
* @throws {ArgumentError} When `predicate` is undefined.
|
|
626
|
+
*/
|
|
627
|
+
firstOrDefault(predicate: ItemPredicate<TSource>, defaultValue: TSource): TSource;
|
|
628
|
+
/**
|
|
629
|
+
* Returns the zero-based index of the first element that satisfies the predicate.
|
|
630
|
+
*
|
|
631
|
+
* @remarks
|
|
632
|
+
* Returns `-1` if no element satisfies the predicate.
|
|
633
|
+
* When `startIndex` is provided, the search starts at that index.
|
|
634
|
+
* The predicate receives each element and its zero-based index within the full sequence.
|
|
635
|
+
*
|
|
636
|
+
* @throws {ArgumentNullError} When `predicate` is null.
|
|
637
|
+
* @throws {ArgumentError} When `predicate` is undefined.
|
|
638
|
+
* @throws {ArgumentOutOfRangeError} When `startIndex` is negative.
|
|
639
|
+
*/
|
|
640
|
+
indexOf(predicate: ItemPredicate<TSource>, startIndex?: number): number;
|
|
641
|
+
/**
|
|
642
|
+
* Returns the last element that satisfies the predicate.
|
|
643
|
+
*
|
|
644
|
+
* @remarks
|
|
645
|
+
* The predicate receives each element and its zero-based index.
|
|
646
|
+
*
|
|
647
|
+
* @throws {ArgumentNullError} When `predicate` is null.
|
|
648
|
+
* @throws {ArgumentError} When `predicate` is undefined.
|
|
649
|
+
* @throws {InvalidOperationError} When no element satisfies the predicate.
|
|
650
|
+
*/
|
|
651
|
+
last(predicate: ItemPredicate<TSource>): TSource;
|
|
652
|
+
/**
|
|
653
|
+
* Returns the last element that satisfies the predicate, or `defaultValue` if none does.
|
|
654
|
+
*
|
|
655
|
+
* @remarks
|
|
656
|
+
* The predicate receives each element and its zero-based index.
|
|
657
|
+
*
|
|
658
|
+
* @throws {ArgumentNullError} When `predicate` is null.
|
|
659
|
+
* @throws {ArgumentError} When `predicate` is undefined.
|
|
660
|
+
*/
|
|
661
|
+
lastOrDefault(predicate: ItemPredicate<TSource>, defaultValue: TSource): TSource;
|
|
662
|
+
/**
|
|
663
|
+
* Returns the maximum element according to the comparer.
|
|
664
|
+
*
|
|
665
|
+
* @remarks
|
|
666
|
+
* Uses the natural `>` operator when no comparer is provided.
|
|
667
|
+
*
|
|
668
|
+
* @throws {SequenceContainsNoElementsError} When the sequence is empty.
|
|
669
|
+
*/
|
|
670
|
+
max(comparer?: Comparer<TSource>): TSource;
|
|
671
|
+
/**
|
|
672
|
+
* Returns the element with the maximum key.
|
|
673
|
+
*
|
|
674
|
+
* @throws {SequenceContainsNoElementsError} When the sequence is empty.
|
|
675
|
+
* @throws {ArgumentNullError} When `keySelector` is null.
|
|
676
|
+
* @throws {ArgumentError} When `keySelector` is undefined.
|
|
677
|
+
*/
|
|
678
|
+
maxBy<TKey>(keySelector: (element: TSource) => TKey, comparer?: Comparer<TKey>): TSource;
|
|
679
|
+
/**
|
|
680
|
+
* Returns the minimum element according to the comparer.
|
|
681
|
+
*
|
|
682
|
+
* @remarks
|
|
683
|
+
* Uses the natural `<` operator when no comparer is provided.
|
|
684
|
+
*
|
|
685
|
+
* @throws {SequenceContainsNoElementsError} When the sequence is empty.
|
|
686
|
+
*/
|
|
687
|
+
min(comparer?: Comparer<TSource>): TSource;
|
|
688
|
+
/**
|
|
689
|
+
* Returns the element with the minimum key.
|
|
690
|
+
*
|
|
691
|
+
* @throws {SequenceContainsNoElementsError} When the sequence is empty.
|
|
692
|
+
* @throws {ArgumentNullError} When `keySelector` is null.
|
|
693
|
+
* @throws {ArgumentError} When `keySelector` is undefined.
|
|
694
|
+
*/
|
|
695
|
+
minBy<TKey>(keySelector: (element: TSource) => TKey, comparer?: Comparer<TKey>): TSource;
|
|
696
|
+
/**
|
|
697
|
+
* Returns `true` if this sequence and `other` have the same elements in the same order.
|
|
698
|
+
*
|
|
699
|
+
* @remarks
|
|
700
|
+
* Uses `equalityComparer` for element comparison, or `===` when omitted.
|
|
701
|
+
* Returns `true` if both sequences are empty.
|
|
702
|
+
*/
|
|
703
|
+
sequenceEqual(other: Iterable<TSource>, equalityComparer?: EqualityComparer<TSource>): boolean;
|
|
704
|
+
/**
|
|
705
|
+
* Returns the only element that satisfies the predicate.
|
|
706
|
+
*
|
|
707
|
+
* @remarks
|
|
708
|
+
* The predicate receives each element and its zero-based index.
|
|
709
|
+
*
|
|
710
|
+
* @throws {ArgumentNullError} When `predicate` is null.
|
|
711
|
+
* @throws {ArgumentError} When `predicate` is undefined.
|
|
712
|
+
* @throws {InvalidOperationError} When no element satisfies the predicate, or when more than one does.
|
|
713
|
+
*/
|
|
714
|
+
single(predicate: ItemPredicate<TSource>): TSource;
|
|
715
|
+
/**
|
|
716
|
+
* Returns the only element that satisfies the predicate, or `defaultValue` if none does.
|
|
717
|
+
*
|
|
718
|
+
* @remarks
|
|
719
|
+
* The predicate receives each element and its zero-based index.
|
|
720
|
+
*
|
|
721
|
+
* @throws {ArgumentNullError} When `predicate` is null.
|
|
722
|
+
* @throws {ArgumentError} When `predicate` is undefined.
|
|
723
|
+
* @throws {InvalidOperationError} When more than one element satisfies the predicate.
|
|
724
|
+
*/
|
|
725
|
+
singleOrDefault(predicate: ItemPredicate<TSource>, defaultValue: TSource): TSource;
|
|
726
|
+
/**
|
|
727
|
+
* Returns `true` if this sequence ends with all elements of `sequence` in order.
|
|
728
|
+
*
|
|
729
|
+
* @remarks
|
|
730
|
+
* Uses `equalityComparer` for element comparison, or `===` when omitted.
|
|
731
|
+
* Returns `true` when `sequence` is empty (vacuous truth).
|
|
732
|
+
* Returns `false` when `sequence` is longer than the source.
|
|
733
|
+
*
|
|
734
|
+
* @example
|
|
735
|
+
* ```ts
|
|
736
|
+
* Tyneq.from([1, 2, 3, 4, 5]).endsWith([4, 5]); // true
|
|
737
|
+
* Tyneq.from([1, 2, 3, 4, 5]).endsWith([3, 5]); // false
|
|
738
|
+
* Tyneq.from([1, 2, 3]).endsWith([]); // true
|
|
739
|
+
* Tyneq.from([1, 2]).endsWith([1, 2, 3]); // false
|
|
740
|
+
*
|
|
741
|
+
* // Custom equality
|
|
742
|
+
* Tyneq.from(["A", "B", "C"]).endsWith(
|
|
743
|
+
* ["b", "c"],
|
|
744
|
+
* (a, b) => a.toLowerCase() === b.toLowerCase()
|
|
745
|
+
* ); // true
|
|
746
|
+
* ```
|
|
747
|
+
*
|
|
748
|
+
* @throws {ArgumentNullError} When `sequence` is null.
|
|
749
|
+
* @throws {ArgumentError} When `sequence` is undefined.
|
|
750
|
+
* @throws {ArgumentTypeError} When `sequence` is not iterable.
|
|
751
|
+
* @throws {ArgumentNullError} When `equalityComparer` is null (undefined is allowed).
|
|
752
|
+
*/
|
|
753
|
+
endsWith(sequence: Iterable<TSource>, equalityComparer?: EqualityComparer<TSource>): boolean;
|
|
754
|
+
/**
|
|
755
|
+
* Returns `true` if this sequence starts with all elements of `sequence` in order.
|
|
756
|
+
*
|
|
757
|
+
* @remarks
|
|
758
|
+
* Uses `equalityComparer` for element comparison, or `===` when omitted.
|
|
759
|
+
* Returns `true` when `sequence` is empty (vacuous truth).
|
|
760
|
+
* Returns `false` when `sequence` is longer than the source.
|
|
761
|
+
*
|
|
762
|
+
* @throws {ArgumentNullError} When `sequence` is null.
|
|
763
|
+
* @throws {ArgumentError} When `sequence` is undefined.
|
|
764
|
+
* @throws {ArgumentTypeError} When `sequence` is not iterable.
|
|
765
|
+
* @throws {ArgumentNullError} When `equalityComparer` is null (undefined is allowed).
|
|
766
|
+
*/
|
|
767
|
+
startsWith(sequence: Iterable<TSource>, equalityComparer?: EqualityComparer<TSource>): boolean;
|
|
768
|
+
/**
|
|
769
|
+
* Returns the sum of `selector` applied to each element.
|
|
770
|
+
*
|
|
771
|
+
* @remarks
|
|
772
|
+
* Returns `0` for an empty sequence.
|
|
773
|
+
*
|
|
774
|
+
* @throws {ArgumentNullError} When `selector` is null.
|
|
775
|
+
* @throws {ArgumentError} When `selector` is undefined.
|
|
776
|
+
*/
|
|
777
|
+
sum(selector: (item: TSource) => number): number;
|
|
778
|
+
/**
|
|
779
|
+
* Materializes the sequence into an array.
|
|
780
|
+
*
|
|
781
|
+
* @remarks
|
|
782
|
+
* Returns `[]` for an empty sequence.
|
|
783
|
+
*/
|
|
784
|
+
toArray(): TSource[];
|
|
785
|
+
/**
|
|
786
|
+
* Returns an `AsyncIterable` that iterates this sequence asynchronously.
|
|
787
|
+
*
|
|
788
|
+
* @remarks
|
|
789
|
+
* Deferred - each `for await...of` loop produces a fresh traversal of the source.
|
|
790
|
+
*/
|
|
791
|
+
toAsync(): AsyncIterable<TSource>;
|
|
792
|
+
/**
|
|
793
|
+
* Materializes the sequence into a `Map`.
|
|
794
|
+
*
|
|
795
|
+
* @throws {ArgumentNullError} When `selector` is null.
|
|
796
|
+
* @throws {ArgumentError} When `selector` is undefined.
|
|
797
|
+
*/
|
|
798
|
+
toMap<TKey, TValue>(selector: (item: TSource) => KeyValuePair<TKey, TValue>): Map<TKey, TValue>;
|
|
799
|
+
/**
|
|
800
|
+
* Materializes the sequence into a plain object record.
|
|
801
|
+
*
|
|
802
|
+
* @throws {ArgumentNullError} When `selector` is null.
|
|
803
|
+
* @throws {ArgumentError} When `selector` is undefined.
|
|
804
|
+
*/
|
|
805
|
+
toRecord<TKey extends string | number | symbol, TValue>(selector: (item: TSource) => KeyValuePair<TKey, TValue>): Record<TKey, TValue>;
|
|
806
|
+
/**
|
|
807
|
+
* Materializes the sequence into a `Set`.
|
|
808
|
+
*
|
|
809
|
+
* @remarks
|
|
810
|
+
* Duplicate elements are deduplicated using `Set` identity semantics.
|
|
811
|
+
*/
|
|
812
|
+
toSet(): Set<TSource>;
|
|
813
|
+
/**
|
|
814
|
+
* Returns the arithmetic mean of `selector` applied to each element.
|
|
815
|
+
*
|
|
816
|
+
* @throws {SequenceContainsNoElementsError} When the sequence is empty.
|
|
817
|
+
* @throws {ArgumentNullError} When `selector` is null.
|
|
818
|
+
* @throws {ArgumentError} When `selector` is undefined.
|
|
819
|
+
*/
|
|
820
|
+
average(selector: (item: TSource) => number): number;
|
|
821
|
+
/**
|
|
822
|
+
* Folds the sequence into a single result value.
|
|
823
|
+
*
|
|
824
|
+
* @remarks
|
|
825
|
+
* Applies `func` to each element in order, starting from `seed`. Returns `resultSelector(seed)` for an empty sequence.
|
|
826
|
+
*
|
|
827
|
+
* @throws {ArgumentNullError} When `func` or `resultSelector` is null.
|
|
828
|
+
* @throws {ArgumentError} When `func` or `resultSelector` is undefined.
|
|
829
|
+
*/
|
|
830
|
+
aggregate<UAccumulate, VResult>(seed: UAccumulate, func: (accumulate: UAccumulate, item: TSource) => UAccumulate, resultSelector: (accumulate: UAccumulate) => VResult): VResult;
|
|
831
|
+
/** Returns a new sequence with `item` appended after all source elements. */
|
|
832
|
+
append(item: TSource): TyneqSequence<TSource>;
|
|
833
|
+
/**
|
|
834
|
+
* Partitions the sequence into non-overlapping arrays of length `size`.
|
|
835
|
+
*
|
|
836
|
+
* @remarks
|
|
837
|
+
* The last chunk may be shorter than `size` if the sequence length is not divisible by `size`.
|
|
838
|
+
*
|
|
839
|
+
* @throws {ArgumentError} When `size` is not a safe integer.
|
|
840
|
+
* @throws {ArgumentOutOfRangeError} When `size` is less than or equal to `0`.
|
|
841
|
+
*/
|
|
842
|
+
chunk(size: number): TyneqSequence<TSource[]>;
|
|
843
|
+
/** Returns a new sequence with the elements of `other` appended after the source. */
|
|
844
|
+
concat(other: Iterable<TSource>): TyneqSequence<TSource>;
|
|
845
|
+
/**
|
|
846
|
+
* Returns a sequence that yields `defaultValue` when the source is empty.
|
|
847
|
+
*
|
|
848
|
+
* @remarks
|
|
849
|
+
* Passes source elements through unchanged when the source is non-empty.
|
|
850
|
+
*/
|
|
851
|
+
defaultIfEmpty(defaultValue: TSource): TyneqSequence<TSource>;
|
|
852
|
+
/**
|
|
853
|
+
* Flattens one level of nesting from a sequence of iterables.
|
|
854
|
+
*
|
|
855
|
+
* @remarks
|
|
856
|
+
* Deferred. Each inner iterable is consumed lazily as the outer sequence advances.
|
|
857
|
+
* Returns an empty sequence when the source is empty.
|
|
858
|
+
* Equivalent to `selectMany(x => x)` but without requiring a selector.
|
|
859
|
+
*
|
|
860
|
+
* @example
|
|
861
|
+
* ```ts
|
|
862
|
+
* Tyneq.from([[1, 2], [3, 4], [5]]).flatten().toArray();
|
|
863
|
+
* // [1, 2, 3, 4, 5]
|
|
864
|
+
*
|
|
865
|
+
* Tyneq.from(["hello", "world"]).flatten().toArray();
|
|
866
|
+
* // ["h", "e", "l", "l", "o", "w", "o", "r", "l", "d"]
|
|
867
|
+
* ```
|
|
868
|
+
*/
|
|
869
|
+
flatten<TInner>(this: TyneqSequence<Iterable<TInner>>): TyneqSequence<TInner>;
|
|
870
|
+
/**
|
|
871
|
+
* Returns consecutive overlapping pairs of elements: `[e0,e1]`, `[e1,e2]`, ...
|
|
872
|
+
*
|
|
873
|
+
* @remarks
|
|
874
|
+
* Returns an empty sequence when the source has fewer than two elements.
|
|
875
|
+
*/
|
|
876
|
+
pairwise(): TyneqSequence<[TSource, TSource]>;
|
|
877
|
+
/**
|
|
878
|
+
* Filters elements to those for which `guard` returns `true`, narrowing the type to `U`.
|
|
879
|
+
*
|
|
880
|
+
* @throws {ArgumentNullError} When `guard` is null.
|
|
881
|
+
* @throws {ArgumentError} When `guard` is undefined.
|
|
882
|
+
*/
|
|
883
|
+
ofType<U extends TSource>(guard: (value: TSource) => value is U): TyneqSequence<U>;
|
|
884
|
+
/** Returns a new sequence with `item` prepended before all source elements. */
|
|
885
|
+
prepend(item: TSource): TyneqSequence<TSource>;
|
|
886
|
+
/**
|
|
887
|
+
* Repeats the source sequence `count` times.
|
|
888
|
+
*
|
|
889
|
+
* @remarks
|
|
890
|
+
* Deferred. Re-enumerates the source from the beginning for each repetition.
|
|
891
|
+
* Returns an empty sequence when `count` is `0`.
|
|
892
|
+
*
|
|
893
|
+
* @example
|
|
894
|
+
* ```ts
|
|
895
|
+
* Tyneq.from([1, 2]).repeat(3).toArray();
|
|
896
|
+
* // [1, 2, 1, 2, 1, 2]
|
|
897
|
+
*
|
|
898
|
+
* Tyneq.from([1, 2]).repeat(0).toArray();
|
|
899
|
+
* // []
|
|
900
|
+
* ```
|
|
901
|
+
*
|
|
902
|
+
* @throws {ArgumentOutOfRangeError} When `count` is negative.
|
|
903
|
+
* @throws {ArgumentError} When `count` is not an integer.
|
|
904
|
+
*/
|
|
905
|
+
repeat(count: number): TyneqSequence<TSource>;
|
|
906
|
+
/**
|
|
907
|
+
* Replaces each element with `value`, keeping the same sequence length.
|
|
908
|
+
*
|
|
909
|
+
* @remarks
|
|
910
|
+
* Useful for generating a sequence of a fixed value with a known length derived from the source.
|
|
911
|
+
*/
|
|
912
|
+
populate<TValue>(value: TValue): TyneqSequence<TValue>;
|
|
913
|
+
/**
|
|
914
|
+
* Projects each element through `selector`.
|
|
915
|
+
*
|
|
916
|
+
* @remarks
|
|
917
|
+
* The selector receives each element and its zero-based index.
|
|
918
|
+
*
|
|
919
|
+
* @throws {ArgumentNullError} When `selector` is null.
|
|
920
|
+
* @throws {ArgumentError} When `selector` is undefined.
|
|
921
|
+
*/
|
|
922
|
+
select<TResult>(selector: ItemSelector<TSource, TResult>): TyneqSequence<TResult>;
|
|
923
|
+
/**
|
|
924
|
+
* Projects each element to an iterable and flattens the results into a single sequence.
|
|
925
|
+
*
|
|
926
|
+
* @throws {ArgumentNullError} When `selector` is null.
|
|
927
|
+
* @throws {ArgumentError} When `selector` is undefined.
|
|
928
|
+
*/
|
|
929
|
+
selectMany<TResult>(selector: (item: TSource) => Iterable<TResult>): TyneqSequence<TResult>;
|
|
930
|
+
/**
|
|
931
|
+
* Yields fixed-size windows (sub-arrays) over the source sequence.
|
|
932
|
+
*
|
|
933
|
+
* @remarks
|
|
934
|
+
* Deferred. O(`size`) memory - only the current window is held in memory.
|
|
935
|
+
* When `step` is 1 (the default), windows slide one element at a time (overlapping).
|
|
936
|
+
* When `step` equals `size`, windows are non-overlapping (tumbling).
|
|
937
|
+
* When `step` exceeds `size`, elements between windows are skipped (gaps).
|
|
938
|
+
* Yields no windows when the source has fewer than `size` elements.
|
|
939
|
+
* Each yielded array is a snapshot - mutating it does not affect subsequent windows.
|
|
940
|
+
*
|
|
941
|
+
* @example
|
|
942
|
+
* ```ts
|
|
943
|
+
* // Sliding (default step = 1)
|
|
944
|
+
* Tyneq.range(1, 5).window(3).toArray();
|
|
945
|
+
* // [[1,2,3], [2,3,4], [3,4,5]]
|
|
946
|
+
*
|
|
947
|
+
* // Tumbling (step = size)
|
|
948
|
+
* Tyneq.range(1, 6).window(2, 2).toArray();
|
|
949
|
+
* // [[1,2], [3,4], [5,6]]
|
|
950
|
+
* ```
|
|
951
|
+
*
|
|
952
|
+
* @throws {ArgumentError} When `size` or `step` is not a safe integer.
|
|
953
|
+
* @throws {ArgumentOutOfRangeError} When `size` is less than `1`.
|
|
954
|
+
* @throws {ArgumentOutOfRangeError} When `step` is less than `1`.
|
|
955
|
+
*/
|
|
956
|
+
window(size: number, step?: number): TyneqSequence<TSource[]>;
|
|
957
|
+
/**
|
|
958
|
+
* Skips the first `count` elements.
|
|
959
|
+
*
|
|
960
|
+
* @remarks
|
|
961
|
+
* Returns an empty sequence when `count` exceeds the sequence length.
|
|
962
|
+
* `count` must be non-negative.
|
|
963
|
+
*
|
|
964
|
+
* @throws {ArgumentError} When `count` is not a safe integer.
|
|
965
|
+
* @throws {ArgumentOutOfRangeError} When `count` is negative.
|
|
966
|
+
*/
|
|
967
|
+
skip(count: number): TyneqSequence<TSource>;
|
|
968
|
+
/**
|
|
969
|
+
* Skips the last `count` elements.
|
|
970
|
+
*
|
|
971
|
+
* @remarks
|
|
972
|
+
* Buffers `count` elements to determine the cutoff.
|
|
973
|
+
*
|
|
974
|
+
* @throws {ArgumentError} When `count` is not a safe integer.
|
|
975
|
+
* @throws {ArgumentOutOfRangeError} When `count` is negative.
|
|
976
|
+
*/
|
|
977
|
+
skipLast(count: number): TyneqSequence<TSource>;
|
|
978
|
+
/**
|
|
979
|
+
* Skips elements until `predicate` returns `true`, then yields all remaining elements
|
|
980
|
+
* including the one that triggered the predicate.
|
|
981
|
+
*
|
|
982
|
+
* @remarks
|
|
983
|
+
* The predicate receives each element and its zero-based index.
|
|
984
|
+
* Once the predicate returns `true` it is never called again.
|
|
985
|
+
*
|
|
986
|
+
* @throws {ArgumentNullError} When `predicate` is null.
|
|
987
|
+
* @throws {ArgumentError} When `predicate` is undefined.
|
|
988
|
+
*/
|
|
989
|
+
skipUntil(predicate: ItemPredicate<TSource>): TyneqSequence<TSource>;
|
|
990
|
+
/**
|
|
991
|
+
* Skips elements while `predicate` returns `true`, then yields the rest.
|
|
992
|
+
*
|
|
993
|
+
* @remarks
|
|
994
|
+
* The predicate receives each element and its zero-based index.
|
|
995
|
+
*
|
|
996
|
+
* @throws {ArgumentNullError} When `predicate` is null.
|
|
997
|
+
* @throws {ArgumentError} When `predicate` is undefined.
|
|
998
|
+
*/
|
|
999
|
+
skipWhile(predicate: ItemPredicate<TSource>): TyneqSequence<TSource>;
|
|
1000
|
+
/**
|
|
1001
|
+
* Yields elements between `start` (inclusive) and `end` (exclusive) by index.
|
|
1002
|
+
*
|
|
1003
|
+
* @remarks
|
|
1004
|
+
* Deferred. Enumerates only as far as `end`.
|
|
1005
|
+
* When `end` is omitted, yields all elements from `start` to the end of the sequence.
|
|
1006
|
+
* Returns an empty sequence when `start` is beyond the sequence length.
|
|
1007
|
+
*
|
|
1008
|
+
* @example
|
|
1009
|
+
* ```ts
|
|
1010
|
+
* Tyneq.from([0, 1, 2, 3, 4]).slice(1, 4).toArray();
|
|
1011
|
+
* // [1, 2, 3]
|
|
1012
|
+
*
|
|
1013
|
+
* Tyneq.from([0, 1, 2, 3, 4]).slice(2).toArray();
|
|
1014
|
+
* // [2, 3, 4]
|
|
1015
|
+
* ```
|
|
1016
|
+
*
|
|
1017
|
+
* @throws {ArgumentOutOfRangeError} When `start` is negative.
|
|
1018
|
+
* @throws {ArgumentOutOfRangeError} When `end` is negative or less than `start`.
|
|
1019
|
+
*/
|
|
1020
|
+
slice(start: number, end?: number): TyneqSequence<TSource>;
|
|
1021
|
+
/**
|
|
1022
|
+
* Splits the sequence at elements where `splitOn` returns `true`.
|
|
1023
|
+
*
|
|
1024
|
+
* @remarks
|
|
1025
|
+
* The delimiter elements are consumed and not included in any sub-array.
|
|
1026
|
+
*
|
|
1027
|
+
* @throws {ArgumentNullError} When `splitOn` is null.
|
|
1028
|
+
* @throws {ArgumentError} When `splitOn` is undefined.
|
|
1029
|
+
*/
|
|
1030
|
+
split(splitOn: (item: TSource) => boolean): TyneqSequence<TSource[]>;
|
|
1031
|
+
/**
|
|
1032
|
+
* Takes at most the first `count` elements.
|
|
1033
|
+
*
|
|
1034
|
+
* @throws {ArgumentError} When `count` is not a safe integer.
|
|
1035
|
+
* @throws {ArgumentOutOfRangeError} When `count` is negative.
|
|
1036
|
+
*/
|
|
1037
|
+
take(count: number): TyneqSequence<TSource>;
|
|
1038
|
+
/**
|
|
1039
|
+
* Yields elements until `predicate` returns `true`, then stops.
|
|
1040
|
+
* The element that triggered the predicate is not included.
|
|
1041
|
+
*
|
|
1042
|
+
* @remarks
|
|
1043
|
+
* The predicate receives each element and its zero-based index.
|
|
1044
|
+
* Once the predicate returns `true` the sequence ends immediately.
|
|
1045
|
+
*
|
|
1046
|
+
* @throws {ArgumentNullError} When `predicate` is null.
|
|
1047
|
+
* @throws {ArgumentError} When `predicate` is undefined.
|
|
1048
|
+
*/
|
|
1049
|
+
takeUntil(predicate: ItemPredicate<TSource>): TyneqSequence<TSource>;
|
|
1050
|
+
/**
|
|
1051
|
+
* Takes elements while `predicate` returns `true`, then stops.
|
|
1052
|
+
*
|
|
1053
|
+
* @remarks
|
|
1054
|
+
* The predicate receives each element and its zero-based index.
|
|
1055
|
+
*
|
|
1056
|
+
* @throws {ArgumentNullError} When `predicate` is null.
|
|
1057
|
+
* @throws {ArgumentError} When `predicate` is undefined.
|
|
1058
|
+
*/
|
|
1059
|
+
takeWhile(predicate: ItemPredicate<TSource>): TyneqSequence<TSource>;
|
|
1060
|
+
/**
|
|
1061
|
+
* Executes `action` for each element as it passes through the pipeline, then yields it unchanged.
|
|
1062
|
+
*
|
|
1063
|
+
* @remarks
|
|
1064
|
+
* The action receives each element and its zero-based index.
|
|
1065
|
+
*
|
|
1066
|
+
* @throws {ArgumentNullError} When `action` is null.
|
|
1067
|
+
* @throws {ArgumentError} When `action` is undefined.
|
|
1068
|
+
*/
|
|
1069
|
+
tap(action: ItemAction<TSource>): TyneqSequence<TSource>;
|
|
1070
|
+
/**
|
|
1071
|
+
* Executes `action` for each element only while `predicate()` returns `true`.
|
|
1072
|
+
*
|
|
1073
|
+
* @remarks
|
|
1074
|
+
* The action receives each element and its zero-based index.
|
|
1075
|
+
*
|
|
1076
|
+
* @throws {ArgumentNullError} When `action` or `predicate` is null.
|
|
1077
|
+
* @throws {ArgumentError} When `action` or `predicate` is undefined.
|
|
1078
|
+
*/
|
|
1079
|
+
tapIf(action: ItemAction<TSource>, predicate: () => boolean): TyneqSequence<TSource>;
|
|
1080
|
+
/**
|
|
1081
|
+
* Yields every `count`-th element (i.e. elements at indices 0, `count`, `2*count`, ...).
|
|
1082
|
+
*
|
|
1083
|
+
* @throws {ArgumentError} When `count` is not a safe integer.
|
|
1084
|
+
* @throws {ArgumentOutOfRangeError} When `count` is less than or equal to `0`.
|
|
1085
|
+
*/
|
|
1086
|
+
throttle(count: number): TyneqSequence<TSource>;
|
|
1087
|
+
/**
|
|
1088
|
+
* Yields only elements for which `predicate` returns `true`.
|
|
1089
|
+
*
|
|
1090
|
+
* @remarks
|
|
1091
|
+
* The predicate receives each element and its zero-based index.
|
|
1092
|
+
*
|
|
1093
|
+
* @throws {ArgumentNullError} When `predicate` is null.
|
|
1094
|
+
* @throws {ArgumentError} When `predicate` is undefined.
|
|
1095
|
+
*/
|
|
1096
|
+
where(predicate: ItemPredicate<TSource>): TyneqSequence<TSource>;
|
|
1097
|
+
/**
|
|
1098
|
+
* Pairs each element with the corresponding element from `other` using `selector`.
|
|
1099
|
+
*
|
|
1100
|
+
* @remarks
|
|
1101
|
+
* Stops at the shorter of the two sequences.
|
|
1102
|
+
*
|
|
1103
|
+
* @throws {ArgumentNullError} When `other` or `selector` is null.
|
|
1104
|
+
* @throws {ArgumentError} When `other` or `selector` is undefined.
|
|
1105
|
+
* @throws {ArgumentTypeError} When `other` is not iterable.
|
|
1106
|
+
*/
|
|
1107
|
+
zip<TOther, TResult>(other: Iterable<TOther>, selector: (first: TSource, second: TOther) => TResult): TyneqSequence<TResult>;
|
|
1108
|
+
/** Returns the sequence without duplicate elements, using SameValueZero (Set) equality. */
|
|
1109
|
+
distinct(): TyneqSequence<TSource>;
|
|
1110
|
+
/**
|
|
1111
|
+
* Returns the sequence without duplicate elements, comparing by the result of `keySelector`.
|
|
1112
|
+
*
|
|
1113
|
+
* @throws {ArgumentNullError} When `keySelector` is null.
|
|
1114
|
+
* @throws {ArgumentError} When `keySelector` is undefined.
|
|
1115
|
+
*/
|
|
1116
|
+
distinctBy<TKey>(keySelector: (item: TSource) => TKey): TyneqSequence<TSource>;
|
|
1117
|
+
/** Returns elements not present in `excludedValues`, using SameValueZero (Set) equality. */
|
|
1118
|
+
except(excludedValues: Iterable<TSource>): TyneqSequence<TSource>;
|
|
1119
|
+
/**
|
|
1120
|
+
* Returns elements whose key (via `keySelector`) is not found in `excludedKeys`.
|
|
1121
|
+
*
|
|
1122
|
+
* @throws {ArgumentNullError} When `keySelector` is null.
|
|
1123
|
+
* @throws {ArgumentError} When `keySelector` is undefined.
|
|
1124
|
+
*/
|
|
1125
|
+
exceptBy<TKey>(excludedKeys: Iterable<TKey>, keySelector: (item: TSource) => TKey): TyneqSequence<TSource>;
|
|
1126
|
+
/**
|
|
1127
|
+
* Groups elements by key and projects each group with `resultSelector`.
|
|
1128
|
+
*
|
|
1129
|
+
* @throws {ArgumentNullError} When `keySelector`, `valueSelector`, or `resultSelector` is null.
|
|
1130
|
+
* @throws {ArgumentError} When `keySelector`, `valueSelector`, or `resultSelector` is undefined.
|
|
1131
|
+
*/
|
|
1132
|
+
groupBy<TKey, TValue, TResult>(keySelector: (item: TSource) => TKey, valueSelector: (item: TSource) => TValue, resultSelector: (key: TKey, values: TyneqSequence<TValue>) => TResult): TyneqSequence<TResult>;
|
|
1133
|
+
/**
|
|
1134
|
+
* Performs a left outer join: each outer element is paired with its matching inner group.
|
|
1135
|
+
*
|
|
1136
|
+
* @remarks
|
|
1137
|
+
* Elements with no match in `inner` receive an empty group.
|
|
1138
|
+
*
|
|
1139
|
+
* @throws {ArgumentNullError} When any selector is null.
|
|
1140
|
+
* @throws {ArgumentError} When any selector is undefined.
|
|
1141
|
+
* @throws {ArgumentTypeError} When `inner` is not iterable.
|
|
1142
|
+
*/
|
|
1143
|
+
groupJoin<TInner, TKey, TResult>(inner: Iterable<TInner>, outerKeySelector: (outer: TSource) => TKey, innerKeySelector: (inner: TInner) => TKey, resultSelector: (outer: TSource, group: TyneqSequence<TInner>) => TResult): TyneqSequence<TResult>;
|
|
1144
|
+
/** Returns elements that are also present in `intersectedValues`, using SameValueZero (Set) equality. */
|
|
1145
|
+
intersect(intersectedValues: Iterable<TSource>): TyneqSequence<TSource>;
|
|
1146
|
+
/**
|
|
1147
|
+
* Returns elements whose key (via `keySelector`) is found in `intersectedKeys`.
|
|
1148
|
+
*
|
|
1149
|
+
* @throws {ArgumentNullError} When `keySelector` is null.
|
|
1150
|
+
* @throws {ArgumentError} When `keySelector` is undefined.
|
|
1151
|
+
*/
|
|
1152
|
+
intersectBy<TKey>(intersectedKeys: Iterable<TKey>, keySelector: (item: TSource) => TKey): TyneqSequence<TSource>;
|
|
1153
|
+
/**
|
|
1154
|
+
* Performs an inner join: produces one result for each matching pair of outer and inner elements.
|
|
1155
|
+
*
|
|
1156
|
+
* @throws {ArgumentNullError} When any selector is null.
|
|
1157
|
+
* @throws {ArgumentError} When any selector is undefined.
|
|
1158
|
+
*/
|
|
1159
|
+
join<TInner, TKey, TResult>(inner: Iterable<TInner>, outerKeySelector: (outer: TSource) => TKey, innerKeySelector: (inner: TInner) => TKey, resultSelector: (outer: TSource, inner: TInner) => TResult): TyneqSequence<TResult>;
|
|
1160
|
+
/**
|
|
1161
|
+
* Returns a sequence that caches elements incrementally as they are iterated.
|
|
1162
|
+
*
|
|
1163
|
+
* @remarks
|
|
1164
|
+
* Subsequent iterations replay the cache; the source is only iterated once.
|
|
1165
|
+
* Call `refresh()` on the returned sequence to clear the cache and re-enumerate the source.
|
|
1166
|
+
*/
|
|
1167
|
+
memoize(): TyneqCachedSequence<TSource>;
|
|
1168
|
+
/**
|
|
1169
|
+
* Returns the sequence sorted in ascending order by `keySelector`.
|
|
1170
|
+
*
|
|
1171
|
+
* @remarks
|
|
1172
|
+
* Stable sort. Append `thenBy`/`thenByDescending` for multi-key sorting.
|
|
1173
|
+
*
|
|
1174
|
+
* @throws {ArgumentNullError} When `keySelector` is null.
|
|
1175
|
+
* @throws {ArgumentError} When `keySelector` is undefined.
|
|
1176
|
+
*/
|
|
1177
|
+
orderBy<TKey>(keySelector: (item: TSource) => TKey, comparer?: Comparer<TKey>): TyneqOrderedSequence<TSource>;
|
|
1178
|
+
/**
|
|
1179
|
+
* Returns the sequence sorted in descending order by `keySelector`.
|
|
1180
|
+
*
|
|
1181
|
+
* @remarks
|
|
1182
|
+
* Stable sort. Append `thenBy`/`thenByDescending` for multi-key sorting.
|
|
1183
|
+
*
|
|
1184
|
+
* @throws {ArgumentNullError} When `keySelector` is null.
|
|
1185
|
+
* @throws {ArgumentError} When `keySelector` is undefined.
|
|
1186
|
+
*/
|
|
1187
|
+
orderByDescending<TKey>(keySelector: (item: TSource) => TKey, comparer?: Comparer<TKey>): TyneqOrderedSequence<TSource>;
|
|
1188
|
+
/**
|
|
1189
|
+
* Returns all possible permutations of the sequence.
|
|
1190
|
+
*
|
|
1191
|
+
* @remarks
|
|
1192
|
+
* O(n!) time and O(n) auxiliary memory. Use only on short sequences.
|
|
1193
|
+
* For a sequence of length n, produces n! result arrays, each of length n.
|
|
1194
|
+
*/
|
|
1195
|
+
permutations(): TyneqSequence<TSource[]>;
|
|
1196
|
+
/** Returns the sequence in reverse order. */
|
|
1197
|
+
reverse(): TyneqSequence<TSource>;
|
|
1198
|
+
/**
|
|
1199
|
+
* Returns the sequence in random order using `Math.random()`.
|
|
1200
|
+
*
|
|
1201
|
+
* @remarks
|
|
1202
|
+
* Uses the Fisher-Yates shuffle. Not cryptographically secure.
|
|
1203
|
+
*/
|
|
1204
|
+
shuffle(): TyneqSequence<TSource>;
|
|
1205
|
+
/**
|
|
1206
|
+
* Inserts elements from `other` into the sequence at `index`.
|
|
1207
|
+
*
|
|
1208
|
+
* @remarks
|
|
1209
|
+
* `index` is zero-based and counts from the end of the sequence.
|
|
1210
|
+
* Use `0` to append after the last element, `1` to insert before the last element.
|
|
1211
|
+
*
|
|
1212
|
+
* @example
|
|
1213
|
+
* ```ts
|
|
1214
|
+
* Tyneq.from([1, 2, 3]).backsert(0, [4, 5]).toArray();
|
|
1215
|
+
* // [1, 2, 3, 4, 5] (appended)
|
|
1216
|
+
*
|
|
1217
|
+
* Tyneq.from([1, 2, 3]).backsert(1, [99]).toArray();
|
|
1218
|
+
* // [1, 2, 99, 3] (inserted before the last element)
|
|
1219
|
+
* ```
|
|
1220
|
+
*
|
|
1221
|
+
* @throws {ArgumentOutOfRangeError} When `index` is negative.
|
|
1222
|
+
*/
|
|
1223
|
+
backsert(index: number, other: Iterable<TSource>): TyneqSequence<TSource>;
|
|
1224
|
+
/** Returns the distinct elements from both this sequence and `otherValues`, using SameValueZero (Set) equality. */
|
|
1225
|
+
union(otherValues: Iterable<TSource>): TyneqSequence<TSource>;
|
|
1226
|
+
/**
|
|
1227
|
+
* Returns the elements from both sequences whose keys are distinct.
|
|
1228
|
+
*
|
|
1229
|
+
* @throws {ArgumentNullError} When `keySelector` is null.
|
|
1230
|
+
* @throws {ArgumentError} When `keySelector` is undefined.
|
|
1231
|
+
*/
|
|
1232
|
+
unionBy<TKey>(otherValues: Iterable<TSource>, keySelector: (item: TSource) => TKey): TyneqSequence<TSource>;
|
|
1233
|
+
/**
|
|
1234
|
+
* Passes this sequence through a custom `factory` function and wraps the result.
|
|
1235
|
+
*
|
|
1236
|
+
* @remarks
|
|
1237
|
+
* The returned sequence tracks a `"pipe"` node in the query plan, with `factory` recorded
|
|
1238
|
+
* as the argument. Use this for one-off operator compositions that do not need to be
|
|
1239
|
+
* registered via the plugin API.
|
|
1240
|
+
*
|
|
1241
|
+
* @throws {ArgumentNullError} When `factory` is null.
|
|
1242
|
+
* @throws {ArgumentError} When `factory` is undefined.
|
|
1243
|
+
*/
|
|
1244
|
+
pipe<TResult>(factory: (source: Iterable<TSource>) => Enumerator<TResult> | IterableIterator<TResult>): TyneqSequence<TResult>;
|
|
1245
|
+
/**
|
|
1246
|
+
* Returns a sequence of running aggregates.
|
|
1247
|
+
*
|
|
1248
|
+
* @remarks
|
|
1249
|
+
* The first element of the output is `accumulator(seed, source[0])`. Returns an empty sequence when the source is empty.
|
|
1250
|
+
*
|
|
1251
|
+
* @throws {ArgumentNullError} When `accumulator` is null.
|
|
1252
|
+
* @throws {ArgumentError} When `accumulator` is undefined.
|
|
1253
|
+
*/
|
|
1254
|
+
scan<TResult>(seed: TResult, accumulator: (acc: TResult, item: TSource) => TResult): TyneqSequence<TResult>;
|
|
1255
|
+
/**
|
|
1256
|
+
* Returns the minimum and maximum element in one pass.
|
|
1257
|
+
*
|
|
1258
|
+
* @remarks
|
|
1259
|
+
* Uses the natural `<` / `>` operators when no comparer is provided.
|
|
1260
|
+
*
|
|
1261
|
+
* @throws {SequenceContainsNoElementsError} When the sequence is empty.
|
|
1262
|
+
*/
|
|
1263
|
+
minMax(comparer?: Comparer<TSource>): MinMaxResult<TSource>;
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* A `TyneqSequence` with additional secondary sort keys applied.
|
|
1267
|
+
*
|
|
1268
|
+
* @remarks
|
|
1269
|
+
* Produced by `orderBy` / `orderByDescending`. Chain `thenBy` / `thenByDescending` to add secondary sort criteria.
|
|
1270
|
+
*
|
|
1271
|
+
* @typeParam TSource - Element type.
|
|
1272
|
+
* @group Interfaces
|
|
1273
|
+
*/
|
|
1274
|
+
interface TyneqOrderedSequence<TSource> extends TyneqSequence<TSource> {
|
|
1275
|
+
/**
|
|
1276
|
+
* Adds an ascending secondary sort key.
|
|
1277
|
+
*
|
|
1278
|
+
* @throws {ArgumentNullError} When `keySelector` is null.
|
|
1279
|
+
* @throws {ArgumentError} When `keySelector` is undefined.
|
|
1280
|
+
*/
|
|
1281
|
+
thenBy<TKey>(keySelector: (item: TSource) => TKey, comparer?: Comparer<TKey>): TyneqOrderedSequence<TSource>;
|
|
1282
|
+
/**
|
|
1283
|
+
* Adds a descending secondary sort key.
|
|
1284
|
+
*
|
|
1285
|
+
* @throws {ArgumentNullError} When `keySelector` is null.
|
|
1286
|
+
* @throws {ArgumentError} When `keySelector` is undefined.
|
|
1287
|
+
*/
|
|
1288
|
+
thenByDescending<TKey>(keySelector: (item: TSource) => TKey, comparer?: Comparer<TKey>): TyneqOrderedSequence<TSource>;
|
|
1289
|
+
/** Sets the ordering to ascending according to the current sort keys. */
|
|
1290
|
+
asc(): TyneqOrderedSequence<TSource>;
|
|
1291
|
+
/** Sets the ordering to descending according to the current sort keys. */
|
|
1292
|
+
desc(): TyneqOrderedSequence<TSource>;
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* A `TyneqSequence` that caches elements as they are iterated.
|
|
1296
|
+
*
|
|
1297
|
+
* @remarks
|
|
1298
|
+
* Produced by `memoize()`. Call `refresh()` to clear the cache and allow re-enumeration from the source.
|
|
1299
|
+
*
|
|
1300
|
+
* @typeParam TSource - Element type.
|
|
1301
|
+
* @group Interfaces
|
|
1302
|
+
*/
|
|
1303
|
+
interface TyneqCachedSequence<TSource> extends TyneqSequence<TSource> {
|
|
1304
|
+
/**
|
|
1305
|
+
* Clears the element cache and returns a new `TyneqCachedSequence` that will re-enumerate from the source.
|
|
1306
|
+
*/
|
|
1307
|
+
refresh(): TyneqCachedSequence<TSource>;
|
|
1308
|
+
}
|
|
1309
|
+
/**
|
|
1310
|
+
* Low-level interface for a sequence that supports incremental cache access.
|
|
1311
|
+
*
|
|
1312
|
+
* @typeParam TSource - Element type.
|
|
1313
|
+
* @group Interfaces
|
|
1314
|
+
* @internal
|
|
1315
|
+
*/
|
|
1316
|
+
interface CachedEnumerable<TSource> extends Enumerable<TSource> {
|
|
1317
|
+
/**
|
|
1318
|
+
* Attempts to return the cached element at `index`.
|
|
1319
|
+
*
|
|
1320
|
+
* @returns `{ has: true, value }` if cached, `{ has: false }` otherwise.
|
|
1321
|
+
*/
|
|
1322
|
+
tryGetAtFromCache(index: number): CacheResult<TSource>;
|
|
1323
|
+
}
|
|
1324
|
+
/** Result returned by the cache-lookup method on a memoized sequence. */
|
|
1325
|
+
type CacheResult<TSource> = {
|
|
1326
|
+
has: true;
|
|
1327
|
+
value: TSource;
|
|
1328
|
+
} | {
|
|
1329
|
+
has: false;
|
|
1330
|
+
};
|
|
1331
|
+
/**
|
|
1332
|
+
* Low-level interface for a sequence that can produce a sort comparator.
|
|
1333
|
+
*
|
|
1334
|
+
* @remarks
|
|
1335
|
+
* Implemented by `TyneqOrderedEnumerable`. Consumed by the ordering infrastructure.
|
|
1336
|
+
*
|
|
1337
|
+
* @typeParam TSource - Element type.
|
|
1338
|
+
* @group Interfaces
|
|
1339
|
+
* @internal
|
|
1340
|
+
*/
|
|
1341
|
+
interface OrderedEnumerable<TSource> extends Enumerable<TSource> {
|
|
1342
|
+
source: TyneqSequence<TSource>;
|
|
1343
|
+
/** The parent ordering level, or `null` for the primary sort. */
|
|
1344
|
+
parent: Nullable<OrderedEnumerable<TSource>>;
|
|
1345
|
+
/**
|
|
1346
|
+
* Produces a sorter chain that combines this level with any chained levels.
|
|
1347
|
+
*
|
|
1348
|
+
* @param next - The child sorter, or `null` if this is the innermost level.
|
|
1349
|
+
*/
|
|
1350
|
+
getSorter(next: Nullable<BaseEnumerableSorter<TSource>>): BaseEnumerableSorter<TSource>;
|
|
1351
|
+
}
|
|
1352
|
+
/** Result of `minMax()`, containing both the minimum and maximum elements. */
|
|
1353
|
+
type MinMaxResult<T> = {
|
|
1354
|
+
readonly min: T;
|
|
1355
|
+
readonly max: T;
|
|
1356
|
+
};
|
|
1357
|
+
/** A key-value pair used by `toMap()` and `toRecord()` selectors. */
|
|
1358
|
+
type KeyValuePair<TKey, TValue> = {
|
|
1359
|
+
key: TKey;
|
|
1360
|
+
value: TValue;
|
|
1361
|
+
};
|
|
1362
|
+
/**
|
|
1363
|
+
* Structural interface used by registration machinery to call the protected factory methods
|
|
1364
|
+
* on sequence classes without exposing them publicly.
|
|
1365
|
+
*
|
|
1366
|
+
* The double-cast `(this as unknown as SequenceFactory<T>)` is intentional:
|
|
1367
|
+
* these methods are `protected`, so the cast is the only way to call them from
|
|
1368
|
+
* outside the class hierarchy without changing their access modifier.
|
|
1369
|
+
*
|
|
1370
|
+
* @internal
|
|
1371
|
+
*/
|
|
1372
|
+
interface SequenceFactory<TSource> {
|
|
1373
|
+
readonly [tyneqQueryNode]: Nullable<QueryPlanNode>;
|
|
1374
|
+
createEnumerable(factory: {
|
|
1375
|
+
getEnumerator(): unknown;
|
|
1376
|
+
}, node?: Nullable<QueryPlanNode>): unknown;
|
|
1377
|
+
createOrderedEnumerable<TKey>(keySelector: (x: TSource) => TKey, comparer: Comparer<TKey>, descending: boolean, node?: Nullable<QueryPlanNode>): TyneqOrderedSequence<TSource>;
|
|
1378
|
+
createCachedEnumerable(source: TyneqSequence<TSource>, node?: Nullable<QueryPlanNode>): TyneqCachedSequence<TSource>;
|
|
1379
|
+
}
|
|
1380
|
+
/** A fully resolved operator entry: metadata plus the prototype-level implementation. */
|
|
1381
|
+
interface OperatorEntry {
|
|
1382
|
+
readonly metadata: OperatorMetadata;
|
|
1383
|
+
readonly impl: BoundMethod<TyneqEnumerableBase<unknown>>;
|
|
1384
|
+
}
|
|
1385
|
+
/** Source of an operator implementation, used internally to track where operators come from. */
|
|
1386
|
+
type OperatorSource = "internal" | "external";
|
|
1387
|
+
/** Kind of an operator, used internally to categorize operators. Extends `OperatorCategory` with registry-only kinds. */
|
|
1388
|
+
type OperatorKind = OperatorCategory | "cache" | "extension" | "unknown";
|
|
1389
|
+
/** Constructor type for a sequence class. */
|
|
1390
|
+
type SequenceConstructor = abstract new (...args: any[]) => TyneqEnumerableCore<unknown>;
|
|
1391
|
+
//#endregion
|
|
1392
|
+
export { Predicate as $, SourceKind as A, Func as B, QueryNode as C, QueryPlanTraversalDirection as D, QueryPlanPrinterOptions as E, BoundMethod as F, ItemPredicate as G, HasLength as H, Cast as I, Method as J, ItemSelector as K, Constructor as L, tyneqQueryNode as M, Action as N, QueryPlanVisitor as O, Assume as P, Optional as Q, Factory as R, TyneqEnumerableBase as S, QueryPlanNode as T, InstanceOf as U, GenericFunction as V, ItemAction as W, NoInfer as X, MethodKeys as Y, Nullable as Z, TyneqCachedSequence as _, Enumerator as a, TyneqSequence as b, IteratorFactory as c, OperatorEntry as d, WithProperties as et, OperatorKind as f, SequenceFactory as g, SequenceConstructor as h, Enumerable as i, isSourceNode as j, QueryPlanWalkerOptions as k, KeyValuePair as l, OrderedEnumerable as m, CachedEnumerable as n, EnumeratorFactory as o, OperatorSource as p, Maybe as q, Comparer as r, EqualityComparer as s, CacheResult as t, BaseEnumerableSorter as tt, MinMaxResult as u, TyneqEnumerableFactory as v, OperatorCategory as w, OperatorMetadata as x, TyneqOrderedSequence as y, FieldKeys as z };
|
|
1393
|
+
//# sourceMappingURL=core.d.cts.map
|