@absoluteui/helpers 0.0.0-stage → 0.13.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/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +47 -2
- package/SECURITY.md +102 -0
- package/dist/array/compare.d.ts +8 -0
- package/dist/array/compare.js +2 -0
- package/dist/array/index.d.ts +328 -0
- package/dist/array/index.js +2 -0
- package/dist/array/tree.d.ts +48 -0
- package/dist/array/tree.js +2 -0
- package/dist/async/batch.d.ts +103 -0
- package/dist/async/batch.js +2 -0
- package/dist/async/concurrency.d.ts +92 -0
- package/dist/async/concurrency.js +2 -0
- package/dist/async/control.d.ts +77 -0
- package/dist/async/control.js +2 -0
- package/dist/async/index.d.ts +8 -0
- package/dist/async/index.js +2 -0
- package/dist/async/signal.d.ts +95 -0
- package/dist/async/signal.js +2 -0
- package/dist/boolean/index.d.ts +83 -0
- package/dist/boolean/index.js +2 -0
- package/dist/business-calendar/days.d.ts +397 -0
- package/dist/business-calendar/days.js +2 -0
- package/dist/business-calendar/describe.d.ts +45 -0
- package/dist/business-calendar/describe.js +2 -0
- package/dist/business-calendar/engine.d.ts +305 -0
- package/dist/business-calendar/engine.js +2 -0
- package/dist/business-calendar/hours.d.ts +96 -0
- package/dist/business-calendar/hours.js +2 -0
- package/dist/business-calendar/index.d.ts +29 -0
- package/dist/business-calendar/index.js +2 -0
- package/dist/business-calendar/internal.d.ts +44 -0
- package/dist/business-calendar/internal.js +2 -0
- package/dist/business-calendar/rules.d.ts +260 -0
- package/dist/business-calendar/rules.js +2 -0
- package/dist/color/index.d.ts +200 -0
- package/dist/color/index.js +2 -0
- package/dist/color/named.d.ts +4 -0
- package/dist/color/named.js +2 -0
- package/dist/compare/index.d.ts +186 -0
- package/dist/compare/index.js +2 -0
- package/dist/convert/index.d.ts +152 -0
- package/dist/convert/index.js +2 -0
- package/dist/csv/index.d.ts +6 -0
- package/dist/csv/index.js +2 -0
- package/dist/csv/parse.d.ts +85 -0
- package/dist/csv/parse.js +12 -0
- package/dist/csv/stringify.d.ts +48 -0
- package/dist/csv/stringify.js +5 -0
- package/dist/date/calendar.d.ts +339 -0
- package/dist/date/calendar.js +2 -0
- package/dist/date/format.d.ts +66 -0
- package/dist/date/format.js +2 -0
- package/dist/date/index.d.ts +26 -0
- package/dist/date/index.js +2 -0
- package/dist/date/intervals.d.ts +110 -0
- package/dist/date/intervals.js +2 -0
- package/dist/date/intl-cache.d.ts +10 -0
- package/dist/date/intl-cache.js +2 -0
- package/dist/date/locale.d.ts +58 -0
- package/dist/date/locale.js +2 -0
- package/dist/date/plain-date.d.ts +105 -0
- package/dist/date/plain-date.js +2 -0
- package/dist/date/plain-time.d.ts +121 -0
- package/dist/date/plain-time.js +2 -0
- package/dist/date/zone.d.ts +121 -0
- package/dist/date/zone.js +2 -0
- package/dist/decimal/index.d.ts +149 -0
- package/dist/decimal/index.js +2 -0
- package/dist/ds/avl.d.ts +50 -0
- package/dist/ds/avl.js +2 -0
- package/dist/ds/bitset.d.ts +46 -0
- package/dist/ds/bitset.js +2 -0
- package/dist/ds/bloom.d.ts +41 -0
- package/dist/ds/bloom.js +2 -0
- package/dist/ds/caches.d.ts +141 -0
- package/dist/ds/caches.js +2 -0
- package/dist/ds/disjoint-set.d.ts +38 -0
- package/dist/ds/disjoint-set.js +2 -0
- package/dist/ds/emitter.d.ts +53 -0
- package/dist/ds/emitter.js +2 -0
- package/dist/ds/graph.d.ts +84 -0
- package/dist/ds/graph.js +2 -0
- package/dist/ds/heap.d.ts +49 -0
- package/dist/ds/heap.js +2 -0
- package/dist/ds/index.d.ts +20 -0
- package/dist/ds/index.js +2 -0
- package/dist/ds/internal.d.ts +19 -0
- package/dist/ds/internal.js +2 -0
- package/dist/ds/interval-tree.d.ts +49 -0
- package/dist/ds/interval-tree.js +2 -0
- package/dist/ds/linked-list.d.ts +54 -0
- package/dist/ds/linked-list.js +2 -0
- package/dist/ds/maps.d.ts +89 -0
- package/dist/ds/maps.js +2 -0
- package/dist/ds/ring.d.ts +99 -0
- package/dist/ds/ring.js +2 -0
- package/dist/ds/sorted.d.ts +104 -0
- package/dist/ds/sorted.js +2 -0
- package/dist/ds/stack.d.ts +28 -0
- package/dist/ds/stack.js +2 -0
- package/dist/ds/trie.d.ts +84 -0
- package/dist/ds/trie.js +2 -0
- package/dist/duration/index.d.ts +146 -0
- package/dist/duration/index.js +2 -0
- package/dist/encoding/index.d.ts +144 -0
- package/dist/encoding/index.js +2 -0
- package/dist/error/index.d.ts +316 -0
- package/dist/error/index.js +2 -0
- package/dist/fn/index.d.ts +129 -0
- package/dist/fn/index.js +2 -0
- package/dist/fn/memo.d.ts +46 -0
- package/dist/fn/memo.js +2 -0
- package/dist/fn/timing.d.ts +64 -0
- package/dist/fn/timing.js +2 -0
- package/dist/http/headers.d.ts +160 -0
- package/dist/http/headers.js +2 -0
- package/dist/http/index.d.ts +10 -0
- package/dist/http/index.js +2 -0
- package/dist/http/problem.d.ts +37 -0
- package/dist/http/problem.js +2 -0
- package/dist/http/response.d.ts +43 -0
- package/dist/http/response.js +2 -0
- package/dist/http/status.d.ts +169 -0
- package/dist/http/status.js +2 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +2 -0
- package/dist/internal/keys.d.ts +6 -0
- package/dist/internal/keys.js +2 -0
- package/dist/is/index.d.ts +219 -0
- package/dist/is/index.js +2 -0
- package/dist/json/index.d.ts +9 -0
- package/dist/json/index.js +2 -0
- package/dist/json/internal.d.ts +12 -0
- package/dist/json/internal.js +2 -0
- package/dist/json/ndjson.d.ts +28 -0
- package/dist/json/ndjson.js +4 -0
- package/dist/json/parse.d.ts +45 -0
- package/dist/json/parse.js +2 -0
- package/dist/json/patch.d.ts +62 -0
- package/dist/json/patch.js +2 -0
- package/dist/json/pointer.d.ts +43 -0
- package/dist/json/pointer.js +2 -0
- package/dist/json/stringify.d.ts +42 -0
- package/dist/json/stringify.js +2 -0
- package/dist/linq/enumerable.d.ts +208 -0
- package/dist/linq/enumerable.js +2 -0
- package/dist/linq/index.d.ts +6 -0
- package/dist/linq/index.js +2 -0
- package/dist/linq/operators.d.ts +503 -0
- package/dist/linq/operators.js +2 -0
- package/dist/number/core.d.ts +164 -0
- package/dist/number/core.js +2 -0
- package/dist/number/format.d.ts +80 -0
- package/dist/number/format.js +2 -0
- package/dist/number/index.d.ts +12 -0
- package/dist/number/index.js +2 -0
- package/dist/number/internal.d.ts +18 -0
- package/dist/number/internal.js +2 -0
- package/dist/number/parse.d.ts +45 -0
- package/dist/number/parse.js +2 -0
- package/dist/number/words.d.ts +19 -0
- package/dist/number/words.js +2 -0
- package/dist/object/basic.d.ts +130 -0
- package/dist/object/basic.js +2 -0
- package/dist/object/deep.d.ts +90 -0
- package/dist/object/deep.js +2 -0
- package/dist/object/diff.d.ts +57 -0
- package/dist/object/diff.js +2 -0
- package/dist/object/index.d.ts +8 -0
- package/dist/object/index.js +2 -0
- package/dist/object/internal.d.ts +21 -0
- package/dist/object/internal.js +2 -0
- package/dist/object/path.d.ts +17 -0
- package/dist/object/path.js +2 -0
- package/dist/random/core.d.ts +14 -0
- package/dist/random/core.js +2 -0
- package/dist/random/index.d.ts +167 -0
- package/dist/random/index.js +2 -0
- package/dist/random/seeded.d.ts +27 -0
- package/dist/random/seeded.js +2 -0
- package/dist/sanitize/index.d.ts +8 -0
- package/dist/sanitize/index.js +2 -0
- package/dist/sanitize/pii.d.ts +48 -0
- package/dist/sanitize/pii.js +2 -0
- package/dist/sanitize/records.d.ts +100 -0
- package/dist/sanitize/records.js +2 -0
- package/dist/sanitize/text.d.ts +101 -0
- package/dist/sanitize/text.js +2 -0
- package/dist/set/index.d.ts +162 -0
- package/dist/set/index.js +2 -0
- package/dist/stats/index.d.ts +190 -0
- package/dist/stats/index.js +2 -0
- package/dist/string/index.d.ts +494 -0
- package/dist/string/index.js +8 -0
- package/dist/string/internal.d.ts +33 -0
- package/dist/string/internal.js +2 -0
- package/dist/string/words.d.ts +14 -0
- package/dist/string/words.js +2 -0
- package/dist/timezone/index.d.ts +76 -0
- package/dist/timezone/index.js +2 -0
- package/dist/url/index.d.ts +178 -0
- package/dist/url/index.js +2 -0
- package/dist/validate/builders.d.ts +6 -0
- package/dist/validate/builders.js +2 -0
- package/dist/validate/formats.d.ts +237 -0
- package/dist/validate/formats.js +2 -0
- package/dist/validate/index.d.ts +13 -0
- package/dist/validate/index.js +2 -0
- package/dist/validate/schema.d.ts +220 -0
- package/dist/validate/schema.js +2 -0
- package/dist/zip/index.d.ts +8 -0
- package/dist/zip/index.js +2 -0
- package/dist/zip/internal.d.ts +69 -0
- package/dist/zip/internal.js +2 -0
- package/dist/zip/reader.d.ts +56 -0
- package/dist/zip/reader.js +2 -0
- package/dist/zip/writer.d.ts +65 -0
- package/dist/zip/writer.js +2 -0
- package/package.json +150 -4
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
/** Lazy transformation of one sequence into another. */
|
|
2
|
+
export type Operator<T, U> = (source: Iterable<T>) => Iterable<U>;
|
|
3
|
+
/** Consumes a sequence into a value. */
|
|
4
|
+
export type Terminal<T, R> = (source: Iterable<T>) => R;
|
|
5
|
+
/** Key comparer: negative, zero, or positive. */
|
|
6
|
+
export type KeyComparer<K> = (a: K, b: K) => number;
|
|
7
|
+
/** Equality test used by `contains` and `sequenceEqual`. */
|
|
8
|
+
export type EqualityComparer<T> = (a: T, b: T) => boolean;
|
|
9
|
+
/** SameValueZero, as used by `Set`, `Map`, and `Array#includes`. */
|
|
10
|
+
export declare const sameValueZero: (a: unknown, b: unknown) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Throws `HLP_LINQ_INVALID_ARGUMENT` unless `n` is a non-negative safe integer.
|
|
13
|
+
* @example
|
|
14
|
+
* assertCount(3); // => undefined
|
|
15
|
+
* assertCount(-1); // => throws HLP_LINQ_INVALID_ARGUMENT
|
|
16
|
+
*/
|
|
17
|
+
export declare function assertCount(n: number): void;
|
|
18
|
+
/**
|
|
19
|
+
* Default key order: nullish/`NaN` first, then booleans, numbers and bigints, strings (code-unit order), dates.
|
|
20
|
+
* @example
|
|
21
|
+
* [3, null, 1].sort(defaultCompare); // => [null, 1, 3]
|
|
22
|
+
*/
|
|
23
|
+
export declare function defaultCompare(a: unknown, b: unknown): number;
|
|
24
|
+
/**
|
|
25
|
+
* Threads `source` through operators left to right; the last may be a terminal.
|
|
26
|
+
* @example
|
|
27
|
+
* pipe([5, 1, 4], where((n) => n > 1), orderBy((n) => n), toArray()); // => [4, 5]
|
|
28
|
+
*/
|
|
29
|
+
export declare function pipe<A>(source: A): A;
|
|
30
|
+
export declare function pipe<A, B>(source: A, op1: (a: A) => B): B;
|
|
31
|
+
export declare function pipe<A, B, C>(source: A, op1: (a: A) => B, op2: (b: B) => C): C;
|
|
32
|
+
export declare function pipe<A, B, C, D>(source: A, op1: (a: A) => B, op2: (b: B) => C, op3: (c: C) => D): D;
|
|
33
|
+
export declare function pipe<A, B, C, D, E>(source: A, op1: (a: A) => B, op2: (b: B) => C, op3: (c: C) => D, op4: (d: D) => E): E;
|
|
34
|
+
export declare function pipe<A, B, C, D, E, F>(source: A, op1: (a: A) => B, op2: (b: B) => C, op3: (c: C) => D, op4: (d: D) => E, op5: (e: E) => F): F;
|
|
35
|
+
export declare function pipe<A, B, C, D, E, F, G>(source: A, op1: (a: A) => B, op2: (b: B) => C, op3: (c: C) => D, op4: (d: D) => E, op5: (e: E) => F, op6: (f: F) => G): G;
|
|
36
|
+
export declare function pipe<A, B, C, D, E, F, G, H>(source: A, op1: (a: A) => B, op2: (b: B) => C, op3: (c: C) => D, op4: (d: D) => E, op5: (e: E) => F, op6: (f: F) => G, op7: (g: G) => H): H;
|
|
37
|
+
export declare function pipe<A, B, C, D, E, F, G, H, I>(source: A, op1: (a: A) => B, op2: (b: B) => C, op3: (c: C) => D, op4: (d: D) => E, op5: (e: E) => F, op6: (f: F) => G, op7: (g: G) => H, op8: (h: H) => I): I;
|
|
38
|
+
export declare function pipe<A, B, C, D, E, F, G, H, I, J>(source: A, op1: (a: A) => B, op2: (b: B) => C, op3: (c: C) => D, op4: (d: D) => E, op5: (e: E) => F, op6: (f: F) => G, op7: (g: G) => H, op8: (h: H) => I, op9: (i: I) => J): J;
|
|
39
|
+
export declare function pipe(source: unknown, ...ops: ((value: unknown) => unknown)[]): unknown;
|
|
40
|
+
/**
|
|
41
|
+
* Keeps items matching `predicate(item, index)`.
|
|
42
|
+
* @example
|
|
43
|
+
* pipe([1, 2, 3], where((n) => n > 1), toArray()); // => [2, 3]
|
|
44
|
+
*/
|
|
45
|
+
export declare function where<T, S extends T>(predicate: (item: T, index: number) => item is S): Operator<T, S>;
|
|
46
|
+
export declare function where<T>(predicate: (item: T, index: number) => boolean): Operator<T, T>;
|
|
47
|
+
/**
|
|
48
|
+
* Keeps items passing a type guard (the `OfType` equivalent).
|
|
49
|
+
* @example
|
|
50
|
+
* pipe([1, 'a', 2], whereType((x): x is number => typeof x === 'number'), toArray()); // => [1, 2]
|
|
51
|
+
*/
|
|
52
|
+
export declare function whereType<T, S extends T>(guard: (item: T) => item is S): Operator<T, S>;
|
|
53
|
+
/**
|
|
54
|
+
* Maps items with `selector(item, index)`.
|
|
55
|
+
* @example
|
|
56
|
+
* pipe([1, 2], select((n, i) => n * 10 + i), toArray()); // => [10, 21]
|
|
57
|
+
*/
|
|
58
|
+
export declare function select<T, U>(selector: (item: T, index: number) => U): Operator<T, U>;
|
|
59
|
+
/**
|
|
60
|
+
* Maps each item to a sequence and flattens, optionally projecting `(item, child)`.
|
|
61
|
+
* @example
|
|
62
|
+
* pipe([[1, 2], [3]], selectMany((a) => a), toArray()); // => [1, 2, 3]
|
|
63
|
+
*/
|
|
64
|
+
export declare function selectMany<T, U>(selector: (item: T, index: number) => Iterable<U>): Operator<T, U>;
|
|
65
|
+
export declare function selectMany<T, U, R>(selector: (item: T, index: number) => Iterable<U>, resultSelector: (item: T, child: U) => R): Operator<T, R>;
|
|
66
|
+
interface SortSpec<T> {
|
|
67
|
+
key(item: T): unknown;
|
|
68
|
+
readonly compare: KeyComparer<unknown>;
|
|
69
|
+
readonly desc: boolean;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A deferred, stable sort. Iterating materializes and sorts the source (keys computed once per item);
|
|
73
|
+
* `thenBy`/`thenByDescending` add tie-breakers without re-sorting eagerly.
|
|
74
|
+
* @example
|
|
75
|
+
* const people = [{ name: 'Ravi', age: 41 }, { name: 'Ada', age: 36 }, { name: 'Ben', age: 36 }];
|
|
76
|
+
* [...orderBy((p: { name: string; age: number }) => p.age)(people).thenBy((p) => p.name)].map((p) => p.name); // => ['Ada', 'Ben', 'Ravi']
|
|
77
|
+
*/
|
|
78
|
+
export declare class OrderedSequence<T> implements Iterable<T> {
|
|
79
|
+
#private;
|
|
80
|
+
/** @internal Use `orderBy`/`orderByDescending`. */
|
|
81
|
+
constructor(source: Iterable<T>, specs: readonly SortSpec<T>[]);
|
|
82
|
+
/** Adds an ascending tie-breaker key. */
|
|
83
|
+
thenBy<K>(key: (item: T) => K, compare?: KeyComparer<K>): OrderedSequence<T>;
|
|
84
|
+
/** Adds a descending tie-breaker key. */
|
|
85
|
+
thenByDescending<K>(key: (item: T) => K, compare?: KeyComparer<K>): OrderedSequence<T>;
|
|
86
|
+
[Symbol.iterator](): Iterator<T>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Stable ascending sort by key (deferred until iterated).
|
|
90
|
+
* @example
|
|
91
|
+
* const people = [{ first: 'Ben', last: 'Kay' }, { first: 'Ada', last: 'Lee' }, { first: 'Al', last: 'Kay' }];
|
|
92
|
+
* pipe(people, orderBy((p) => p.last), thenBy((p) => p.first), toArray()).map((p) => p.first); // => ['Al', 'Ben', 'Ada']
|
|
93
|
+
*/
|
|
94
|
+
export declare function orderBy<T, K>(key: (item: T) => K, compare?: KeyComparer<K>): (source: Iterable<T>) => OrderedSequence<T>;
|
|
95
|
+
/**
|
|
96
|
+
* Stable descending sort by key (deferred until iterated).
|
|
97
|
+
* @example
|
|
98
|
+
* pipe([1, 3, 2], orderByDescending((n) => n), toArray()); // => [3, 2, 1]
|
|
99
|
+
*/
|
|
100
|
+
export declare function orderByDescending<T, K>(key: (item: T) => K, compare?: KeyComparer<K>): (source: Iterable<T>) => OrderedSequence<T>;
|
|
101
|
+
/**
|
|
102
|
+
* Ascending tie-breaker; only applies to an `orderBy` result.
|
|
103
|
+
* @example
|
|
104
|
+
* const rows = [{ a: 2, b: 1 }, { a: 1, b: 2 }, { a: 1, b: 1 }];
|
|
105
|
+
* pipe(rows, orderBy((r) => r.a), thenBy((r) => r.b), toArray()); // => [{ a: 1, b: 1 }, { a: 1, b: 2 }, { a: 2, b: 1 }]
|
|
106
|
+
*/
|
|
107
|
+
export declare function thenBy<T, K>(key: (item: T) => K, compare?: KeyComparer<K>): (source: OrderedSequence<T>) => OrderedSequence<T>;
|
|
108
|
+
/**
|
|
109
|
+
* Descending tie-breaker; only applies to an `orderBy` result.
|
|
110
|
+
* @example
|
|
111
|
+
* const rows = [{ a: 2, b: 1 }, { a: 1, b: 1 }, { a: 1, b: 2 }];
|
|
112
|
+
* pipe(rows, orderBy((r) => r.a), thenByDescending((r) => r.b), toArray()); // => [{ a: 1, b: 2 }, { a: 1, b: 1 }, { a: 2, b: 1 }]
|
|
113
|
+
*/
|
|
114
|
+
export declare function thenByDescending<T, K>(key: (item: T) => K, compare?: KeyComparer<K>): (source: OrderedSequence<T>) => OrderedSequence<T>;
|
|
115
|
+
/**
|
|
116
|
+
* Reverses the sequence (materializes when iterated).
|
|
117
|
+
* @example
|
|
118
|
+
* pipe([1, 2, 3], reverse(), toArray()); // => [3, 2, 1]
|
|
119
|
+
*/
|
|
120
|
+
export declare function reverse<T>(): Operator<T, T>;
|
|
121
|
+
/**
|
|
122
|
+
* A group of items sharing `key`. Re-iterable.
|
|
123
|
+
* @example
|
|
124
|
+
* const words = ['apple', 'avocado', 'banana'];
|
|
125
|
+
* const groups = pipe(words, groupBy((w) => w.charAt(0)), toArray());
|
|
126
|
+
* groups.map((g) => [g.key, g.items]); // => [['a', ['apple', 'avocado']], ['b', ['banana']]]
|
|
127
|
+
*/
|
|
128
|
+
export declare class Grouping<K, T> implements Iterable<T> {
|
|
129
|
+
readonly key: K;
|
|
130
|
+
readonly items: readonly T[];
|
|
131
|
+
/** @internal */
|
|
132
|
+
constructor(key: K, items: readonly T[]);
|
|
133
|
+
[Symbol.iterator](): Iterator<T>;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Groups by key (SameValueZero) in first-key order; materializes when iterated.
|
|
137
|
+
* @example
|
|
138
|
+
* pipe(['a', 'bb', 'cc'], groupBy((s) => s.length), select((g) => [g.key, g.items.length]), toArray()); // => [[1, 1], [2, 2]]
|
|
139
|
+
*/
|
|
140
|
+
export declare function groupBy<T, K>(key: (item: T) => K): Operator<T, Grouping<K, T>>;
|
|
141
|
+
export declare function groupBy<T, K, E>(key: (item: T) => K, element: (item: T) => E): Operator<T, Grouping<K, E>>;
|
|
142
|
+
export declare function groupBy<T, K, E, R>(key: (item: T) => K, element: (item: T) => E, result: (key: K, items: readonly E[]) => R): Operator<T, R>;
|
|
143
|
+
/**
|
|
144
|
+
* Read-only multi-map from `toLookup`. Missing keys give an empty array.
|
|
145
|
+
* @example
|
|
146
|
+
* const users = [{ name: 'Ada', dept: 'HR' }, { name: 'Ben', dept: 'IT' }, { name: 'Cy', dept: 'HR' }];
|
|
147
|
+
* const byDept = pipe(users, toLookup((u) => u.dept));
|
|
148
|
+
* byDept.get('HR').map((u) => u.name); // => ['Ada', 'Cy']
|
|
149
|
+
* byDept.get('Sales'); // => []
|
|
150
|
+
*/
|
|
151
|
+
export declare class Lookup<K, V> implements Iterable<Grouping<K, V>> {
|
|
152
|
+
#private;
|
|
153
|
+
/** @internal */
|
|
154
|
+
constructor(map: Map<K, V[]>);
|
|
155
|
+
/** Number of distinct keys. */
|
|
156
|
+
get size(): number;
|
|
157
|
+
/** True when `key` has at least one value. */
|
|
158
|
+
has(key: K): boolean;
|
|
159
|
+
/** Values for `key` (empty when absent). */
|
|
160
|
+
get(key: K): readonly V[];
|
|
161
|
+
[Symbol.iterator](): Iterator<Grouping<K, V>>;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Inner equi-join; nullish keys never match. The inner sequence is read once per iteration.
|
|
165
|
+
* @example
|
|
166
|
+
* const customers = [{ id: 1, name: 'Acme' }, { id: 2, name: 'Globex' }];
|
|
167
|
+
* const orders = [{ id: 10, customerId: 2 }, { id: 11, customerId: 3 }];
|
|
168
|
+
* pipe(orders, join(customers, (o) => o.customerId, (c) => c.id, (o, c) => ({ ...o, name: c.name })), toArray()); // => [{ id: 10, customerId: 2, name: 'Globex' }]
|
|
169
|
+
*/
|
|
170
|
+
export declare function join<T, U, K, R>(inner: Iterable<U>, outerKey: (item: T) => K, innerKey: (item: U) => K, result: (outer: T, inner: U) => R): Operator<T, R>;
|
|
171
|
+
/**
|
|
172
|
+
* Pairs each outer item with all matching inner items (possibly none).
|
|
173
|
+
* @example
|
|
174
|
+
* const customers = [{ id: 1, name: 'Acme' }, { id: 2, name: 'Globex' }];
|
|
175
|
+
* const orders = [{ id: 10, customerId: 2 }, { id: 12, customerId: 2 }];
|
|
176
|
+
* pipe(customers, groupJoin(orders, (c) => c.id, (o) => o.customerId, (c, os) => ({ name: c.name, n: os.length })), toArray()); // => [{ name: 'Acme', n: 0 }, { name: 'Globex', n: 2 }]
|
|
177
|
+
*/
|
|
178
|
+
export declare function groupJoin<T, U, K, R>(inner: Iterable<U>, outerKey: (item: T) => K, innerKey: (item: U) => K, result: (outer: T, inners: readonly U[]) => R): Operator<T, R>;
|
|
179
|
+
/**
|
|
180
|
+
* Left outer join: every outer item appears at least once, with `undefined` when nothing matches.
|
|
181
|
+
* @example
|
|
182
|
+
* const depts = [{ id: 'HR', name: 'Human Resources' }];
|
|
183
|
+
* const employees = [{ name: 'Ada', deptId: 'HR' }, { name: 'Ben', deptId: 'IT' }];
|
|
184
|
+
* pipe(employees, leftJoin(depts, (e) => e.deptId, (d) => d.id, (e, d) => [e.name, d?.name]), toArray()); // => [['Ada', 'Human Resources'], ['Ben', undefined]]
|
|
185
|
+
*/
|
|
186
|
+
export declare function leftJoin<T, U, K, R>(inner: Iterable<U>, outerKey: (item: T) => K, innerKey: (item: U) => K, result: (outer: T, inner: U | undefined) => R): Operator<T, R>;
|
|
187
|
+
/**
|
|
188
|
+
* Removes duplicates (SameValueZero), keeping first occurrences.
|
|
189
|
+
* @example
|
|
190
|
+
* pipe([1, 1, 2], distinct(), toArray()); // => [1, 2]
|
|
191
|
+
*/
|
|
192
|
+
export declare function distinct<T>(): Operator<T, T>;
|
|
193
|
+
/**
|
|
194
|
+
* Removes items with a duplicate key, keeping first occurrences.
|
|
195
|
+
* @example
|
|
196
|
+
* const users = [{ id: 1, email: 'ada@x.io' }, { id: 2, email: 'ben@x.io' }, { id: 3, email: 'ada@x.io' }];
|
|
197
|
+
* pipe(users, distinctBy((u) => u.email), toArray()).map((u) => u.id); // => [1, 2]
|
|
198
|
+
*/
|
|
199
|
+
export declare function distinctBy<T>(key: (item: T) => unknown): Operator<T, T>;
|
|
200
|
+
/**
|
|
201
|
+
* Distinct items of the source followed by new items of `other`.
|
|
202
|
+
* @example
|
|
203
|
+
* pipe([1, 2], union([2, 3]), toArray()); // => [1, 2, 3]
|
|
204
|
+
*/
|
|
205
|
+
export declare function union<T>(other: Iterable<T>): Operator<T, T>;
|
|
206
|
+
/**
|
|
207
|
+
* Union by key; the first item per key wins.
|
|
208
|
+
* @example
|
|
209
|
+
* const a = [{ id: 1, v: 'a' }, { id: 2, v: 'a' }];
|
|
210
|
+
* const b = [{ id: 2, v: 'b' }, { id: 3, v: 'b' }];
|
|
211
|
+
* pipe(a, unionBy(b, (x) => x.id), toArray()); // => [{ id: 1, v: 'a' }, { id: 2, v: 'a' }, { id: 3, v: 'b' }]
|
|
212
|
+
*/
|
|
213
|
+
export declare function unionBy<T>(other: Iterable<T>, key: (item: T) => unknown): Operator<T, T>;
|
|
214
|
+
/**
|
|
215
|
+
* Distinct items of the source that also occur in `other`.
|
|
216
|
+
* @example
|
|
217
|
+
* pipe([1, 2, 3, 2], intersect([2, 3]), toArray()); // => [2, 3]
|
|
218
|
+
*/
|
|
219
|
+
export declare function intersect<T>(other: Iterable<T>): Operator<T, T>;
|
|
220
|
+
/**
|
|
221
|
+
* Items whose key occurs among the keys of `other` (the key selector applies to both sequences), distinct by key.
|
|
222
|
+
* @example
|
|
223
|
+
* const a = [{ id: 1, v: 'a' }, { id: 2, v: 'a' }];
|
|
224
|
+
* const b = [{ id: 2, v: 'b' }, { id: 3, v: 'b' }];
|
|
225
|
+
* pipe(a, intersectBy(b, (x) => x.id), toArray()); // => [{ id: 2, v: 'a' }]
|
|
226
|
+
*/
|
|
227
|
+
export declare function intersectBy<T>(other: Iterable<T>, key: (item: T) => unknown): Operator<T, T>;
|
|
228
|
+
/**
|
|
229
|
+
* Distinct items of the source that do not occur in `other`.
|
|
230
|
+
* @example
|
|
231
|
+
* pipe([1, 2, 3, 1], except([2]), toArray()); // => [1, 3]
|
|
232
|
+
*/
|
|
233
|
+
export declare function except<T>(other: Iterable<T>): Operator<T, T>;
|
|
234
|
+
/**
|
|
235
|
+
* Items whose key does not occur among the keys of `other`, distinct by key.
|
|
236
|
+
* @example
|
|
237
|
+
* const a = [{ id: 1, v: 'a' }, { id: 2, v: 'a' }];
|
|
238
|
+
* const b = [{ id: 2, v: 'b' }, { id: 3, v: 'b' }];
|
|
239
|
+
* pipe(a, exceptBy(b, (x) => x.id), toArray()); // => [{ id: 1, v: 'a' }]
|
|
240
|
+
*/
|
|
241
|
+
export declare function exceptBy<T>(other: Iterable<T>, key: (item: T) => unknown): Operator<T, T>;
|
|
242
|
+
/**
|
|
243
|
+
* Appends another sequence.
|
|
244
|
+
* @example
|
|
245
|
+
* pipe([1], concat([2, 3]), toArray()); // => [1, 2, 3]
|
|
246
|
+
*/
|
|
247
|
+
export declare function concat<T>(other: Iterable<T>): Operator<T, T>;
|
|
248
|
+
/**
|
|
249
|
+
* Pairs items with `other` position-wise, stopping at the shorter sequence.
|
|
250
|
+
* @example
|
|
251
|
+
* pipe([1, 2, 3], zip(['a', 'b']), toArray()); // => [[1, 'a'], [2, 'b']]
|
|
252
|
+
*/
|
|
253
|
+
export declare function zip<T, U>(other: Iterable<U>): Operator<T, [T, U]>;
|
|
254
|
+
export declare function zip<T, U, R>(other: Iterable<U>, result: (a: T, b: U) => R): Operator<T, R>;
|
|
255
|
+
/**
|
|
256
|
+
* Adds an item at the end.
|
|
257
|
+
* @example
|
|
258
|
+
* pipe([1], append(2), toArray()); // => [1, 2]
|
|
259
|
+
*/
|
|
260
|
+
export declare function append<T>(item: T): Operator<T, T>;
|
|
261
|
+
/**
|
|
262
|
+
* Adds an item at the start.
|
|
263
|
+
* @example
|
|
264
|
+
* pipe([2], prepend(1), toArray()); // => [1, 2]
|
|
265
|
+
*/
|
|
266
|
+
export declare function prepend<T>(item: T): Operator<T, T>;
|
|
267
|
+
/**
|
|
268
|
+
* Yields `value` alone when the source is empty.
|
|
269
|
+
* @example
|
|
270
|
+
* pipe([], defaultIfEmpty(0), toArray()); // => [0]
|
|
271
|
+
*/
|
|
272
|
+
export declare function defaultIfEmpty<T>(value: T): Operator<T, T>;
|
|
273
|
+
/**
|
|
274
|
+
* Splits into arrays of `size` (the last may be shorter).
|
|
275
|
+
* @example
|
|
276
|
+
* pipe([1, 2, 3], chunk(2), toArray()); // => [[1, 2], [3]]
|
|
277
|
+
*/
|
|
278
|
+
export declare function chunk<T>(size: number): Operator<T, T[]>;
|
|
279
|
+
/**
|
|
280
|
+
* Takes the first `count` items and stops pulling from the source.
|
|
281
|
+
* @example
|
|
282
|
+
* function* naturals(): Generator<number> {
|
|
283
|
+
* for (let n = 0; ; n++) yield n;
|
|
284
|
+
* }
|
|
285
|
+
* pipe(naturals(), take(3), toArray()); // => [0, 1, 2]
|
|
286
|
+
*/
|
|
287
|
+
export declare function take<T>(count: number): Operator<T, T>;
|
|
288
|
+
/**
|
|
289
|
+
* Takes leading items while `predicate(item, index)` holds.
|
|
290
|
+
* @example
|
|
291
|
+
* pipe([1, 2, 5, 1], takeWhile((n) => n < 3), toArray()); // => [1, 2]
|
|
292
|
+
*/
|
|
293
|
+
export declare function takeWhile<T>(predicate: (item: T, index: number) => boolean): Operator<T, T>;
|
|
294
|
+
/**
|
|
295
|
+
* Takes the last `count` items (buffers `count` items).
|
|
296
|
+
* @example
|
|
297
|
+
* pipe([1, 2, 3], takeLast(2), toArray()); // => [2, 3]
|
|
298
|
+
*/
|
|
299
|
+
export declare function takeLast<T>(count: number): Operator<T, T>;
|
|
300
|
+
/**
|
|
301
|
+
* Skips the first `count` items.
|
|
302
|
+
* @example
|
|
303
|
+
* pipe([1, 2, 3], skip(1), toArray()); // => [2, 3]
|
|
304
|
+
*/
|
|
305
|
+
export declare function skip<T>(count: number): Operator<T, T>;
|
|
306
|
+
/**
|
|
307
|
+
* Skips leading items while `predicate(item, index)` holds.
|
|
308
|
+
* @example
|
|
309
|
+
* pipe([1, 2, 5, 1], skipWhile((n) => n < 3), toArray()); // => [5, 1]
|
|
310
|
+
*/
|
|
311
|
+
export declare function skipWhile<T>(predicate: (item: T, index: number) => boolean): Operator<T, T>;
|
|
312
|
+
/**
|
|
313
|
+
* Skips the last `count` items (buffers `count` items).
|
|
314
|
+
* @example
|
|
315
|
+
* pipe([1, 2, 3], skipLast(1), toArray()); // => [1, 2]
|
|
316
|
+
*/
|
|
317
|
+
export declare function skipLast<T>(count: number): Operator<T, T>;
|
|
318
|
+
/**
|
|
319
|
+
* Collects into an array.
|
|
320
|
+
* @example
|
|
321
|
+
* pipe(new Set([1, 2]), toArray()); // => [1, 2]
|
|
322
|
+
*/
|
|
323
|
+
export declare function toArray<T>(): Terminal<T, T[]>;
|
|
324
|
+
/**
|
|
325
|
+
* Collects into a `Set`.
|
|
326
|
+
* @example
|
|
327
|
+
* pipe([1, 1, 2], toSet()); // => new Set([1, 2])
|
|
328
|
+
*/
|
|
329
|
+
export declare function toSet<T>(): Terminal<T, Set<T>>;
|
|
330
|
+
/**
|
|
331
|
+
* Collects into a `Map`; throws `HLP_LINQ_DUPLICATE_KEY` on a repeated key.
|
|
332
|
+
* @example
|
|
333
|
+
* const users = [{ id: 1, name: 'Ada' }, { id: 2, name: 'Ben' }];
|
|
334
|
+
* const names = pipe(users, toMap((u) => u.id, (u) => u.name));
|
|
335
|
+
* names.get(2); // => 'Ben'
|
|
336
|
+
* pipe([...users, { id: 1, name: 'Cy' }], toMap((u) => u.id)); // => throws HLP_LINQ_DUPLICATE_KEY
|
|
337
|
+
*/
|
|
338
|
+
export declare function toMap<T, K>(key: (item: T) => K): Terminal<T, Map<K, T>>;
|
|
339
|
+
export declare function toMap<T, K, V>(key: (item: T) => K, value: (item: T) => V): Terminal<T, Map<K, V>>;
|
|
340
|
+
/**
|
|
341
|
+
* Alias of `toMap` (the .NET `ToDictionary` name).
|
|
342
|
+
* @example
|
|
343
|
+
* const users = [{ id: 1, name: 'Ada' }, { id: 2, name: 'Ben' }];
|
|
344
|
+
* pipe(users, toDictionary((u) => u.id)).get(1); // => { id: 1, name: 'Ada' }
|
|
345
|
+
*/
|
|
346
|
+
export declare const toDictionary: typeof toMap;
|
|
347
|
+
/**
|
|
348
|
+
* Collects into a `Lookup` (key -> values), keys in first-occurrence order.
|
|
349
|
+
* @example
|
|
350
|
+
* const users = [{ name: 'Ada', dept: 'HR' }, { name: 'Ben', dept: 'IT' }, { name: 'Cy', dept: 'HR' }];
|
|
351
|
+
* pipe(users, toLookup((u) => u.dept)).get('HR').length; // => 2
|
|
352
|
+
*/
|
|
353
|
+
export declare function toLookup<T, K>(key: (item: T) => K): Terminal<T, Lookup<K, T>>;
|
|
354
|
+
export declare function toLookup<T, K, V>(key: (item: T) => K, value: (item: T) => V): Terminal<T, Lookup<K, V>>;
|
|
355
|
+
/**
|
|
356
|
+
* Runs `action(item, index)` for every item.
|
|
357
|
+
* @example
|
|
358
|
+
* let total = 0;
|
|
359
|
+
* pipe([1, 2], forEach((n) => { total += n; }));
|
|
360
|
+
* total; // => 3
|
|
361
|
+
*/
|
|
362
|
+
export declare function forEach<T>(action: (item: T, index: number) => void): Terminal<T, void>;
|
|
363
|
+
type Predicate<T> = (item: T, index: number) => boolean;
|
|
364
|
+
/**
|
|
365
|
+
* First matching item; throws `HLP_LINQ_NO_ELEMENTS` when none.
|
|
366
|
+
* @example
|
|
367
|
+
* pipe([1, 2, 3], first((n) => n > 1)); // => 2
|
|
368
|
+
*/
|
|
369
|
+
export declare function first<T>(predicate?: Predicate<T>): Terminal<T, T>;
|
|
370
|
+
/**
|
|
371
|
+
* First matching item, or `defaultValue` (default `undefined`).
|
|
372
|
+
* @example
|
|
373
|
+
* pipe([1], firstOrDefault((n) => n > 5)); // => undefined
|
|
374
|
+
* pipe([1], firstOrDefault(undefined, 0)); // => 1
|
|
375
|
+
*/
|
|
376
|
+
export declare function firstOrDefault<T>(predicate?: Predicate<T>): Terminal<T, T | undefined>;
|
|
377
|
+
export declare function firstOrDefault<T, D>(predicate: Predicate<T> | undefined, defaultValue: D): Terminal<T, T | D>;
|
|
378
|
+
/**
|
|
379
|
+
* Last matching item; throws `HLP_LINQ_NO_ELEMENTS` when none.
|
|
380
|
+
* @example
|
|
381
|
+
* pipe([1, 2, 3], last()); // => 3
|
|
382
|
+
*/
|
|
383
|
+
export declare function last<T>(predicate?: Predicate<T>): Terminal<T, T>;
|
|
384
|
+
/**
|
|
385
|
+
* Last matching item, or `defaultValue` (default `undefined`).
|
|
386
|
+
* @example
|
|
387
|
+
* pipe([], lastOrDefault()); // => undefined
|
|
388
|
+
*/
|
|
389
|
+
export declare function lastOrDefault<T>(predicate?: Predicate<T>): Terminal<T, T | undefined>;
|
|
390
|
+
export declare function lastOrDefault<T, D>(predicate: Predicate<T> | undefined, defaultValue: D): Terminal<T, T | D>;
|
|
391
|
+
/**
|
|
392
|
+
* The only matching item; throws `HLP_LINQ_NO_ELEMENTS` or `HLP_LINQ_MULTIPLE_ELEMENTS`.
|
|
393
|
+
* @example
|
|
394
|
+
* pipe([1, 2], single((n) => n > 1)); // => 2
|
|
395
|
+
*/
|
|
396
|
+
export declare function single<T>(predicate?: Predicate<T>): Terminal<T, T>;
|
|
397
|
+
/**
|
|
398
|
+
* The only matching item or `defaultValue`; still throws `HLP_LINQ_MULTIPLE_ELEMENTS` for several.
|
|
399
|
+
* @example
|
|
400
|
+
* pipe([], singleOrDefault()); // => undefined
|
|
401
|
+
*/
|
|
402
|
+
export declare function singleOrDefault<T>(predicate?: Predicate<T>): Terminal<T, T | undefined>;
|
|
403
|
+
export declare function singleOrDefault<T, D>(predicate: Predicate<T> | undefined, defaultValue: D): Terminal<T, T | D>;
|
|
404
|
+
/**
|
|
405
|
+
* Item at `index` (negative counts from the end); throws `HLP_LINQ_INDEX_OUT_OF_RANGE`.
|
|
406
|
+
* @example
|
|
407
|
+
* pipe([1, 2, 3], elementAt(-1)); // => 3
|
|
408
|
+
*/
|
|
409
|
+
export declare function elementAt<T>(index: number): Terminal<T, T>;
|
|
410
|
+
/**
|
|
411
|
+
* Item at `index` (negative counts from the end), or `defaultValue`.
|
|
412
|
+
* @example
|
|
413
|
+
* pipe([1], elementAtOrDefault(5)); // => undefined
|
|
414
|
+
*/
|
|
415
|
+
export declare function elementAtOrDefault<T>(index: number): Terminal<T, T | undefined>;
|
|
416
|
+
export declare function elementAtOrDefault<T, D>(index: number, defaultValue: D): Terminal<T, T | D>;
|
|
417
|
+
/**
|
|
418
|
+
* True when any item matches (or the sequence is non-empty); stops at the first match.
|
|
419
|
+
* @example
|
|
420
|
+
* pipe([1, 2], any((n) => n > 1)); // => true
|
|
421
|
+
*/
|
|
422
|
+
export declare function any<T>(predicate?: Predicate<T>): Terminal<T, boolean>;
|
|
423
|
+
/**
|
|
424
|
+
* True when every item matches (true for empty); stops at the first failure.
|
|
425
|
+
* @example
|
|
426
|
+
* pipe([1, 2], all((n) => n > 0)); // => true
|
|
427
|
+
*/
|
|
428
|
+
export declare function all<T>(predicate: Predicate<T>): Terminal<T, boolean>;
|
|
429
|
+
/**
|
|
430
|
+
* True when the sequence contains `value` (SameValueZero by default).
|
|
431
|
+
* @example
|
|
432
|
+
* pipe([1, NaN], contains(NaN)); // => true
|
|
433
|
+
*/
|
|
434
|
+
export declare function contains<T>(value: T, equals?: EqualityComparer<T>): Terminal<T, boolean>;
|
|
435
|
+
/**
|
|
436
|
+
* True when both sequences have equal items in the same order.
|
|
437
|
+
* @example
|
|
438
|
+
* pipe([1, 2], sequenceEqual(new Set([1, 2]))); // => true
|
|
439
|
+
*/
|
|
440
|
+
export declare function sequenceEqual<T>(other: Iterable<T>, equals?: EqualityComparer<T>): Terminal<T, boolean>;
|
|
441
|
+
/**
|
|
442
|
+
* Number of matching items (O(1) for arrays, `Set`s and `Map`s without a predicate).
|
|
443
|
+
* @example
|
|
444
|
+
* pipe([1, 2, 3], count((n) => n > 1)); // => 2
|
|
445
|
+
*/
|
|
446
|
+
export declare function count<T>(predicate?: Predicate<T>): Terminal<T, number>;
|
|
447
|
+
/**
|
|
448
|
+
* Compensated sum (0 for empty).
|
|
449
|
+
* @example
|
|
450
|
+
* pipe([1, 2, 3], sum()); // => 6
|
|
451
|
+
* const orders = [{ id: 1, total: 120 }, { id: 2, total: 80.5 }];
|
|
452
|
+
* pipe(orders, sum((o) => o.total)); // => 200.5
|
|
453
|
+
*/
|
|
454
|
+
export declare function sum(): Terminal<number, number>;
|
|
455
|
+
export declare function sum<T>(selector: (item: T, index: number) => number): Terminal<T, number>;
|
|
456
|
+
/**
|
|
457
|
+
* Arithmetic mean; throws `HLP_LINQ_NO_ELEMENTS` for empty input.
|
|
458
|
+
* @example
|
|
459
|
+
* pipe([1, 2, 3], average()); // => 2
|
|
460
|
+
*/
|
|
461
|
+
export declare function average(): Terminal<number, number>;
|
|
462
|
+
export declare function average<T>(selector: (item: T, index: number) => number): Terminal<T, number>;
|
|
463
|
+
/**
|
|
464
|
+
* Smallest value (nullish and `NaN` ignored); throws `HLP_LINQ_NO_ELEMENTS` when none remain.
|
|
465
|
+
* @example
|
|
466
|
+
* pipe([3, 1, 2], min()); // => 1
|
|
467
|
+
* const users = [{ name: 'Ada', age: 36 }, { name: 'Ben', age: 29 }];
|
|
468
|
+
* pipe(users, min((u) => u.age)); // => 29
|
|
469
|
+
*/
|
|
470
|
+
export declare function min<T>(): Terminal<T, T>;
|
|
471
|
+
export declare function min<T, R>(selector: (item: T, index: number) => R, compare?: KeyComparer<R>): Terminal<T, R>;
|
|
472
|
+
/**
|
|
473
|
+
* Largest value (nullish and `NaN` ignored); throws `HLP_LINQ_NO_ELEMENTS` when none remain.
|
|
474
|
+
* @example
|
|
475
|
+
* pipe([3, 1, 2], max()); // => 3
|
|
476
|
+
*/
|
|
477
|
+
export declare function max<T>(): Terminal<T, T>;
|
|
478
|
+
export declare function max<T, R>(selector: (item: T, index: number) => R, compare?: KeyComparer<R>): Terminal<T, R>;
|
|
479
|
+
/**
|
|
480
|
+
* Item with the smallest key (first on ties, nullish keys ignored), or `undefined`.
|
|
481
|
+
* @example
|
|
482
|
+
* const users = [{ name: 'Ada', age: 36 }, { name: 'Ben', age: 29 }];
|
|
483
|
+
* pipe(users, minBy((u) => u.age)); // => { name: 'Ben', age: 29 }
|
|
484
|
+
*/
|
|
485
|
+
export declare function minBy<T, K>(key: (item: T) => K, compare?: KeyComparer<K>): Terminal<T, T | undefined>;
|
|
486
|
+
/**
|
|
487
|
+
* Item with the largest key (first on ties, nullish keys ignored), or `undefined`.
|
|
488
|
+
* @example
|
|
489
|
+
* const users = [{ name: 'Ada', age: 36 }, { name: 'Ben', age: 29 }];
|
|
490
|
+
* pipe(users, maxBy((u) => u.age)); // => { name: 'Ada', age: 36 }
|
|
491
|
+
*/
|
|
492
|
+
export declare function maxBy<T, K>(key: (item: T) => K, compare?: KeyComparer<K>): Terminal<T, T | undefined>;
|
|
493
|
+
/**
|
|
494
|
+
* Folds the sequence. Without a seed the first item seeds the fold (throws `HLP_LINQ_NO_ELEMENTS` when empty).
|
|
495
|
+
* @example
|
|
496
|
+
* pipe([1, 2, 3], aggregate((a, b) => a + b)); // => 6
|
|
497
|
+
* pipe([1, 2, 3], aggregate('', (s, n) => s + n)); // => '123'
|
|
498
|
+
* pipe([1, 2], aggregate(0, (a, n) => a + n, (a) => a * 10)); // => 30
|
|
499
|
+
*/
|
|
500
|
+
export declare function aggregate<T>(fn: (acc: T, item: T, index: number) => T): Terminal<T, T>;
|
|
501
|
+
export declare function aggregate<T, A>(seed: A, fn: (acc: A, item: T, index: number) => A): Terminal<T, A>;
|
|
502
|
+
export declare function aggregate<T, A, R>(seed: A, fn: (acc: A, item: T, index: number) => A, result: (acc: A) => R): Terminal<T, R>;
|
|
503
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{ConflictError as g,NotFoundError as w,ValidationError as D}from"../error/index.js";const a=e=>({[Symbol.iterator]:e}),I=(e,n)=>e===n||e!==e&&n!==n,s=()=>new w("HLP_LINQ_NO_ELEMENTS","The sequence contains no matching element."),v=()=>new g("HLP_LINQ_MULTIPLE_ELEMENTS","The sequence contains more than one matching element."),L=()=>new w("HLP_LINQ_INDEX_OUT_OF_RANGE","The index is out of range.");function d(e){if(!Number.isSafeInteger(e)||e<0)throw new D("HLP_LINQ_INVALID_ARGUMENT","Count must be a non-negative integer.")}function x(e){if(e==null)return 0;switch(typeof e){case"boolean":return 1;case"number":return Number.isNaN(e)?0:2;case"bigint":return 2;case"string":return 3;default:return e instanceof Date?Number.isNaN(e.getTime())?0:4:5}}function p(e,n){const t=x(e),r=x(n);if(t!==r)return t-r;if(t===0||t===5)return 0;if(t===4)return e.getTime()-n.getTime();const o=e,i=n;return o===i?0:o<i?-1:o>i?1:0}function H(e,...n){return n.reduce((t,r)=>r(t),e)}function Q(e){return n=>a(function*(){let t=0;for(const r of n)e(r,t++)&&(yield r)})}function z(e){return n=>a(function*(){for(const t of n)e(t)&&(yield t)})}function V(e){return n=>a(function*(){let t=0;for(const r of n)yield e(r,t++)})}function J(e,n){return t=>a(function*(){let r=0;for(const o of t)for(const i of e(o,r++))yield n?n(o,i):i})}class m{#e;#n;constructor(n,t){this.#e=n,this.#n=t}thenBy(n,t){return new m(this.#e,[...this.#n,b(n,t,!1)])}thenByDescending(n,t){return new m(this.#e,[...this.#n,b(n,t,!0)])}*[Symbol.iterator](){const n=[...this.#e],r=this.#n.map(i=>({sp:i,keys:n.map(u=>i.key(u))})),o=n.map((i,u)=>u);o.sort((i,u)=>{for(const{sp:T,keys:f}of r){const l=T.compare(f[i],f[u]);if(l!==0)return T.desc?-l:l}return i-u});for(const i of o)yield n[i]}}function b(e,n,t){return{key:e,compare:n??p,desc:t}}function W(e,n){return t=>new m(t,[b(e,n,!1)])}function j(e,n){return t=>new m(t,[b(e,n,!0)])}function X(e,n){return t=>t.thenBy(e,n)}function Y(e,n){return t=>t.thenByDescending(e,n)}function Z(){return e=>a(function*(){const n=[...e];for(let t=n.length-1;t>=0;t--)yield n[t]})}class O{key;items;constructor(n,t){this.key=n,this.items=t}[Symbol.iterator](){return this.items[Symbol.iterator]()}}function R(e,n,t){const r=new Map;for(const o of e){const i=n(o),u=r.get(i);u?u.push(t(o)):r.set(i,[t(o)])}return r}function $(e,n,t){const r=n??(o=>o);return o=>a(function*(){for(const[i,u]of R(o,e,r))yield t?t(i,u):new O(i,u)})}class N{#e;constructor(n){this.#e=n}get size(){return this.#e.size}has(n){return this.#e.has(n)}get(n){return this.#e.get(n)??[]}*[Symbol.iterator](){for(const[n,t]of this.#e)yield new O(n,t)}}function k(e,n){const t=new Map;for(const r of e){const o=n(r);if(o==null)continue;const i=t.get(o);i?i.push(r):t.set(o,[r])}return t}function ee(e,n,t,r){return o=>a(function*(){const i=k(e,t);for(const u of o){const T=n(u);if(T!=null)for(const f of i.get(T)??[])yield r(u,f)}})}function ne(e,n,t,r){return o=>a(function*(){const i=k(e,t);for(const u of o){const T=n(u);yield r(u,T==null?[]:i.get(T)??[])}})}function te(e,n,t,r){return o=>a(function*(){const i=k(e,t);for(const u of o){const T=n(u),f=T==null?void 0:i.get(T);if(f)for(const l of f)yield r(u,l);else yield r(u,void 0)}})}function re(){return E(e=>e)}function E(e){return n=>a(function*(){const t=new Set;for(const r of n){const o=e(r);t.has(o)||(t.add(o),yield r)}})}function oe(e){return P(e,n=>n)}function P(e,n){return t=>E(n)(G(e)(t))}function ie(e){return M(e,n=>n)}function M(e,n){return t=>a(function*(){const r=new Set;for(const o of e)r.add(n(o));for(const o of t){const i=n(o);r.delete(i)&&(yield o)}})}function ue(e){return F(e,n=>n)}function F(e,n){return t=>a(function*(){const r=new Set;for(const o of e)r.add(n(o));for(const o of t){const i=n(o);r.has(i)||(r.add(i),yield o)}})}function G(e){return n=>a(function*(){yield*n,yield*e})}function ae(e,n){return t=>a(function*(){const r=t[Symbol.iterator](),o=e[Symbol.iterator]();try{for(;;){const i=r.next();if(i.done===!0)return;const u=o.next();if(u.done===!0)return;yield n?n(i.value,u.value):[i.value,u.value]}}finally{r.return?.(),o.return?.()}})}function Te(e){return n=>a(function*(){yield*n,yield e})}function fe(e){return n=>a(function*(){yield e,yield*n})}function ce(e){return n=>a(function*(){let t=!1;for(const r of n)t=!0,yield r;t||(yield e)})}function le(e){if(!Number.isSafeInteger(e)||e<1)throw new D("HLP_LINQ_INVALID_ARGUMENT","Chunk size must be a positive integer.");return n=>a(function*(){let t=[];for(const r of n)t.push(r),t.length===e&&(yield t,t=[]);t.length&&(yield t)})}function pe(e){return d(e),n=>a(function*(){if(e===0)return;let t=0;for(const r of n)if(yield r,++t>=e)return})}function se(e){return n=>a(function*(){let t=0;for(const r of n){if(!e(r,t++))return;yield r}})}function me(e){return d(e),n=>a(function*(){if(e===0)return;const t=[];let r=0;for(const o of n)t.length<e?t.push(o):(t[r]=o,r=(r+1)%e);for(let o=0;o<t.length;o++)yield t[(r+o)%t.length]})}function de(e){return d(e),n=>a(function*(){let t=0;for(const r of n)t++>=e&&(yield r)})}function xe(e){return n=>a(function*(){let t=!0,r=0;for(const o of n)t&&e(o,r++)||(t=!1,yield o)})}function be(e){return d(e),n=>a(function*(){if(e===0){yield*n;return}const t=[];let r=0;for(const o of n){if(t.length<e){t.push(o);continue}yield t[r],t[r]=o,r=(r+1)%e}})}function ye(){return e=>[...e]}function Ke(){return e=>new Set(e)}function _(e,n){return t=>{const r=new Map;for(const o of t){const i=e(o);if(r.has(i))throw new g("HLP_LINQ_DUPLICATE_KEY","The sequence produced a duplicate key.");r.set(i,n?n(o):o)}return r}}const he=_;function ke(e,n){return t=>new N(R(t,e,n??(r=>r)))}function ge(e){return n=>{let t=0;for(const r of n)e(r,t++)}}const c=()=>!0;function we(e=c){return n=>{let t=0;for(const r of n)if(e(r,t++))return r;throw s()}}function De(e=c,n){return t=>{let r=0;for(const o of t)if(e(o,r++))return o;return n}}function A(e,n){let t=!1,r,o=0;for(const i of e)n(i,o++)&&(t=!0,r=i);return{found:t,value:r}}function Ie(e=c){return n=>{const t=A(n,e);if(!t.found)throw s();return t.value}}function Oe(e=c,n){return t=>{const r=A(t,e);return r.found?r.value:n}}function C(e,n){let t=!1,r,o=0;for(const i of e)if(n(i,o++)){if(t)throw v();t=!0,r=i}return{found:t,value:r}}function Re(e=c){return n=>{const t=C(n,e);if(!t.found)throw s();return t.value}}function Ee(e=c,n){return t=>{const r=C(t,e);return r.found?r.value:n}}function U(e,n){if(!Number.isSafeInteger(n))return{found:!1,value:void 0};if(Array.isArray(e)||n<0){const r=Array.isArray(e)?e:[...e],o=n<0?r.length+n:n;return o>=0&&o<r.length?{found:!0,value:r[o]}:{found:!1,value:void 0}}let t=0;for(const r of e)if(t++===n)return{found:!0,value:r};return{found:!1,value:void 0}}function Ae(e){return n=>{const t=U(n,e);if(!t.found)throw L();return t.value}}function Ce(e,n){return t=>{const r=U(t,e);return r.found?r.value:n}}function Ue(e=c){return n=>{let t=0;for(const r of n)if(e(r,t++))return!0;return!1}}function Be(e){return n=>{let t=0;for(const r of n)if(!e(r,t++))return!1;return!0}}function Se(e,n=I){return t=>{for(const r of t)if(n(r,e))return!0;return!1}}function ve(e,n=I){return t=>{const r=t[Symbol.iterator](),o=e[Symbol.iterator]();try{for(;;){const i=r.next(),u=o.next();if(i.done===!0||u.done===!0)return i.done===u.done;if(!n(i.value,u.value))return!1}}finally{r.return?.(),o.return?.()}}}function Le(e){return n=>{if(!e){if(Array.isArray(n))return n.length;if(n instanceof Set||n instanceof Map)return n.size}const t=e??c;let r=0,o=0;for(const i of n)t(i,o++)&&r++;return r}}function B(e){let n=0,t=0,r=0;for(const o of e){const i=n+o;t+=Math.abs(n)>=Math.abs(o)?n-i+o:o-i+n,n=i,r++}return{sum:n+t,n:r}}function y(e,n){return V(n)(e)}function Ve(e){return n=>B(e?y(n,e):n).sum}function Ne(e){return n=>{const t=B(e?y(n,e):n);if(t.n===0)throw s();return t.sum/t.n}}function K(e,n,t){let r=!1,o;for(const i of e)x(i)!==0&&(!r||t(i,o)*n<0)&&(o=i,r=!0);if(!r)throw s();return o}function Pe(e,n=p){return t=>e?K(y(t,e),1,n):K(t,1,p)}function Me(e,n=p){return t=>e?K(y(t,e),-1,n):K(t,-1,p)}function S(e,n,t,r){let o=!1,i,u;for(const T of e){const f=n(T);x(f)!==0&&(!o||t(f,u)*r<0)&&(i=T,u=f,o=!0)}return i}function Fe(e,n=p){return t=>S(t,e,n,1)}function Ge(e,n=p){return t=>S(t,e,n,-1)}function _e(...e){return n=>{if(e.length===1){const i=e[0],u=n[Symbol.iterator](),T=u.next();if(T.done===!0)throw s();let f=T.value,l=1;for(let h=u.next();h.done!==!0;h=u.next())f=i(f,h.value,l++);return f}const t=e[1];let r=e[0],o=0;for(const i of n)r=t(r,i,o++);return e.length>2?e[2](r):r}}export{O as Grouping,N as Lookup,m as OrderedSequence,_e as aggregate,Be as all,Ue as any,Te as append,d as assertCount,Ne as average,le as chunk,G as concat,Se as contains,Le as count,p as defaultCompare,ce as defaultIfEmpty,re as distinct,E as distinctBy,Ae as elementAt,Ce as elementAtOrDefault,ue as except,F as exceptBy,we as first,De as firstOrDefault,ge as forEach,$ as groupBy,ne as groupJoin,ie as intersect,M as intersectBy,ee as join,Ie as last,Oe as lastOrDefault,te as leftJoin,Me as max,Ge as maxBy,Pe as min,Fe as minBy,W as orderBy,j as orderByDescending,H as pipe,fe as prepend,Z as reverse,I as sameValueZero,V as select,J as selectMany,ve as sequenceEqual,Re as single,Ee as singleOrDefault,de as skip,be as skipLast,xe as skipWhile,Ve as sum,pe as take,me as takeLast,se as takeWhile,X as thenBy,Y as thenByDescending,ye as toArray,he as toDictionary,ke as toLookup,_ as toMap,Ke as toSet,oe as union,P as unionBy,Q as where,z as whereType,ae as zip};
|