@elaraai/east 0.0.1-beta.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.md +682 -0
- package/README.md +276 -0
- package/dist/src/analyze.d.ts +95 -0
- package/dist/src/analyze.d.ts.map +1 -0
- package/dist/src/analyze.js +1110 -0
- package/dist/src/analyze.js.map +1 -0
- package/dist/src/ast.d.ts +263 -0
- package/dist/src/ast.d.ts.map +1 -0
- package/dist/src/ast.js +151 -0
- package/dist/src/ast.js.map +1 -0
- package/dist/src/ast_to_ir.d.ts +24 -0
- package/dist/src/ast_to_ir.d.ts.map +1 -0
- package/dist/src/ast_to_ir.js +834 -0
- package/dist/src/ast_to_ir.js.map +1 -0
- package/dist/src/builtins.d.ts +18 -0
- package/dist/src/builtins.d.ts.map +1 -0
- package/dist/src/builtins.js +1105 -0
- package/dist/src/builtins.js.map +1 -0
- package/dist/src/comparison.d.ts +28 -0
- package/dist/src/comparison.d.ts.map +1 -0
- package/dist/src/comparison.js +1017 -0
- package/dist/src/comparison.js.map +1 -0
- package/dist/src/compile.d.ts +22 -0
- package/dist/src/compile.d.ts.map +1 -0
- package/dist/src/compile.js +3260 -0
- package/dist/src/compile.js.map +1 -0
- package/dist/src/containers/ref.d.ts +106 -0
- package/dist/src/containers/ref.d.ts.map +1 -0
- package/dist/src/containers/ref.js +100 -0
- package/dist/src/containers/ref.js.map +1 -0
- package/dist/src/containers/sortedmap.d.ts +165 -0
- package/dist/src/containers/sortedmap.d.ts.map +1 -0
- package/dist/src/containers/sortedmap.js +237 -0
- package/dist/src/containers/sortedmap.js.map +1 -0
- package/dist/src/containers/sortedset.d.ts +185 -0
- package/dist/src/containers/sortedset.d.ts.map +1 -0
- package/dist/src/containers/sortedset.js +312 -0
- package/dist/src/containers/sortedset.js.map +1 -0
- package/dist/src/containers/variant.d.ts +131 -0
- package/dist/src/containers/variant.d.ts.map +1 -0
- package/dist/src/containers/variant.js +68 -0
- package/dist/src/containers/variant.js.map +1 -0
- package/dist/src/datetime_format/parse.d.ts +50 -0
- package/dist/src/datetime_format/parse.d.ts.map +1 -0
- package/dist/src/datetime_format/parse.js +908 -0
- package/dist/src/datetime_format/parse.js.map +1 -0
- package/dist/src/datetime_format/print.d.ts +35 -0
- package/dist/src/datetime_format/print.d.ts.map +1 -0
- package/dist/src/datetime_format/print.js +157 -0
- package/dist/src/datetime_format/print.js.map +1 -0
- package/dist/src/datetime_format/tokenize.d.ts +76 -0
- package/dist/src/datetime_format/tokenize.d.ts.map +1 -0
- package/dist/src/datetime_format/tokenize.js +271 -0
- package/dist/src/datetime_format/tokenize.js.map +1 -0
- package/dist/src/datetime_format/types.d.ts +99 -0
- package/dist/src/datetime_format/types.d.ts.map +1 -0
- package/dist/src/datetime_format/types.js +103 -0
- package/dist/src/datetime_format/types.js.map +1 -0
- package/dist/src/datetime_format/validate.d.ts +51 -0
- package/dist/src/datetime_format/validate.d.ts.map +1 -0
- package/dist/src/datetime_format/validate.js +208 -0
- package/dist/src/datetime_format/validate.js.map +1 -0
- package/dist/src/default.d.ts +21 -0
- package/dist/src/default.d.ts.map +1 -0
- package/dist/src/default.js +82 -0
- package/dist/src/default.js.map +1 -0
- package/dist/src/eastir.d.ts +33 -0
- package/dist/src/eastir.d.ts.map +1 -0
- package/dist/src/eastir.js +92 -0
- package/dist/src/eastir.js.map +1 -0
- package/dist/src/error.d.ts +13 -0
- package/dist/src/error.d.ts.map +1 -0
- package/dist/src/error.js +8 -0
- package/dist/src/error.js.map +1 -0
- package/dist/src/expr/array.d.ts +1711 -0
- package/dist/src/expr/array.d.ts.map +1 -0
- package/dist/src/expr/array.js +1805 -0
- package/dist/src/expr/array.js.map +1 -0
- package/dist/src/expr/ast.d.ts +17 -0
- package/dist/src/expr/ast.d.ts.map +1 -0
- package/dist/src/expr/ast.js +302 -0
- package/dist/src/expr/ast.js.map +1 -0
- package/dist/src/expr/blob.d.ts +141 -0
- package/dist/src/expr/blob.d.ts.map +1 -0
- package/dist/src/expr/blob.js +198 -0
- package/dist/src/expr/blob.js.map +1 -0
- package/dist/src/expr/block.d.ts +201 -0
- package/dist/src/expr/block.d.ts.map +1 -0
- package/dist/src/expr/block.js +1505 -0
- package/dist/src/expr/block.js.map +1 -0
- package/dist/src/expr/boolean.d.ts +207 -0
- package/dist/src/expr/boolean.d.ts.map +1 -0
- package/dist/src/expr/boolean.js +261 -0
- package/dist/src/expr/boolean.js.map +1 -0
- package/dist/src/expr/datetime.d.ts +544 -0
- package/dist/src/expr/datetime.d.ts.map +1 -0
- package/dist/src/expr/datetime.js +980 -0
- package/dist/src/expr/datetime.js.map +1 -0
- package/dist/src/expr/dict.d.ts +1242 -0
- package/dist/src/expr/dict.d.ts.map +1 -0
- package/dist/src/expr/dict.js +1492 -0
- package/dist/src/expr/dict.js.map +1 -0
- package/dist/src/expr/expr.d.ts +95 -0
- package/dist/src/expr/expr.d.ts.map +1 -0
- package/dist/src/expr/expr.js +171 -0
- package/dist/src/expr/expr.js.map +1 -0
- package/dist/src/expr/float.d.ts +357 -0
- package/dist/src/expr/float.d.ts.map +1 -0
- package/dist/src/expr/float.js +637 -0
- package/dist/src/expr/float.js.map +1 -0
- package/dist/src/expr/function.d.ts +46 -0
- package/dist/src/expr/function.d.ts.map +1 -0
- package/dist/src/expr/function.js +58 -0
- package/dist/src/expr/function.js.map +1 -0
- package/dist/src/expr/index.d.ts +450 -0
- package/dist/src/expr/index.d.ts.map +1 -0
- package/dist/src/expr/index.js +423 -0
- package/dist/src/expr/index.js.map +1 -0
- package/dist/src/expr/integer.d.ts +256 -0
- package/dist/src/expr/integer.d.ts.map +1 -0
- package/dist/src/expr/integer.js +311 -0
- package/dist/src/expr/integer.js.map +1 -0
- package/dist/src/expr/libs/array.d.ts +106 -0
- package/dist/src/expr/libs/array.d.ts.map +1 -0
- package/dist/src/expr/libs/array.js +140 -0
- package/dist/src/expr/libs/array.js.map +1 -0
- package/dist/src/expr/libs/blob.d.ts +42 -0
- package/dist/src/expr/libs/blob.d.ts.map +1 -0
- package/dist/src/expr/libs/blob.js +70 -0
- package/dist/src/expr/libs/blob.js.map +1 -0
- package/dist/src/expr/libs/datetime.d.ts +479 -0
- package/dist/src/expr/libs/datetime.d.ts.map +1 -0
- package/dist/src/expr/libs/datetime.js +624 -0
- package/dist/src/expr/libs/datetime.js.map +1 -0
- package/dist/src/expr/libs/dict.d.ts +66 -0
- package/dist/src/expr/libs/dict.d.ts.map +1 -0
- package/dist/src/expr/libs/dict.js +77 -0
- package/dist/src/expr/libs/dict.js.map +1 -0
- package/dist/src/expr/libs/float.d.ts +299 -0
- package/dist/src/expr/libs/float.d.ts.map +1 -0
- package/dist/src/expr/libs/float.js +564 -0
- package/dist/src/expr/libs/float.js.map +1 -0
- package/dist/src/expr/libs/integer.d.ts +228 -0
- package/dist/src/expr/libs/integer.d.ts.map +1 -0
- package/dist/src/expr/libs/integer.js +398 -0
- package/dist/src/expr/libs/integer.js.map +1 -0
- package/dist/src/expr/libs/set.d.ts +59 -0
- package/dist/src/expr/libs/set.d.ts.map +1 -0
- package/dist/src/expr/libs/set.js +69 -0
- package/dist/src/expr/libs/set.js.map +1 -0
- package/dist/src/expr/libs/string.d.ts +71 -0
- package/dist/src/expr/libs/string.d.ts.map +1 -0
- package/dist/src/expr/libs/string.js +75 -0
- package/dist/src/expr/libs/string.js.map +1 -0
- package/dist/src/expr/never.d.ts +15 -0
- package/dist/src/expr/never.d.ts.map +1 -0
- package/dist/src/expr/never.js +12 -0
- package/dist/src/expr/never.js.map +1 -0
- package/dist/src/expr/null.d.ts +15 -0
- package/dist/src/expr/null.d.ts.map +1 -0
- package/dist/src/expr/null.js +12 -0
- package/dist/src/expr/null.js.map +1 -0
- package/dist/src/expr/ref.d.ts +103 -0
- package/dist/src/expr/ref.d.ts.map +1 -0
- package/dist/src/expr/ref.js +131 -0
- package/dist/src/expr/ref.js.map +1 -0
- package/dist/src/expr/regex_validation.d.ts +25 -0
- package/dist/src/expr/regex_validation.d.ts.map +1 -0
- package/dist/src/expr/regex_validation.js +130 -0
- package/dist/src/expr/regex_validation.js.map +1 -0
- package/dist/src/expr/set.d.ts +1071 -0
- package/dist/src/expr/set.d.ts.map +1 -0
- package/dist/src/expr/set.js +1137 -0
- package/dist/src/expr/set.js.map +1 -0
- package/dist/src/expr/string.d.ts +414 -0
- package/dist/src/expr/string.d.ts.map +1 -0
- package/dist/src/expr/string.js +683 -0
- package/dist/src/expr/string.js.map +1 -0
- package/dist/src/expr/struct.d.ts +48 -0
- package/dist/src/expr/struct.d.ts.map +1 -0
- package/dist/src/expr/struct.js +65 -0
- package/dist/src/expr/struct.js.map +1 -0
- package/dist/src/expr/types.d.ts +68 -0
- package/dist/src/expr/types.d.ts.map +1 -0
- package/dist/src/expr/types.js +6 -0
- package/dist/src/expr/types.js.map +1 -0
- package/dist/src/expr/variant.d.ts +137 -0
- package/dist/src/expr/variant.d.ts.map +1 -0
- package/dist/src/expr/variant.js +105 -0
- package/dist/src/expr/variant.js.map +1 -0
- package/dist/src/fuzz.d.ts +80 -0
- package/dist/src/fuzz.d.ts.map +1 -0
- package/dist/src/fuzz.js +300 -0
- package/dist/src/fuzz.js.map +1 -0
- package/dist/src/index.d.ts +21 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +21 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/internal.d.ts +36 -0
- package/dist/src/internal.d.ts.map +1 -0
- package/dist/src/internal.js +11 -0
- package/dist/src/internal.js.map +1 -0
- package/dist/src/ir.d.ts +1571 -0
- package/dist/src/ir.d.ts.map +1 -0
- package/dist/src/ir.js +56 -0
- package/dist/src/ir.js.map +1 -0
- package/dist/src/location.d.ts +48 -0
- package/dist/src/location.d.ts.map +1 -0
- package/dist/src/location.js +62 -0
- package/dist/src/location.js.map +1 -0
- package/dist/src/platform.d.ts +21 -0
- package/dist/src/platform.d.ts.map +1 -0
- package/dist/src/platform.js +8 -0
- package/dist/src/platform.js.map +1 -0
- package/dist/src/serialization/beast.d.ts +39 -0
- package/dist/src/serialization/beast.d.ts.map +1 -0
- package/dist/src/serialization/beast.js +555 -0
- package/dist/src/serialization/beast.js.map +1 -0
- package/dist/src/serialization/beast2-stream.d.ts +38 -0
- package/dist/src/serialization/beast2-stream.d.ts.map +1 -0
- package/dist/src/serialization/beast2-stream.js +665 -0
- package/dist/src/serialization/beast2-stream.js.map +1 -0
- package/dist/src/serialization/beast2.d.ts +41 -0
- package/dist/src/serialization/beast2.d.ts.map +1 -0
- package/dist/src/serialization/beast2.js +489 -0
- package/dist/src/serialization/beast2.js.map +1 -0
- package/dist/src/serialization/binary-utils.d.ts +151 -0
- package/dist/src/serialization/binary-utils.d.ts.map +1 -0
- package/dist/src/serialization/binary-utils.js +929 -0
- package/dist/src/serialization/binary-utils.js.map +1 -0
- package/dist/src/serialization/east.d.ts +84 -0
- package/dist/src/serialization/east.d.ts.map +1 -0
- package/dist/src/serialization/east.js +1802 -0
- package/dist/src/serialization/east.js.map +1 -0
- package/dist/src/serialization/index.d.ts +11 -0
- package/dist/src/serialization/index.d.ts.map +1 -0
- package/dist/src/serialization/index.js +12 -0
- package/dist/src/serialization/index.js.map +1 -0
- package/dist/src/serialization/json.d.ts +36 -0
- package/dist/src/serialization/json.d.ts.map +1 -0
- package/dist/src/serialization/json.js +849 -0
- package/dist/src/serialization/json.js.map +1 -0
- package/dist/src/type_of_type.d.ts +115 -0
- package/dist/src/type_of_type.d.ts.map +1 -0
- package/dist/src/type_of_type.js +362 -0
- package/dist/src/type_of_type.js.map +1 -0
- package/dist/src/types.d.ts +648 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +1631 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,1711 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import type { AST } from "../ast.js";
|
|
6
|
+
import { ArrayType, BooleanType, FunctionType, IntegerType, NullType, StringType, NeverType, OptionType, StructType, VariantType, SetType, FloatType, DictType, type ValueTypeOf, type SubType } from "../types.js";
|
|
7
|
+
import type { IntegerExpr } from "./integer.js";
|
|
8
|
+
import type { NullExpr } from "./null.js";
|
|
9
|
+
import { Expr, type ToExpr } from "./expr.js";
|
|
10
|
+
import type { StringExpr } from "./string.js";
|
|
11
|
+
import type { SubtypeExprOrValue, ExprType, TypeOf } from "./types.js";
|
|
12
|
+
import type { BlockBuilder } from "./block.js";
|
|
13
|
+
import type { BooleanExpr } from "./boolean.js";
|
|
14
|
+
import type { SetExpr } from "./set.js";
|
|
15
|
+
import type { FloatExpr } from "./float.js";
|
|
16
|
+
import type { DictExpr } from "./dict.js";
|
|
17
|
+
/**
|
|
18
|
+
* Expression representing mutable array values and operations.
|
|
19
|
+
*
|
|
20
|
+
* ArrayExpr provides comprehensive methods for array manipulation including element access,
|
|
21
|
+
* mutation (push/pop/sort/reverse), transformation (map/filter/reduce), searching, slicing,
|
|
22
|
+
* grouping, and aggregation. Arrays are mutable, ordered collections with zero-based indexing.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* // Array manipulation
|
|
27
|
+
* const processArray = East.function([ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr) => {
|
|
28
|
+
* $(arr.pushLast(10n)); // Mutate: add element
|
|
29
|
+
* const doubled = arr.map(($, x, i) => x.multiply(2n));
|
|
30
|
+
* $.return(doubled);
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Filtering and mapping
|
|
34
|
+
* const filterMap = East.function([ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr) => {
|
|
35
|
+
* const evens = arr.filter(($, x, i) => x.remainder(2n).equal(0n));
|
|
36
|
+
* $.return(evens.map(($, x, i) => x.add(1n)));
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // Aggregation
|
|
40
|
+
* const sumArray = East.function([ArrayType(IntegerType)], IntegerType, ($, arr) => {
|
|
41
|
+
* $.return(arr.reduce(($, acc, x, i) => acc.add(x), 0n));
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class ArrayExpr<T extends any> extends Expr<ArrayType<T>> {
|
|
46
|
+
private value_type;
|
|
47
|
+
constructor(value_type: T, ast: AST, createExpr: ToExpr);
|
|
48
|
+
/**
|
|
49
|
+
* Returns the size (length) of the array.
|
|
50
|
+
*
|
|
51
|
+
* @returns An IntegerExpr representing the number of elements
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const getSize = East.function([ArrayType(IntegerType)], IntegerType, ($, arr) => {
|
|
56
|
+
* $.return(arr.size());
|
|
57
|
+
* });
|
|
58
|
+
* const compiled = East.compile(getSize.toIR(), []);
|
|
59
|
+
* compiled([1n, 2n, 3n]); // 3n
|
|
60
|
+
* compiled([]); // 0n
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
size(): IntegerExpr;
|
|
64
|
+
/**
|
|
65
|
+
* Checks if an element exists at the specified index (i.e., if the index is in bounds).
|
|
66
|
+
*
|
|
67
|
+
* @param key - The zero-based index to check
|
|
68
|
+
* @returns A BooleanExpr that is true if the index is valid (0 <= index < size)
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const hasElement = East.function([ArrayType(IntegerType), IntegerType], BooleanType, ($, arr, index) => {
|
|
73
|
+
* $.return(arr.has(index));
|
|
74
|
+
* });
|
|
75
|
+
* const compiled = East.compile(hasElement.toIR(), []);
|
|
76
|
+
* compiled([10n, 20n, 30n], 1n); // true
|
|
77
|
+
* compiled([10n, 20n, 30n], 5n); // false
|
|
78
|
+
* compiled([10n, 20n, 30n], -1n); // false
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
has(key: Expr<IntegerType> | bigint): ExprType<BooleanType>;
|
|
82
|
+
/**
|
|
83
|
+
* Gets the element at the specified index.
|
|
84
|
+
*
|
|
85
|
+
* @param key - The zero-based index
|
|
86
|
+
* @param defaultFn - Optional function to provide a default value for out-of-bounds indices
|
|
87
|
+
* @returns An expression of the array's element type
|
|
88
|
+
*
|
|
89
|
+
* @throws East runtime error if index is out of bounds and no defaultFn is provided
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* const getElement = East.function([ArrayType(IntegerType), IntegerType], IntegerType, ($, arr, index) => {
|
|
94
|
+
* $.return(arr.get(index));
|
|
95
|
+
* });
|
|
96
|
+
* const compiled = East.compile(getElement.toIR(), []);
|
|
97
|
+
* compiled([10n, 20n, 30n], 1n); // 20n
|
|
98
|
+
* // compiled([10n, 20n, 30n], 5n) would throw error
|
|
99
|
+
*
|
|
100
|
+
* // With default value
|
|
101
|
+
* const getOrDefault = East.function([ArrayType(IntegerType), IntegerType], IntegerType, ($, arr, index) => {
|
|
102
|
+
* $.return(arr.get(index, ($, i) => -1n));
|
|
103
|
+
* });
|
|
104
|
+
* compiled = East.compile(getOrDefault.toIR(), []);
|
|
105
|
+
* compiled([10n, 20n, 30n], 5n); // -1n (out of bounds)
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
get(key: Expr<IntegerType> | bigint, defaultFn?: SubtypeExprOrValue<FunctionType<[IntegerType], T>>): ExprType<T>;
|
|
109
|
+
/**
|
|
110
|
+
* Safely gets the element at the specified index, returning an Option variant.
|
|
111
|
+
*
|
|
112
|
+
* @param key - The zero-based index
|
|
113
|
+
* @returns An OptionType expression containing .some(value) if in bounds, or .none if out of bounds
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const tryGetElement = East.function([ArrayType(IntegerType), IntegerType], OptionType(IntegerType), ($, arr, index) => {
|
|
118
|
+
* $.return(arr.tryGet(index));
|
|
119
|
+
* });
|
|
120
|
+
* const compiled = East.compile(tryGetElement.toIR(), []);
|
|
121
|
+
* compiled([10n, 20n, 30n], 1n); // {_tag: "some", some: 20n}
|
|
122
|
+
* compiled([10n, 20n, 30n], 5n); // {_tag: "none", none: null}
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
tryGet(key: Expr<IntegerType> | bigint): ExprType<OptionType<T>>;
|
|
126
|
+
/**
|
|
127
|
+
* Updates (replaces) the element at the specified index (mutates the array).
|
|
128
|
+
*
|
|
129
|
+
* @param key - The zero-based index to update
|
|
130
|
+
* @param value - The new value to set at that index
|
|
131
|
+
* @returns NullExpr (operation performed for side effect)
|
|
132
|
+
*
|
|
133
|
+
* @throws East runtime error if index is out of bounds
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const updateElement = East.function([ArrayType(IntegerType), IntegerType, IntegerType], ArrayType(IntegerType), ($, arr, index, value) => {
|
|
138
|
+
* $(arr.update(index, value)); // Mutate the array
|
|
139
|
+
* $.return(arr);
|
|
140
|
+
* });
|
|
141
|
+
* const compiled = East.compile(updateElement.toIR(), []);
|
|
142
|
+
* compiled([10n, 20n, 30n], 1n, 99n); // [10n, 99n, 30n]
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
update(key: Expr<IntegerType> | bigint, value: SubtypeExprOrValue<T>): NullExpr;
|
|
146
|
+
/** Modify an array element at index by merging it with a new value using a function accepting the new and current value. An error is thrown on missing key (index out of bounds).
|
|
147
|
+
*
|
|
148
|
+
* This is useful for patterns where you want to update an element based on its current value, e.g. incrementing a number, appending to a string, updating fields in a struct, or pushing to an array.
|
|
149
|
+
*
|
|
150
|
+
* @see {@link update} for simply replacing the value.
|
|
151
|
+
*/
|
|
152
|
+
merge<T2>(key: Expr<IntegerType> | bigint, value: Expr<T2>, updateFn: SubtypeExprOrValue<FunctionType<[T, NoInfer<T2>, IntegerType], T>>): ExprType<NullType>;
|
|
153
|
+
/**
|
|
154
|
+
* Adds an element to the end of the array (mutates the array).
|
|
155
|
+
*
|
|
156
|
+
* @param value - The value to append
|
|
157
|
+
* @returns NullExpr (operation performed for side effect)
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* const appendValue = East.function([ArrayType(IntegerType), IntegerType], ArrayType(IntegerType), ($, arr, value) => {
|
|
162
|
+
* $(arr.pushLast(value)); // Mutate the array
|
|
163
|
+
* $.return(arr);
|
|
164
|
+
* });
|
|
165
|
+
* const compiled = East.compile(appendValue.toIR(), []);
|
|
166
|
+
* compiled([1n, 2n, 3n], 4n); // [1n, 2n, 3n, 4n]
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
pushLast(value: SubtypeExprOrValue<T>): NullExpr;
|
|
170
|
+
/**
|
|
171
|
+
* Removes and returns the last element from the array (mutates the array).
|
|
172
|
+
*
|
|
173
|
+
* @returns An expression of the array's element type containing the removed value
|
|
174
|
+
*
|
|
175
|
+
* @throws East runtime error if the array is empty
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* const removeLastValue = East.function([ArrayType(IntegerType)], IntegerType, ($, arr) => {
|
|
180
|
+
* $.return(arr.popLast());
|
|
181
|
+
* });
|
|
182
|
+
* const compiled = East.compile(removeLastValue.toIR(), []);
|
|
183
|
+
* compiled([1n, 2n, 3n]); // 3n (arr is now [1n, 2n])
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
popLast(): ExprType<T>;
|
|
187
|
+
/**
|
|
188
|
+
* Adds an element to the beginning of the array (mutates the array).
|
|
189
|
+
*
|
|
190
|
+
* @param value - The value to prepend
|
|
191
|
+
* @returns NullExpr (operation performed for side effect)
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* const prependValue = East.function([ArrayType(IntegerType), IntegerType], ArrayType(IntegerType), ($, arr, value) => {
|
|
196
|
+
* $(arr.pushFirst(value)); // Mutate the array
|
|
197
|
+
* $.return(arr);
|
|
198
|
+
* });
|
|
199
|
+
* const compiled = East.compile(prependValue.toIR(), []);
|
|
200
|
+
* compiled([1n, 2n, 3n], 0n); // [0n, 1n, 2n, 3n]
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
pushFirst(value: SubtypeExprOrValue<T>): NullExpr;
|
|
204
|
+
/**
|
|
205
|
+
* Removes and returns the first element from the array (mutates the array).
|
|
206
|
+
*
|
|
207
|
+
* @returns An expression of the array's element type containing the removed value
|
|
208
|
+
*
|
|
209
|
+
* @throws East runtime error if the array is empty
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* const removeFirstValue = East.function([ArrayType(IntegerType)], IntegerType, ($, arr) => {
|
|
214
|
+
* $.return(arr.popFirst());
|
|
215
|
+
* });
|
|
216
|
+
* const compiled = East.compile(removeFirstValue.toIR(), []);
|
|
217
|
+
* compiled([1n, 2n, 3n]); // 1n (arr is now [2n, 3n])
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
popFirst(): ExprType<T>;
|
|
221
|
+
/**
|
|
222
|
+
* Appends all elements from another array to this array (mutates the array).
|
|
223
|
+
*
|
|
224
|
+
* @param array - The array whose elements will be appended
|
|
225
|
+
* @returns NullExpr (operation performed for side effect)
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```ts
|
|
229
|
+
* const appendArray = East.function([ArrayType(IntegerType), ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr1, arr2) => {
|
|
230
|
+
* $(arr1.append(arr2)); // Mutate arr1
|
|
231
|
+
* $.return(arr1);
|
|
232
|
+
* });
|
|
233
|
+
* const compiled = East.compile(appendArray.toIR(), []);
|
|
234
|
+
* compiled([1n, 2n], [3n, 4n]); // [1n, 2n, 3n, 4n]
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
append(array: SubtypeExprOrValue<ArrayType<T>>): ExprType<NullType>;
|
|
238
|
+
/**
|
|
239
|
+
* Prepends all elements from another array to this array (mutates the array).
|
|
240
|
+
*
|
|
241
|
+
* @param array - The array whose elements will be prepended
|
|
242
|
+
* @returns NullExpr (operation performed for side effect)
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* const prependArray = East.function([ArrayType(IntegerType), ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr1, arr2) => {
|
|
247
|
+
* $(arr1.prepend(arr2)); // Mutate arr1
|
|
248
|
+
* $.return(arr1);
|
|
249
|
+
* });
|
|
250
|
+
* const compiled = East.compile(prependArray.toIR(), []);
|
|
251
|
+
* compiled([3n, 4n], [1n, 2n]); // [1n, 2n, 3n, 4n]
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
prepend(array: SubtypeExprOrValue<ArrayType<T>>): ExprType<NullType>;
|
|
255
|
+
/**
|
|
256
|
+
* Merges all elements from another array into this array using a merge function.
|
|
257
|
+
*
|
|
258
|
+
* @param array - The array to merge from
|
|
259
|
+
* @param mergeFn - Function taking (currentValue, otherValue, index) and returning the merged value
|
|
260
|
+
* @returns Null (mutates the array in place)
|
|
261
|
+
*
|
|
262
|
+
* @throws East runtime error if the other array has more elements than this array
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* const mergeArrays = East.function([ArrayType(IntegerType), ArrayType(IntegerType)], NullType, ($, arr1, arr2) => {
|
|
267
|
+
* arr1.mergeAll(arr2, ($, current, other, index) => current.add(other));
|
|
268
|
+
* $.return(null);
|
|
269
|
+
* });
|
|
270
|
+
* const compiled = East.compile(mergeArrays.toIR(), []);
|
|
271
|
+
* const arr1 = [10n, 20n, 30n];
|
|
272
|
+
* const arr2 = [1n, 2n, 3n];
|
|
273
|
+
* compiled(arr1, arr2); // null (arr1 is now [11n, 22n, 33n])
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* // Combining strings
|
|
279
|
+
* const mergeStrings = East.function([ArrayType(StringType), ArrayType(StringType)], ArrayType(StringType), ($, arr1, arr2) => {
|
|
280
|
+
* arr1.mergeAll(arr2, ($, current, other, index) => current.concat(" + ").concat(other));
|
|
281
|
+
* $.return(arr1);
|
|
282
|
+
* });
|
|
283
|
+
* const compiled = East.compile(mergeStrings.toIR(), []);
|
|
284
|
+
* compiled(["a", "b"], ["x", "y"]); // ["a + x", "b + y"]
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
mergeAll<T2>(array: Expr<ArrayType<T2>>, mergeFn: SubtypeExprOrValue<FunctionType<[T, NoInfer<T2>, IntegerType], T>>): ExprType<NullType>;
|
|
288
|
+
/**
|
|
289
|
+
* Clears all elements from the array, making it empty.
|
|
290
|
+
*
|
|
291
|
+
* @returns Null (mutates the array in place)
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```ts
|
|
295
|
+
* const clearArray = East.function([ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr) => {
|
|
296
|
+
* arr.clear();
|
|
297
|
+
* $.return(arr);
|
|
298
|
+
* });
|
|
299
|
+
* const compiled = East.compile(clearArray.toIR(), []);
|
|
300
|
+
* compiled([1n, 2n, 3n]); // []
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
clear(): NullExpr;
|
|
304
|
+
/**
|
|
305
|
+
* Sorts the array in place, re-ordering it in memory.
|
|
306
|
+
*
|
|
307
|
+
* @param by - Optional projection function to determine sort order (defaults to sorting by the values themselves)
|
|
308
|
+
* @returns Null (mutates the array in place)
|
|
309
|
+
*
|
|
310
|
+
* @remarks
|
|
311
|
+
* The optional `by` function can project values to determine sort order (e.g., sort by a specific field).
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```ts
|
|
315
|
+
* const sortNumbers = East.function([ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr) => {
|
|
316
|
+
* arr.sortInPlace();
|
|
317
|
+
* $.return(arr);
|
|
318
|
+
* });
|
|
319
|
+
* const compiled = East.compile(sortNumbers.toIR(), []);
|
|
320
|
+
* compiled([3n, 1n, 4n, 1n, 5n]); // [1n, 1n, 3n, 4n, 5n]
|
|
321
|
+
* ```
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```ts
|
|
325
|
+
* // Sorting structs by a field
|
|
326
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
327
|
+
* const sortByAge = East.function([ArrayType(PersonType)], ArrayType(PersonType), ($, people) => {
|
|
328
|
+
* people.sortInPlace(($, p) => p.age);
|
|
329
|
+
* $.return(people);
|
|
330
|
+
* });
|
|
331
|
+
* const compiled = East.compile(sortByAge.toIR(), []);
|
|
332
|
+
* compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }]);
|
|
333
|
+
* // [{ name: "Bob", age: 25n }, { name: "Alice", age: 30n }]
|
|
334
|
+
* ```
|
|
335
|
+
*
|
|
336
|
+
* @see {@link sort} to produce a new sorted array instead of sorting in place.
|
|
337
|
+
*/
|
|
338
|
+
sortInPlace(by?: SubtypeExprOrValue<FunctionType<[T], undefined>>): NullExpr;
|
|
339
|
+
/**
|
|
340
|
+
* Produces a new array with the values sorted.
|
|
341
|
+
*
|
|
342
|
+
* @param by - Optional projection function to determine sort order (defaults to sorting by the values themselves)
|
|
343
|
+
* @returns A new ArrayExpr containing the sorted elements
|
|
344
|
+
*
|
|
345
|
+
* @remarks
|
|
346
|
+
* The optional `by` function can project values to determine sort order (e.g., sort by a specific field).
|
|
347
|
+
* This method does not mutate the original array.
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```ts
|
|
351
|
+
* const sortNumbers = East.function([ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr) => {
|
|
352
|
+
* $.return(arr.sort());
|
|
353
|
+
* });
|
|
354
|
+
* const compiled = East.compile(sortNumbers.toIR(), []);
|
|
355
|
+
* compiled([3n, 1n, 4n, 1n, 5n]); // [1n, 1n, 3n, 4n, 5n]
|
|
356
|
+
* ```
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```ts
|
|
360
|
+
* // Sorting structs by a field (descending)
|
|
361
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
362
|
+
* const sortByAgeDesc = East.function([ArrayType(PersonType)], ArrayType(PersonType), ($, people) => {
|
|
363
|
+
* $.return(people.sort(($, p) => p.age.negate()));
|
|
364
|
+
* });
|
|
365
|
+
* const compiled = East.compile(sortByAgeDesc.toIR(), []);
|
|
366
|
+
* compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }]);
|
|
367
|
+
* // [{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }]
|
|
368
|
+
* ```
|
|
369
|
+
*
|
|
370
|
+
* @see {@link sortInPlace} to sort the array in place.
|
|
371
|
+
*/
|
|
372
|
+
sort(by?: SubtypeExprOrValue<FunctionType<[T], undefined>>): ArrayExpr<T>;
|
|
373
|
+
/**
|
|
374
|
+
* Reverses the array in place.
|
|
375
|
+
*
|
|
376
|
+
* @returns Null (mutates the array in place)
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```ts
|
|
380
|
+
* const reverseArray = East.function([ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr) => {
|
|
381
|
+
* arr.reverseInPlace();
|
|
382
|
+
* $.return(arr);
|
|
383
|
+
* });
|
|
384
|
+
* const compiled = East.compile(reverseArray.toIR(), []);
|
|
385
|
+
* compiled([1n, 2n, 3n, 4n, 5n]); // [5n, 4n, 3n, 2n, 1n]
|
|
386
|
+
* ```
|
|
387
|
+
*
|
|
388
|
+
* @see {@link reverse} to produce a new reversed array instead of reversing in place.
|
|
389
|
+
*/
|
|
390
|
+
reverseInPlace(): NullExpr;
|
|
391
|
+
/**
|
|
392
|
+
* Produces a new array with the values in reverse order.
|
|
393
|
+
*
|
|
394
|
+
* @returns A new ArrayExpr with elements in reverse order
|
|
395
|
+
*
|
|
396
|
+
* @remarks
|
|
397
|
+
* This method does not mutate the original array.
|
|
398
|
+
*
|
|
399
|
+
* @example
|
|
400
|
+
* ```ts
|
|
401
|
+
* const reverseArray = East.function([ArrayType(StringType)], ArrayType(StringType), ($, arr) => {
|
|
402
|
+
* $.return(arr.reverse());
|
|
403
|
+
* });
|
|
404
|
+
* const compiled = East.compile(reverseArray.toIR(), []);
|
|
405
|
+
* compiled(["a", "b", "c"]); // ["c", "b", "a"]
|
|
406
|
+
* ```
|
|
407
|
+
*
|
|
408
|
+
* @see {@link reverseInPlace} to reverse the array in place.
|
|
409
|
+
*/
|
|
410
|
+
reverse(): ArrayExpr<T>;
|
|
411
|
+
/**
|
|
412
|
+
* Checks if the array is sorted in ascending order.
|
|
413
|
+
*
|
|
414
|
+
* @param by - Optional projection function to determine sort order (defaults to sorting by the values themselves)
|
|
415
|
+
* @returns A BooleanExpr indicating whether the array is sorted
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```ts
|
|
419
|
+
* const checkSorted = East.function([ArrayType(IntegerType)], BooleanType, ($, arr) => {
|
|
420
|
+
* $.return(arr.isSorted());
|
|
421
|
+
* });
|
|
422
|
+
* const compiled = East.compile(checkSorted.toIR(), []);
|
|
423
|
+
* compiled([1n, 2n, 3n, 4n]); // true
|
|
424
|
+
* compiled([1n, 3n, 2n, 4n]); // false
|
|
425
|
+
* ```
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```ts
|
|
429
|
+
* // Checking if sorted by a specific field
|
|
430
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
431
|
+
* const checkSortedByAge = East.function([ArrayType(PersonType)], BooleanType, ($, people) => {
|
|
432
|
+
* $.return(people.isSorted(($, p) => p.age));
|
|
433
|
+
* });
|
|
434
|
+
* const compiled = East.compile(checkSortedByAge.toIR(), []);
|
|
435
|
+
* compiled([{ name: "Bob", age: 25n }, { name: "Alice", age: 30n }]); // true
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
isSorted(by?: SubtypeExprOrValue<FunctionType<[T], undefined>>): BooleanExpr;
|
|
439
|
+
/**
|
|
440
|
+
* Returns the index of the first element in a sorted array that is >= the given value (binary search).
|
|
441
|
+
*
|
|
442
|
+
* @param value - The value to search for
|
|
443
|
+
* @param by - Optional projection function used for sorting (must match the array's sort order)
|
|
444
|
+
* @returns An IntegerExpr representing the index (may be out of bounds if all elements are less)
|
|
445
|
+
*
|
|
446
|
+
* @remarks
|
|
447
|
+
* This method assumes the array is already sorted. If all elements are less than the given value,
|
|
448
|
+
* the returned index will equal the array size (out-of-bounds).
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* ```ts
|
|
452
|
+
* const findFirst = East.function([ArrayType(IntegerType), IntegerType], IntegerType, ($, arr, value) => {
|
|
453
|
+
* $.return(arr.findSortedFirst(value));
|
|
454
|
+
* });
|
|
455
|
+
* const compiled = East.compile(findFirst.toIR(), []);
|
|
456
|
+
* compiled([1n, 3n, 5n, 7n, 9n], 5n); // 2n (index of 5)
|
|
457
|
+
* compiled([1n, 3n, 5n, 7n, 9n], 4n); // 2n (index where 4 would be inserted)
|
|
458
|
+
* compiled([1n, 3n, 5n, 7n, 9n], 10n); // 5n (out of bounds)
|
|
459
|
+
* ```
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ```ts
|
|
463
|
+
* // Using with projection function
|
|
464
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
465
|
+
* const findByAge = East.function([ArrayType(PersonType), IntegerType], IntegerType, ($, people, age) => {
|
|
466
|
+
* $.return(people.findSortedFirst(age, ($, p) => p.age));
|
|
467
|
+
* });
|
|
468
|
+
* const compiled = East.compile(findByAge.toIR(), []);
|
|
469
|
+
* // Assumes people array is sorted by age
|
|
470
|
+
* compiled([{ name: "Bob", age: 25n }, { name: "Alice", age: 30n }], 28n); // 1n
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
findSortedFirst<T2>(value: T2, by?: SubtypeExprOrValue<FunctionType<[T], TypeOf<NoInfer<T2>>>>): IntegerExpr;
|
|
474
|
+
/**
|
|
475
|
+
* Returns the index of the last element in a sorted array that is <= the given value (binary search).
|
|
476
|
+
*
|
|
477
|
+
* @param value - The value to search for
|
|
478
|
+
* @param by - Optional projection function used for sorting (must match the array's sort order)
|
|
479
|
+
* @returns An IntegerExpr representing the index (may be -1 if all elements are greater)
|
|
480
|
+
*
|
|
481
|
+
* @remarks
|
|
482
|
+
* This method assumes the array is already sorted. If all elements are greater than the given value,
|
|
483
|
+
* the returned index will be -1 (out-of-bounds).
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* ```ts
|
|
487
|
+
* const findLast = East.function([ArrayType(IntegerType), IntegerType], IntegerType, ($, arr, value) => {
|
|
488
|
+
* $.return(arr.findSortedLast(value));
|
|
489
|
+
* });
|
|
490
|
+
* const compiled = East.compile(findLast.toIR(), []);
|
|
491
|
+
* compiled([1n, 3n, 5n, 7n, 9n], 5n); // 2n (index of 5)
|
|
492
|
+
* compiled([1n, 3n, 5n, 7n, 9n], 6n); // 2n (index of last element <= 6)
|
|
493
|
+
* compiled([1n, 3n, 5n, 7n, 9n], 0n); // -1n (all elements are greater)
|
|
494
|
+
* ```
|
|
495
|
+
*/
|
|
496
|
+
findSortedLast<T2>(value: T2, by?: SubtypeExprOrValue<FunctionType<[T], TypeOf<NoInfer<T2>>>>): IntegerExpr;
|
|
497
|
+
/**
|
|
498
|
+
* Returns the start and end indices of elements in a sorted array that equal the given value (binary search).
|
|
499
|
+
*
|
|
500
|
+
* @param value - The value to search for
|
|
501
|
+
* @param by - Optional projection function used for sorting (must match the array's sort order)
|
|
502
|
+
* @returns A struct with `start` and `end` indices (exclusive end, may be out of bounds if not found)
|
|
503
|
+
*
|
|
504
|
+
* @remarks
|
|
505
|
+
* This method assumes the array is already sorted. If no elements match, the range will have zero size.
|
|
506
|
+
* The indices may be out-of-bounds if no elements are found.
|
|
507
|
+
*
|
|
508
|
+
* @example
|
|
509
|
+
* ```ts
|
|
510
|
+
* const findRange = East.function([ArrayType(IntegerType), IntegerType], StructType({ start: IntegerType, end: IntegerType }), ($, arr, value) => {
|
|
511
|
+
* $.return(arr.findSortedRange(value));
|
|
512
|
+
* });
|
|
513
|
+
* const compiled = East.compile(findRange.toIR(), []);
|
|
514
|
+
* compiled([1n, 3n, 5n, 5n, 5n, 7n, 9n], 5n); // { start: 2n, end: 5n }
|
|
515
|
+
* compiled([1n, 3n, 5n, 7n, 9n], 4n); // { start: 2n, end: 2n } (not found)
|
|
516
|
+
* ```
|
|
517
|
+
*/
|
|
518
|
+
findSortedRange<T2>(value: T2, by?: SubtypeExprOrValue<FunctionType<[T], TypeOf<NoInfer<T2>>>>): ExprType<StructType<{
|
|
519
|
+
start: IntegerType;
|
|
520
|
+
end: IntegerType;
|
|
521
|
+
}>>;
|
|
522
|
+
/**
|
|
523
|
+
* Extracts a slice of the array from start to end index (exclusive).
|
|
524
|
+
*
|
|
525
|
+
* @param start - The starting index (inclusive)
|
|
526
|
+
* @param end - The ending index (exclusive)
|
|
527
|
+
* @returns A new ArrayExpr containing the sliced elements
|
|
528
|
+
*
|
|
529
|
+
* @remarks
|
|
530
|
+
* This method does not mutate the original array.
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* ```ts
|
|
534
|
+
* const sliceArray = East.function([ArrayType(IntegerType), IntegerType, IntegerType], ArrayType(IntegerType), ($, arr, start, end) => {
|
|
535
|
+
* $.return(arr.slice(start, end));
|
|
536
|
+
* });
|
|
537
|
+
* const compiled = East.compile(sliceArray.toIR(), []);
|
|
538
|
+
* compiled([10n, 20n, 30n, 40n, 50n], 1n, 4n); // [20n, 30n, 40n]
|
|
539
|
+
* compiled([10n, 20n, 30n, 40n, 50n], 0n, 2n); // [10n, 20n]
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
slice(start: SubtypeExprOrValue<IntegerType>, end: SubtypeExprOrValue<IntegerType>): ArrayExpr<T>;
|
|
543
|
+
/**
|
|
544
|
+
* Creates a new array containing values from this array followed by values of the other array.
|
|
545
|
+
*
|
|
546
|
+
* @param other - The array to concatenate
|
|
547
|
+
* @returns A new ArrayExpr with combined elements
|
|
548
|
+
*
|
|
549
|
+
* @remarks
|
|
550
|
+
* This method does not mutate the original arrays.
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* ```ts
|
|
554
|
+
* const concatArrays = East.function([ArrayType(IntegerType), ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr1, arr2) => {
|
|
555
|
+
* $.return(arr1.concat(arr2));
|
|
556
|
+
* });
|
|
557
|
+
* const compiled = East.compile(concatArrays.toIR(), []);
|
|
558
|
+
* compiled([1n, 2n, 3n], [4n, 5n]); // [1n, 2n, 3n, 4n, 5n]
|
|
559
|
+
* ```
|
|
560
|
+
*/
|
|
561
|
+
concat(other: SubtypeExprOrValue<ArrayType<T>>): ArrayExpr<T>;
|
|
562
|
+
/**
|
|
563
|
+
* Returns a new array containing values at the specified indices.
|
|
564
|
+
*
|
|
565
|
+
* @param keys - An array of indices to retrieve
|
|
566
|
+
* @param onMissing - Optional function to provide default values for out-of-bounds indices
|
|
567
|
+
* @returns A new ArrayExpr with elements at the specified indices
|
|
568
|
+
*
|
|
569
|
+
* @throws East runtime error if an index is out of bounds and no onMissing function is provided
|
|
570
|
+
*
|
|
571
|
+
* @example
|
|
572
|
+
* ```ts
|
|
573
|
+
* const getMultiple = East.function([ArrayType(StringType), ArrayType(IntegerType)], ArrayType(StringType), ($, arr, indices) => {
|
|
574
|
+
* $.return(arr.getKeys(indices));
|
|
575
|
+
* });
|
|
576
|
+
* const compiled = East.compile(getMultiple.toIR(), []);
|
|
577
|
+
* compiled(["a", "b", "c", "d"], [0n, 2n, 3n]); // ["a", "c", "d"]
|
|
578
|
+
* ```
|
|
579
|
+
*
|
|
580
|
+
* @example
|
|
581
|
+
* ```ts
|
|
582
|
+
* // With default for missing keys
|
|
583
|
+
* const getWithDefault = East.function([ArrayType(IntegerType), ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr, indices) => {
|
|
584
|
+
* $.return(arr.getKeys(indices, ($, key) => -1n));
|
|
585
|
+
* });
|
|
586
|
+
* const compiled = East.compile(getWithDefault.toIR(), []);
|
|
587
|
+
* compiled([10n, 20n, 30n], [1n, 5n, 2n]); // [20n, -1n, 30n]
|
|
588
|
+
* ```
|
|
589
|
+
*/
|
|
590
|
+
getKeys(keys: SubtypeExprOrValue<ArrayType<IntegerType>>, onMissing?: SubtypeExprOrValue<FunctionType<[IntegerType], T>>): ArrayExpr<T>;
|
|
591
|
+
/**
|
|
592
|
+
* Executes a function for each element in the array.
|
|
593
|
+
*
|
|
594
|
+
* @param fn - Function taking (element, index) to execute for each entry
|
|
595
|
+
* @returns Null
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* ```ts
|
|
599
|
+
* const log = East.platform(FunctionType([StringType], NullType));
|
|
600
|
+
* const forEachExample = East.function([ArrayType(IntegerType)], NullType, ($, arr) => {
|
|
601
|
+
* arr.forEach(($, elem, index) => {
|
|
602
|
+
* log(Expr.str`Index ${index}: ${elem}`);
|
|
603
|
+
* });
|
|
604
|
+
* $.return(null);
|
|
605
|
+
* });
|
|
606
|
+
* const compiled = East.compile(forEachExample.toIR(), [log.implement(console.log)]);
|
|
607
|
+
* compiled([10n, 20n, 30n]);
|
|
608
|
+
* // Logs: "Index 0: 10", "Index 1: 20", "Index 2: 30"
|
|
609
|
+
* ```
|
|
610
|
+
*/
|
|
611
|
+
forEach(fn: SubtypeExprOrValue<FunctionType<[T, IntegerType], undefined>>): NullExpr;
|
|
612
|
+
/**
|
|
613
|
+
* Creates a shallow copy of the array.
|
|
614
|
+
*
|
|
615
|
+
* @returns A new ArrayExpr with the same elements
|
|
616
|
+
*
|
|
617
|
+
* @remarks
|
|
618
|
+
* Only the top-level array is cloned. Deeply nested structures (e.g., arrays of arrays) share references.
|
|
619
|
+
*
|
|
620
|
+
* @example
|
|
621
|
+
* ```ts
|
|
622
|
+
* const copyArray = East.function([ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr) => {
|
|
623
|
+
* const copy = arr.copy();
|
|
624
|
+
* copy.pushLast(99n);
|
|
625
|
+
* $.return(copy);
|
|
626
|
+
* });
|
|
627
|
+
* const compiled = East.compile(copyArray.toIR(), []);
|
|
628
|
+
* const original = [1n, 2n, 3n];
|
|
629
|
+
* compiled(original); // [1n, 2n, 3n, 99n]
|
|
630
|
+
* // original is unchanged: [1n, 2n, 3n]
|
|
631
|
+
* ```
|
|
632
|
+
*/
|
|
633
|
+
copy(): ArrayExpr<T>;
|
|
634
|
+
/**
|
|
635
|
+
* Maps each element to a new value using a transform function.
|
|
636
|
+
*
|
|
637
|
+
* @param fn - Function taking (element, index) and returning the transformed value
|
|
638
|
+
* @returns A new ArrayExpr with transformed elements
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* ```ts
|
|
642
|
+
* const doubleNumbers = East.function([ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr) => {
|
|
643
|
+
* $.return(arr.map(($, x, i) => x.multiply(2n)));
|
|
644
|
+
* });
|
|
645
|
+
* const compiled = East.compile(doubleNumbers.toIR(), []);
|
|
646
|
+
* compiled([1n, 2n, 3n, 4n]); // [2n, 4n, 6n, 8n]
|
|
647
|
+
* ```
|
|
648
|
+
*
|
|
649
|
+
* @example
|
|
650
|
+
* ```ts
|
|
651
|
+
* // Mapping to a different type
|
|
652
|
+
* const numbersToStrings = East.function([ArrayType(IntegerType)], ArrayType(StringType), ($, arr) => {
|
|
653
|
+
* $.return(arr.map(($, x, i) => Expr.str`Number: ${x}`));
|
|
654
|
+
* });
|
|
655
|
+
* const compiled = East.compile(numbersToStrings.toIR(), []);
|
|
656
|
+
* compiled([10n, 20n]); // ["Number: 10", "Number: 20"]
|
|
657
|
+
* ```
|
|
658
|
+
*
|
|
659
|
+
* @example
|
|
660
|
+
* ```ts
|
|
661
|
+
* // Mapping structs to extract a field
|
|
662
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
663
|
+
* const getNames = East.function([ArrayType(PersonType)], ArrayType(StringType), ($, people) => {
|
|
664
|
+
* $.return(people.map(($, p, i) => p.name));
|
|
665
|
+
* });
|
|
666
|
+
* const compiled = East.compile(getNames.toIR(), []);
|
|
667
|
+
* compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }]); // ["Alice", "Bob"]
|
|
668
|
+
* ```
|
|
669
|
+
*/
|
|
670
|
+
map<T2>(fn: Expr<FunctionType<[T, IntegerType], T2>>): ArrayExpr<T2>;
|
|
671
|
+
map<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, k: ExprType<IntegerType>) => any)>(fn: F): ArrayExpr<TypeOf<ReturnType<F>>>;
|
|
672
|
+
/**
|
|
673
|
+
* Filters array elements using a predicate function.
|
|
674
|
+
*
|
|
675
|
+
* @param predicate - Function taking (element, index) and returning true to keep the element
|
|
676
|
+
* @returns A new ArrayExpr containing only elements for which the predicate returned true
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* ```ts
|
|
680
|
+
* const filterEven = East.function([ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr) => {
|
|
681
|
+
* $.return(arr.filter(($, x, i) => x.modulo(2n).equal(0n)));
|
|
682
|
+
* });
|
|
683
|
+
* const compiled = East.compile(filterEven.toIR(), []);
|
|
684
|
+
* compiled([1n, 2n, 3n, 4n, 5n, 6n]); // [2n, 4n, 6n]
|
|
685
|
+
* ```
|
|
686
|
+
*
|
|
687
|
+
* @example
|
|
688
|
+
* ```ts
|
|
689
|
+
* // Filter by index
|
|
690
|
+
* const filterFirstThree = East.function([ArrayType(StringType)], ArrayType(StringType), ($, arr) => {
|
|
691
|
+
* $.return(arr.filter(($, elem, index) => index.lessThan(3n)));
|
|
692
|
+
* });
|
|
693
|
+
* const compiled = East.compile(filterFirstThree.toIR(), []);
|
|
694
|
+
* compiled(["a", "b", "c", "d", "e"]); // ["a", "b", "c"]
|
|
695
|
+
* ```
|
|
696
|
+
*
|
|
697
|
+
* @example
|
|
698
|
+
* ```ts
|
|
699
|
+
* // Filter structs by field
|
|
700
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
701
|
+
* const filterAdults = East.function([ArrayType(PersonType)], ArrayType(PersonType), ($, people) => {
|
|
702
|
+
* $.return(people.filter(($, p, i) => p.age.greaterOrEqual(18n)));
|
|
703
|
+
* });
|
|
704
|
+
* const compiled = East.compile(filterAdults.toIR(), []);
|
|
705
|
+
* compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 15n }]); // [{ name: "Alice", age: 30n }]
|
|
706
|
+
* ```
|
|
707
|
+
*/
|
|
708
|
+
filter(predicate: SubtypeExprOrValue<FunctionType<[T, IntegerType], BooleanType>>): Expr<ArrayType<T>>;
|
|
709
|
+
/**
|
|
710
|
+
* Filters and maps array elements in a single pass using an Option-returning function.
|
|
711
|
+
*
|
|
712
|
+
* @param fn - Function taking (element, index) and returning Option<T2> (.some(value) to include, .none to exclude)
|
|
713
|
+
* @returns A new ArrayExpr containing only the mapped values from .some() results
|
|
714
|
+
*
|
|
715
|
+
* @remarks
|
|
716
|
+
* This is more efficient than using `filter` followed by `map`, as it only iterates the array once.
|
|
717
|
+
*
|
|
718
|
+
* @example
|
|
719
|
+
* ```ts
|
|
720
|
+
* const parseSafe = East.function([ArrayType(StringType)], ArrayType(IntegerType), ($, arr) => {
|
|
721
|
+
* $.return(arr.filterMap(($, str, i) => {
|
|
722
|
+
* const num = str.toInteger();
|
|
723
|
+
* return $.if(num.isNone(), () => Expr.none, () => Expr.some(num.unwrap()));
|
|
724
|
+
* }));
|
|
725
|
+
* });
|
|
726
|
+
* const compiled = East.compile(parseSafe.toIR(), []);
|
|
727
|
+
* compiled(["10", "not-a-number", "20", "30"]); // [10n, 20n, 30n]
|
|
728
|
+
* ```
|
|
729
|
+
*
|
|
730
|
+
* @example
|
|
731
|
+
* ```ts
|
|
732
|
+
* // Extract and transform field if condition met
|
|
733
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType, active: BooleanType });
|
|
734
|
+
* const getActiveNames = East.function([ArrayType(PersonType)], ArrayType(StringType), ($, people) => {
|
|
735
|
+
* $.return(people.filterMap(($, p, i) =>
|
|
736
|
+
* $.if(p.active, () => Expr.some(p.name.toUpperCase()), () => Expr.none)
|
|
737
|
+
* ));
|
|
738
|
+
* });
|
|
739
|
+
* const compiled = East.compile(getActiveNames.toIR(), []);
|
|
740
|
+
* compiled([
|
|
741
|
+
* { name: "Alice", age: 30n, active: true },
|
|
742
|
+
* { name: "Bob", age: 25n, active: false },
|
|
743
|
+
* { name: "Carol", age: 35n, active: true }
|
|
744
|
+
* ]); // ["ALICE", "CAROL"]
|
|
745
|
+
* ```
|
|
746
|
+
*
|
|
747
|
+
* @see {@link filter} to only filter values, and {@link map} to only map values.
|
|
748
|
+
*/
|
|
749
|
+
filterMap<T2>(fn: Expr<FunctionType<[T, IntegerType], OptionType<T2>>>): ArrayExpr<T2>;
|
|
750
|
+
filterMap<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, k: ExprType<IntegerType>) => any)>(fn: F): ArrayExpr<TypeOf<ReturnType<F>> extends VariantType<infer U> ? "some" extends keyof U ? U["some"] : NeverType : NeverType>;
|
|
751
|
+
/**
|
|
752
|
+
* Find the first element where the mapping function returns `some(value)`, and return that value wrapped in an Option.
|
|
753
|
+
*
|
|
754
|
+
* The supplied function must return an Option type. This method stops iterating as soon as the first `some` value is found,
|
|
755
|
+
* making it efficient for early termination searches.
|
|
756
|
+
*
|
|
757
|
+
* Returns `none` if no element produces a `some` value, or `some(value)` with the first mapped result.
|
|
758
|
+
*
|
|
759
|
+
* @param fn - Function that maps each element to an Option type
|
|
760
|
+
* @returns Option containing the first successfully mapped value, or `none` if none found
|
|
761
|
+
*
|
|
762
|
+
* @see {@link filterMap} to collect all mapped values that return `some` (scans entire array).
|
|
763
|
+
*/
|
|
764
|
+
firstMap<T2>(fn: Expr<FunctionType<[T, IntegerType], OptionType<T2>>>): ExprType<OptionType<T2>>;
|
|
765
|
+
firstMap<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, k: ExprType<IntegerType>) => any)>(fn: F): ExprType<TypeOf<ReturnType<F>>>;
|
|
766
|
+
/**
|
|
767
|
+
* Finds the index of the first element equal to the given value.
|
|
768
|
+
*
|
|
769
|
+
* @param value - The value to search for
|
|
770
|
+
* @param by - Optional projection function to transform elements before comparison
|
|
771
|
+
* @returns Option containing the index of the first matching element, or .none if not found
|
|
772
|
+
*
|
|
773
|
+
* @example
|
|
774
|
+
* ```ts
|
|
775
|
+
* const findValue = East.function([ArrayType(IntegerType), IntegerType], OptionType(IntegerType), ($, arr, val) => {
|
|
776
|
+
* $.return(arr.findFirst(val));
|
|
777
|
+
* });
|
|
778
|
+
* const compiled = East.compile(findValue.toIR(), []);
|
|
779
|
+
* compiled([10n, 20n, 30n, 20n], 20n); // .some(1n)
|
|
780
|
+
* compiled([10n, 20n, 30n], 99n); // .none
|
|
781
|
+
* ```
|
|
782
|
+
*
|
|
783
|
+
* @example
|
|
784
|
+
* ```ts
|
|
785
|
+
* // Finding by a projected field
|
|
786
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
787
|
+
* const findByAge = East.function([ArrayType(PersonType), IntegerType], OptionType(IntegerType), ($, people, targetAge) => {
|
|
788
|
+
* $.return(people.findFirst(targetAge, ($, p, i) => p.age));
|
|
789
|
+
* });
|
|
790
|
+
* const compiled = East.compile(findByAge.toIR(), []);
|
|
791
|
+
* compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }], 25n); // .some(1n)
|
|
792
|
+
* ```
|
|
793
|
+
*
|
|
794
|
+
* @see {@link findAll} to find all matching elements (returns array of indices).
|
|
795
|
+
* @see {@link findSortedFirst} for binary search on sorted arrays (returns index directly, may be out of bounds).
|
|
796
|
+
* @see {@link firstMap} for predicate-based searches that can transform results.
|
|
797
|
+
*/
|
|
798
|
+
findFirst<T2>(value: SubtypeExprOrValue<T2>, by: Expr<FunctionType<[T, IntegerType], T2>>): ExprType<OptionType<IntegerType>>;
|
|
799
|
+
findFirst<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any)>(value: ValueTypeOf<TypeOf<ReturnType<NoInfer<F>>>>, by: F): ExprType<OptionType<IntegerType>>;
|
|
800
|
+
findFirst<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any)>(value: Expr<SubType<TypeOf<ReturnType<NoInfer<F>>>>>, by: F): ExprType<OptionType<IntegerType>>;
|
|
801
|
+
findFirst(value: SubtypeExprOrValue<T>): ExprType<OptionType<IntegerType>>;
|
|
802
|
+
/**
|
|
803
|
+
* Finds the indices of all elements equal to the given value.
|
|
804
|
+
*
|
|
805
|
+
* @param value - The value to search for
|
|
806
|
+
* @param by - Optional projection function to transform elements before comparison
|
|
807
|
+
* @returns An ArrayExpr<IntegerType> of indices for all matching elements (empty if none found)
|
|
808
|
+
*
|
|
809
|
+
* @example
|
|
810
|
+
* ```ts
|
|
811
|
+
* const findAllValues = East.function([ArrayType(IntegerType), IntegerType], ArrayType(IntegerType), ($, arr, val) => {
|
|
812
|
+
* $.return(arr.findAll(val));
|
|
813
|
+
* });
|
|
814
|
+
* const compiled = East.compile(findAllValues.toIR(), []);
|
|
815
|
+
* compiled([10n, 20n, 30n, 20n, 10n], 20n); // [1n, 3n]
|
|
816
|
+
* compiled([10n, 20n, 30n], 99n); // []
|
|
817
|
+
* ```
|
|
818
|
+
*
|
|
819
|
+
* @example
|
|
820
|
+
* ```ts
|
|
821
|
+
* // Finding all by a projected field
|
|
822
|
+
* const PersonType = StructType({ name: StringType, role: StringType });
|
|
823
|
+
* const findByRole = East.function([ArrayType(PersonType), StringType], ArrayType(IntegerType), ($, people, targetRole) => {
|
|
824
|
+
* $.return(people.findAll(targetRole, ($, p, i) => p.role));
|
|
825
|
+
* });
|
|
826
|
+
* const compiled = East.compile(findByRole.toIR(), []);
|
|
827
|
+
* compiled([
|
|
828
|
+
* { name: "Alice", role: "admin" },
|
|
829
|
+
* { name: "Bob", role: "user" },
|
|
830
|
+
* { name: "Carol", role: "admin" }
|
|
831
|
+
* ], "admin"); // [0n, 2n]
|
|
832
|
+
* ```
|
|
833
|
+
*
|
|
834
|
+
* @see {@link findSortedRange} for binary search on sorted arrays (returns start/end indices, may be out of bounds).
|
|
835
|
+
* @see {@link findFirst} to find only the first match (returns Option).
|
|
836
|
+
* @see {@link filterMap} for predicate-based searches that can transform results.
|
|
837
|
+
*/
|
|
838
|
+
findAll<T2>(value: SubtypeExprOrValue<T2>, by: Expr<FunctionType<[T, IntegerType], T2>>): ArrayExpr<IntegerType>;
|
|
839
|
+
findAll<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any)>(value: ValueTypeOf<TypeOf<ReturnType<NoInfer<F>>>>, by: F): ArrayExpr<IntegerType>;
|
|
840
|
+
findAll<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any)>(value: Expr<SubType<TypeOf<ReturnType<NoInfer<F>>>>>, by: F): ArrayExpr<IntegerType>;
|
|
841
|
+
findAll(value: SubtypeExprOrValue<T>): ArrayExpr<IntegerType>;
|
|
842
|
+
/**
|
|
843
|
+
* Reduces the array to a single value using an accumulator function and initial value.
|
|
844
|
+
*
|
|
845
|
+
* @param combineFn - Function taking (accumulator, element, index) and returning the new accumulator value
|
|
846
|
+
* @param init - Initial value for the reduction (determines output type)
|
|
847
|
+
* @returns The final accumulated value
|
|
848
|
+
*
|
|
849
|
+
* @remarks
|
|
850
|
+
* The accumulator function is called for each element with the previous result (or initial value for first element),
|
|
851
|
+
* the current value, and the current index. This operation is safe on empty arrays (returns the initial value).
|
|
852
|
+
*
|
|
853
|
+
* @example
|
|
854
|
+
* ```ts
|
|
855
|
+
* const sumArray = East.function([ArrayType(IntegerType)], IntegerType, ($, arr) => {
|
|
856
|
+
* $.return(arr.reduce(($, acc, val, index) => acc.add(val), 0n));
|
|
857
|
+
* });
|
|
858
|
+
* const compiled = East.compile(sumArray.toIR(), []);
|
|
859
|
+
* compiled([1n, 2n, 3n, 4n]); // 10n
|
|
860
|
+
* compiled([]); // 0n (initial value)
|
|
861
|
+
* ```
|
|
862
|
+
*
|
|
863
|
+
* @example
|
|
864
|
+
* ```ts
|
|
865
|
+
* // Building a string from array
|
|
866
|
+
* const joinArray = East.function([ArrayType(StringType)], StringType, ($, arr) => {
|
|
867
|
+
* $.return(arr.reduce(($, acc, val, index) =>
|
|
868
|
+
* $.if(index.equal(0n), () => val, () => acc.concat(", ").concat(val))
|
|
869
|
+
* , ""));
|
|
870
|
+
* });
|
|
871
|
+
* const compiled = East.compile(joinArray.toIR(), []);
|
|
872
|
+
* compiled(["a", "b", "c"]); // "a, b, c"
|
|
873
|
+
* ```
|
|
874
|
+
*
|
|
875
|
+
* @see {@link mapReduce} for a version that projects each value before reducing (and errors on empty arrays).
|
|
876
|
+
* @see {@link sum}, {@link mean}, {@link every}, and {@link some} for common reduction operations.
|
|
877
|
+
*/
|
|
878
|
+
reduce<T2>(combineFn: SubtypeExprOrValue<FunctionType<[previous: TypeOf<NoInfer<T2>>, value: T, key: IntegerType], TypeOf<NoInfer<T2>>>>, init: T2): ExprType<TypeOf<T2>>;
|
|
879
|
+
/**
|
|
880
|
+
* Reduce array to single value using projection and accumulator functions.
|
|
881
|
+
*
|
|
882
|
+
* The first element of the array is used as initial value and reduction starts from the second element.
|
|
883
|
+
* If the array is empty, an error is thrown.
|
|
884
|
+
*
|
|
885
|
+
* @see {@link reduce} for a version with an initial value
|
|
886
|
+
*/
|
|
887
|
+
mapReduce<T2>(mapFn: Expr<FunctionType<[value: T, key: IntegerType], T2>>, combineFn: SubtypeExprOrValue<FunctionType<[previous: NoInfer<T2>, value: NoInfer<T2>], NoInfer<T2>>>): ExprType<T2>;
|
|
888
|
+
mapReduce<F extends ($: BlockBuilder<NeverType>, value: ExprType<T>, key: IntegerExpr) => any>(mapFn: F, combineFn: SubtypeExprOrValue<FunctionType<[previous: NoInfer<TypeOf<ReturnType<F>>>, value: NoInfer<TypeOf<ReturnType<F>>>], NoInfer<TypeOf<ReturnType<F>>>>>): ExprType<TypeOf<ReturnType<F>>>;
|
|
889
|
+
/**
|
|
890
|
+
* Returns true if every element satisfies the predicate, false otherwise.
|
|
891
|
+
*
|
|
892
|
+
* @param fn - Optional predicate function (required for non-Boolean arrays)
|
|
893
|
+
* @returns A BooleanExpr (true for empty arrays)
|
|
894
|
+
*
|
|
895
|
+
* @remarks
|
|
896
|
+
* This method short-circuits on the first false element for efficiency.
|
|
897
|
+
*
|
|
898
|
+
* @example
|
|
899
|
+
* ```ts
|
|
900
|
+
* const allPositive = East.function([ArrayType(IntegerType)], BooleanType, ($, arr) => {
|
|
901
|
+
* $.return(arr.every(($, x, i) => x.greater(0n)));
|
|
902
|
+
* });
|
|
903
|
+
* const compiled = East.compile(allPositive.toIR(), []);
|
|
904
|
+
* compiled([1n, 2n, 3n]); // true
|
|
905
|
+
* compiled([1n, -2n, 3n]); // false
|
|
906
|
+
* compiled([]); // true (empty array)
|
|
907
|
+
* ```
|
|
908
|
+
*
|
|
909
|
+
* @example
|
|
910
|
+
* ```ts
|
|
911
|
+
* // Checking structs
|
|
912
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
913
|
+
* const allAdults = East.function([ArrayType(PersonType)], BooleanType, ($, people) => {
|
|
914
|
+
* $.return(people.every(($, p, i) => p.age.greaterOrEqual(18n)));
|
|
915
|
+
* });
|
|
916
|
+
* const compiled = East.compile(allAdults.toIR(), []);
|
|
917
|
+
* compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }]); // true
|
|
918
|
+
* ```
|
|
919
|
+
*
|
|
920
|
+
* @see {@link some} to check if at least one element is true.
|
|
921
|
+
*/
|
|
922
|
+
every(fn?: SubtypeExprOrValue<FunctionType<[T, IntegerType], BooleanType>>): BooleanExpr;
|
|
923
|
+
/**
|
|
924
|
+
* Returns true if at least one element satisfies the predicate, false otherwise.
|
|
925
|
+
*
|
|
926
|
+
* @param fn - Optional predicate function (required for non-Boolean arrays)
|
|
927
|
+
* @returns A BooleanExpr (false for empty arrays)
|
|
928
|
+
*
|
|
929
|
+
* @remarks
|
|
930
|
+
* This method short-circuits on the first true element for efficiency.
|
|
931
|
+
*
|
|
932
|
+
* @example
|
|
933
|
+
* ```ts
|
|
934
|
+
* const hasNegative = East.function([ArrayType(IntegerType)], BooleanType, ($, arr) => {
|
|
935
|
+
* $.return(arr.some(($, x, i) => x.less(0n)));
|
|
936
|
+
* });
|
|
937
|
+
* const compiled = East.compile(hasNegative.toIR(), []);
|
|
938
|
+
* compiled([1n, 2n, 3n]); // false
|
|
939
|
+
* compiled([1n, -2n, 3n]); // true
|
|
940
|
+
* compiled([]); // false (empty array)
|
|
941
|
+
* ```
|
|
942
|
+
*
|
|
943
|
+
* @example
|
|
944
|
+
* ```ts
|
|
945
|
+
* // Checking structs
|
|
946
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
947
|
+
* const hasMinor = East.function([ArrayType(PersonType)], BooleanType, ($, people) => {
|
|
948
|
+
* $.return(people.some(($, p, i) => p.age.less(18n)));
|
|
949
|
+
* });
|
|
950
|
+
* const compiled = East.compile(hasMinor.toIR(), []);
|
|
951
|
+
* compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 15n }]); // true
|
|
952
|
+
* ```
|
|
953
|
+
*
|
|
954
|
+
* @see {@link every} to check if all elements are true.
|
|
955
|
+
*/
|
|
956
|
+
some(fn?: SubtypeExprOrValue<FunctionType<[T, IntegerType], BooleanType>>): BooleanExpr;
|
|
957
|
+
/**
|
|
958
|
+
* Sums all elements in the array.
|
|
959
|
+
*
|
|
960
|
+
* @param fn - Optional mapping function to project elements to numbers (required for non-numeric arrays)
|
|
961
|
+
* @returns IntegerExpr or FloatExpr depending on the element type (0 for empty arrays)
|
|
962
|
+
*
|
|
963
|
+
* @example
|
|
964
|
+
* ```ts
|
|
965
|
+
* const sumIntegers = East.function([ArrayType(IntegerType)], IntegerType, ($, arr) => {
|
|
966
|
+
* $.return(arr.sum());
|
|
967
|
+
* });
|
|
968
|
+
* const compiled = East.compile(sumIntegers.toIR(), []);
|
|
969
|
+
* compiled([1n, 2n, 3n, 4n]); // 10n
|
|
970
|
+
* compiled([]); // 0n
|
|
971
|
+
* ```
|
|
972
|
+
*
|
|
973
|
+
* @example
|
|
974
|
+
* ```ts
|
|
975
|
+
* // Sum with projection function
|
|
976
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
977
|
+
* const totalAge = East.function([ArrayType(PersonType)], IntegerType, ($, people) => {
|
|
978
|
+
* $.return(people.sum(($, p, i) => p.age));
|
|
979
|
+
* });
|
|
980
|
+
* const compiled = East.compile(totalAge.toIR(), []);
|
|
981
|
+
* compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }]); // 55n
|
|
982
|
+
* ```
|
|
983
|
+
*/
|
|
984
|
+
sum(fn: Expr<FunctionType<[T, IntegerType], IntegerType>>): IntegerExpr;
|
|
985
|
+
sum(fn: Expr<FunctionType<[T, IntegerType], FloatType>>): FloatExpr;
|
|
986
|
+
sum<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, k: ExprType<IntegerType>) => any)>(fn: F): TypeOf<ReturnType<F>> extends IntegerType ? IntegerExpr : TypeOf<ReturnType<F>> extends FloatType ? FloatExpr : never;
|
|
987
|
+
sum(): T extends IntegerType | FloatType ? ExprType<T> : never;
|
|
988
|
+
/**
|
|
989
|
+
* Calculates the mean (average) of all elements in the array.
|
|
990
|
+
*
|
|
991
|
+
* @param fn - Optional mapping function to project elements to numbers (required for non-numeric arrays)
|
|
992
|
+
* @returns A FloatExpr representing the mean (NaN for empty arrays)
|
|
993
|
+
*
|
|
994
|
+
* @remarks
|
|
995
|
+
* The mean is defined as the sum of all elements divided by the number of elements.
|
|
996
|
+
*
|
|
997
|
+
* @example
|
|
998
|
+
* ```ts
|
|
999
|
+
* const avgNumbers = East.function([ArrayType(IntegerType)], FloatType, ($, arr) => {
|
|
1000
|
+
* $.return(arr.mean());
|
|
1001
|
+
* });
|
|
1002
|
+
* const compiled = East.compile(avgNumbers.toIR(), []);
|
|
1003
|
+
* compiled([1n, 2n, 3n, 4n]); // 2.5
|
|
1004
|
+
* compiled([]); // NaN
|
|
1005
|
+
* ```
|
|
1006
|
+
*
|
|
1007
|
+
* @example
|
|
1008
|
+
* ```ts
|
|
1009
|
+
* // Mean with projection function
|
|
1010
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
1011
|
+
* const avgAge = East.function([ArrayType(PersonType)], FloatType, ($, people) => {
|
|
1012
|
+
* $.return(people.mean(($, p, i) => p.age));
|
|
1013
|
+
* });
|
|
1014
|
+
* const compiled = East.compile(avgAge.toIR(), []);
|
|
1015
|
+
* compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 20n }]); // 25.0
|
|
1016
|
+
* ```
|
|
1017
|
+
*/
|
|
1018
|
+
mean(fn: Expr<FunctionType<[T, IntegerType], IntegerType>>): FloatExpr;
|
|
1019
|
+
mean(fn: Expr<FunctionType<[T, IntegerType], FloatType>>): FloatExpr;
|
|
1020
|
+
mean<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, k: ExprType<IntegerType>) => any)>(fn: F): TypeOf<ReturnType<F>> extends IntegerType | FloatType ? FloatExpr : never;
|
|
1021
|
+
mean(): T extends IntegerType | FloatType ? FloatExpr : never;
|
|
1022
|
+
/**
|
|
1023
|
+
* Finds the index of the maximum element in the array.
|
|
1024
|
+
*
|
|
1025
|
+
* @param by - Optional projection function to transform elements for comparison
|
|
1026
|
+
* @returns Option containing the index of the maximum element, or .none if the array is empty
|
|
1027
|
+
*
|
|
1028
|
+
* @example
|
|
1029
|
+
* ```ts
|
|
1030
|
+
* const findMax = East.function([ArrayType(IntegerType)], OptionType(IntegerType), ($, arr) => {
|
|
1031
|
+
* $.return(arr.findMaximum());
|
|
1032
|
+
* });
|
|
1033
|
+
* const compiled = East.compile(findMax.toIR(), []);
|
|
1034
|
+
* compiled([3n, 1n, 4n, 1n, 5n]); // .some(4n) - index of 5
|
|
1035
|
+
* compiled([]); // .none
|
|
1036
|
+
* ```
|
|
1037
|
+
*
|
|
1038
|
+
* @example
|
|
1039
|
+
* ```ts
|
|
1040
|
+
* // Finding index by projection
|
|
1041
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
1042
|
+
* const findOldest = East.function([ArrayType(PersonType)], OptionType(IntegerType), ($, people) => {
|
|
1043
|
+
* $.return(people.findMaximum(($, p, i) => p.age));
|
|
1044
|
+
* });
|
|
1045
|
+
* const compiled = East.compile(findOldest.toIR(), []);
|
|
1046
|
+
* compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }]); // .some(0n)
|
|
1047
|
+
* ```
|
|
1048
|
+
*
|
|
1049
|
+
* @see {@link findMinimum} to find the index of the minimum element.
|
|
1050
|
+
* @see {@link maximum} to get the maximum element itself (throws on empty array).
|
|
1051
|
+
*/
|
|
1052
|
+
findMaximum(by: Expr<FunctionType<[T, IntegerType], any>>): ExprType<OptionType<IntegerType>>;
|
|
1053
|
+
findMaximum<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any)>(by: F): ExprType<OptionType<IntegerType>>;
|
|
1054
|
+
findMaximum(): T extends (IntegerType | FloatType | StringType) ? ExprType<OptionType<IntegerType>> : never;
|
|
1055
|
+
/**
|
|
1056
|
+
* Finds the index of the minimum element in the array.
|
|
1057
|
+
*
|
|
1058
|
+
* @param by - Optional projection function to transform elements for comparison
|
|
1059
|
+
* @returns Option containing the index of the minimum element, or .none if the array is empty
|
|
1060
|
+
*
|
|
1061
|
+
* @example
|
|
1062
|
+
* ```ts
|
|
1063
|
+
* const findMin = East.function([ArrayType(IntegerType)], OptionType(IntegerType), ($, arr) => {
|
|
1064
|
+
* $.return(arr.findMinimum());
|
|
1065
|
+
* });
|
|
1066
|
+
* const compiled = East.compile(findMin.toIR(), []);
|
|
1067
|
+
* compiled([3n, 1n, 4n, 1n, 5n]); // .some(1n) - index of first 1
|
|
1068
|
+
* compiled([]); // .none
|
|
1069
|
+
* ```
|
|
1070
|
+
*
|
|
1071
|
+
* @example
|
|
1072
|
+
* ```ts
|
|
1073
|
+
* // Finding index by projection
|
|
1074
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
1075
|
+
* const findYoungest = East.function([ArrayType(PersonType)], OptionType(IntegerType), ($, people) => {
|
|
1076
|
+
* $.return(people.findMinimum(($, p, i) => p.age));
|
|
1077
|
+
* });
|
|
1078
|
+
* const compiled = East.compile(findYoungest.toIR(), []);
|
|
1079
|
+
* compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }]); // .some(1n)
|
|
1080
|
+
* ```
|
|
1081
|
+
*
|
|
1082
|
+
* @see {@link findMaximum} to find the index of the maximum element.
|
|
1083
|
+
* @see {@link minimum} to get the minimum element itself (throws on empty array).
|
|
1084
|
+
*/
|
|
1085
|
+
findMinimum(by: Expr<FunctionType<[T, IntegerType], any>>): ExprType<OptionType<IntegerType>>;
|
|
1086
|
+
findMinimum<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any)>(by: F): ExprType<OptionType<IntegerType>>;
|
|
1087
|
+
findMinimum(): T extends (IntegerType | FloatType | StringType) ? ExprType<OptionType<IntegerType>> : never;
|
|
1088
|
+
/**
|
|
1089
|
+
* Returns the maximum element in the array.
|
|
1090
|
+
*
|
|
1091
|
+
* @param by - Optional projection function to transform elements for comparison
|
|
1092
|
+
* @returns The element with the maximum value (or maximum projected value)
|
|
1093
|
+
*
|
|
1094
|
+
* @throws East runtime error if the array is empty
|
|
1095
|
+
*
|
|
1096
|
+
* @example
|
|
1097
|
+
* ```ts
|
|
1098
|
+
* const getMax = East.function([ArrayType(IntegerType)], IntegerType, ($, arr) => {
|
|
1099
|
+
* $.return(arr.maximum());
|
|
1100
|
+
* });
|
|
1101
|
+
* const compiled = East.compile(getMax.toIR(), []);
|
|
1102
|
+
* compiled([3n, 1n, 4n, 1n, 5n]); // 5n
|
|
1103
|
+
* // compiled([]) would throw error
|
|
1104
|
+
* ```
|
|
1105
|
+
*
|
|
1106
|
+
* @example
|
|
1107
|
+
* ```ts
|
|
1108
|
+
* // Getting element by projection
|
|
1109
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
1110
|
+
* const getOldest = East.function([ArrayType(PersonType)], PersonType, ($, people) => {
|
|
1111
|
+
* $.return(people.maximum(($, p, i) => p.age));
|
|
1112
|
+
* });
|
|
1113
|
+
* const compiled = East.compile(getOldest.toIR(), []);
|
|
1114
|
+
* compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }]);
|
|
1115
|
+
* // { name: "Alice", age: 30n }
|
|
1116
|
+
* ```
|
|
1117
|
+
*
|
|
1118
|
+
* @see {@link minimum} to find the minimum element.
|
|
1119
|
+
* @see {@link findMaximum} to get the index instead (returns Option, safe for empty arrays).
|
|
1120
|
+
*/
|
|
1121
|
+
maximum(by: Expr<FunctionType<[T, IntegerType], any>>): ExprType<T>;
|
|
1122
|
+
maximum<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any)>(by: F): ExprType<T>;
|
|
1123
|
+
maximum(): T extends (IntegerType | FloatType | StringType) ? ExprType<T> : never;
|
|
1124
|
+
/**
|
|
1125
|
+
* Returns the minimum element in the array.
|
|
1126
|
+
*
|
|
1127
|
+
* @param by - Optional projection function to transform elements for comparison
|
|
1128
|
+
* @returns The element with the minimum value (or minimum projected value)
|
|
1129
|
+
*
|
|
1130
|
+
* @throws East runtime error if the array is empty
|
|
1131
|
+
*
|
|
1132
|
+
* @example
|
|
1133
|
+
* ```ts
|
|
1134
|
+
* const getMin = East.function([ArrayType(IntegerType)], IntegerType, ($, arr) => {
|
|
1135
|
+
* $.return(arr.minimum());
|
|
1136
|
+
* });
|
|
1137
|
+
* const compiled = East.compile(getMin.toIR(), []);
|
|
1138
|
+
* compiled([3n, 1n, 4n, 1n, 5n]); // 1n
|
|
1139
|
+
* // compiled([]) would throw error
|
|
1140
|
+
* ```
|
|
1141
|
+
*
|
|
1142
|
+
* @example
|
|
1143
|
+
* ```ts
|
|
1144
|
+
* // Getting element by projection
|
|
1145
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
1146
|
+
* const getYoungest = East.function([ArrayType(PersonType)], PersonType, ($, people) => {
|
|
1147
|
+
* $.return(people.minimum(($, p, i) => p.age));
|
|
1148
|
+
* });
|
|
1149
|
+
* const compiled = East.compile(getYoungest.toIR(), []);
|
|
1150
|
+
* compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }]);
|
|
1151
|
+
* // { name: "Bob", age: 25n }
|
|
1152
|
+
* ```
|
|
1153
|
+
*
|
|
1154
|
+
* @see {@link maximum} to find the maximum element.
|
|
1155
|
+
* @see {@link findMinimum} to get the index instead (returns Option, safe for empty arrays).
|
|
1156
|
+
*/
|
|
1157
|
+
minimum(by: Expr<FunctionType<[T, IntegerType], any>>): ExprType<T>;
|
|
1158
|
+
minimum<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any)>(by: F): ExprType<T>;
|
|
1159
|
+
minimum(): T extends (IntegerType | FloatType | StringType) ? ExprType<T> : never;
|
|
1160
|
+
/**
|
|
1161
|
+
* Joins string array elements with a delimiter.
|
|
1162
|
+
*
|
|
1163
|
+
* @param string - The delimiter string to insert between elements
|
|
1164
|
+
* @returns A StringExpr with all elements joined
|
|
1165
|
+
*
|
|
1166
|
+
* @remarks
|
|
1167
|
+
* This method only works on arrays of strings.
|
|
1168
|
+
*
|
|
1169
|
+
* @example
|
|
1170
|
+
* ```ts
|
|
1171
|
+
* const joinStrings = East.function([ArrayType(StringType), StringType], StringType, ($, arr, delimiter) => {
|
|
1172
|
+
* $.return(arr.stringJoin(delimiter));
|
|
1173
|
+
* });
|
|
1174
|
+
* const compiled = East.compile(joinStrings.toIR(), []);
|
|
1175
|
+
* compiled(["a", "b", "c"], ", "); // "a, b, c"
|
|
1176
|
+
* compiled(["hello", "world"], " "); // "hello world"
|
|
1177
|
+
* compiled([], ", "); // ""
|
|
1178
|
+
* ```
|
|
1179
|
+
*/
|
|
1180
|
+
stringJoin(string: T extends StringType ? Expr<StringType> | string : never): StringExpr;
|
|
1181
|
+
/**
|
|
1182
|
+
* Converts the array to a set, keeping only unique values.
|
|
1183
|
+
*
|
|
1184
|
+
* @param keyFn - Optional function to project elements to set keys (defaults to the elements themselves)
|
|
1185
|
+
* @returns A SetExpr containing unique values
|
|
1186
|
+
*
|
|
1187
|
+
* @remarks
|
|
1188
|
+
* Duplicates are automatically ignored. Later values with the same key overwrite earlier ones.
|
|
1189
|
+
*
|
|
1190
|
+
* @example
|
|
1191
|
+
* ```ts
|
|
1192
|
+
* const uniqueNumbers = East.function([ArrayType(IntegerType)], SetType(IntegerType), ($, arr) => {
|
|
1193
|
+
* $.return(arr.toSet());
|
|
1194
|
+
* });
|
|
1195
|
+
* const compiled = East.compile(uniqueNumbers.toIR(), []);
|
|
1196
|
+
* compiled([1n, 2n, 3n, 2n, 1n]); // Set{1n, 2n, 3n}
|
|
1197
|
+
* ```
|
|
1198
|
+
*
|
|
1199
|
+
* @example
|
|
1200
|
+
* ```ts
|
|
1201
|
+
* // Project to keys
|
|
1202
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
1203
|
+
* const uniqueAges = East.function([ArrayType(PersonType)], SetType(IntegerType), ($, people) => {
|
|
1204
|
+
* $.return(people.toSet(($, p, i) => p.age));
|
|
1205
|
+
* });
|
|
1206
|
+
* const compiled = East.compile(uniqueAges.toIR(), []);
|
|
1207
|
+
* compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }, { name: "Carol", age: 30n }]);
|
|
1208
|
+
* // Set{25n, 30n}
|
|
1209
|
+
* ```
|
|
1210
|
+
*/
|
|
1211
|
+
toSet<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>): SetExpr<K2>;
|
|
1212
|
+
toSet<KeyFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, k: ExprType<IntegerType>) => any)>(keyFn: KeyFn): SetExpr<TypeOf<ReturnType<KeyFn>>>;
|
|
1213
|
+
toSet(): SetExpr<T>;
|
|
1214
|
+
/**
|
|
1215
|
+
* Converts the array to a dictionary.
|
|
1216
|
+
*
|
|
1217
|
+
* @param keyFn - Optional function to project elements to dict keys (defaults to array indices)
|
|
1218
|
+
* @param valueFn - Optional function to project elements to dict values (defaults to the elements themselves)
|
|
1219
|
+
* @param onConflict - Optional function to handle duplicate keys (defaults to throwing an error)
|
|
1220
|
+
* @returns A DictExpr mapping keys to values
|
|
1221
|
+
*
|
|
1222
|
+
* @throws East runtime error if duplicate keys are produced and no onConflict function is provided
|
|
1223
|
+
*
|
|
1224
|
+
* @example
|
|
1225
|
+
* ```ts
|
|
1226
|
+
* const indexToValue = East.function([ArrayType(StringType)], DictType(IntegerType, StringType), ($, arr) => {
|
|
1227
|
+
* $.return(arr.toDict());
|
|
1228
|
+
* });
|
|
1229
|
+
* const compiled = East.compile(indexToValue.toIR(), []);
|
|
1230
|
+
* compiled(["a", "b", "c"]); // Dict{0n: "a", 1n: "b", 2n: "c"}
|
|
1231
|
+
* ```
|
|
1232
|
+
*
|
|
1233
|
+
* @example
|
|
1234
|
+
* ```ts
|
|
1235
|
+
* // Custom key and value projection
|
|
1236
|
+
* const PersonType = StructType({ id: IntegerType, name: StringType });
|
|
1237
|
+
* const idToName = East.function([ArrayType(PersonType)], DictType(IntegerType, StringType), ($, people) => {
|
|
1238
|
+
* $.return(people.toDict(($, p, i) => p.id, ($, p, i) => p.name));
|
|
1239
|
+
* });
|
|
1240
|
+
* const compiled = East.compile(idToName.toIR(), []);
|
|
1241
|
+
* compiled([{ id: 1n, name: "Alice" }, { id: 2n, name: "Bob" }]);
|
|
1242
|
+
* // Dict{1n: "Alice", 2n: "Bob"}
|
|
1243
|
+
*
|
|
1244
|
+
* // With conflict handler
|
|
1245
|
+
* const mergeOnConflict = East.function([ArrayType(PersonType)], DictType(IntegerType, StringType), ($, people) => {
|
|
1246
|
+
* $.return(people.toDict(
|
|
1247
|
+
* ($, p, i) => p.id,
|
|
1248
|
+
* ($, p, i) => p.name,
|
|
1249
|
+
* ($, existing, newVal, key) => existing.concat(" & ").concat(newVal)
|
|
1250
|
+
* ));
|
|
1251
|
+
* });
|
|
1252
|
+
* ```
|
|
1253
|
+
*/
|
|
1254
|
+
toDict<K2, T2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, valueFn: Expr<FunctionType<[T, IntegerType], T2>>, onConflict?: SubtypeExprOrValue<FunctionType<[NoInfer<T2>, NoInfer<T2>, NoInfer<K2>], NoInfer<T2>>>): DictExpr<K2, T2>;
|
|
1255
|
+
toDict<K2, ValueFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, k: ExprType<IntegerType>) => any)>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, valueFn: ValueFn, onConflict?: SubtypeExprOrValue<FunctionType<[TypeOf<ReturnType<NoInfer<ValueFn>>>, TypeOf<ReturnType<NoInfer<ValueFn>>>, NoInfer<K2>], TypeOf<ReturnType<NoInfer<ValueFn>>>>>): DictExpr<K2, TypeOf<ReturnType<ValueFn>>>;
|
|
1256
|
+
toDict<KeyFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, k: ExprType<IntegerType>) => any), T2>(keyFn: KeyFn, valueFn: Expr<FunctionType<[T, IntegerType], T2>>, onConflict?: SubtypeExprOrValue<FunctionType<[NoInfer<T2>, NoInfer<T2>, TypeOf<ReturnType<NoInfer<KeyFn>>>], NoInfer<T2>>>): DictExpr<TypeOf<ReturnType<KeyFn>>, T2>;
|
|
1257
|
+
toDict<KeyFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, k: ExprType<IntegerType>) => any), ValueFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, k: ExprType<IntegerType>) => any)>(keyFn: KeyFn, valueFn: ValueFn, onConflict?: SubtypeExprOrValue<FunctionType<[TypeOf<ReturnType<NoInfer<ValueFn>>>, TypeOf<ReturnType<NoInfer<ValueFn>>>, NoInfer<TypeOf<ReturnType<NoInfer<KeyFn>>>>], TypeOf<ReturnType<NoInfer<ValueFn>>>>>): DictExpr<TypeOf<ReturnType<KeyFn>>, TypeOf<ReturnType<ValueFn>>>;
|
|
1258
|
+
toDict<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>): DictExpr<K2, T>;
|
|
1259
|
+
toDict<KeyFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, k: ExprType<IntegerType>) => any)>(keyFn: KeyFn): DictExpr<TypeOf<ReturnType<KeyFn>>, T>;
|
|
1260
|
+
toDict(): DictExpr<IntegerType, T>;
|
|
1261
|
+
/**
|
|
1262
|
+
* Maps each element to an array and flattens the result into a single array.
|
|
1263
|
+
*
|
|
1264
|
+
* @param fn - Optional function to project elements to arrays (omit if already an array-of-arrays)
|
|
1265
|
+
* @returns A flattened ArrayExpr
|
|
1266
|
+
*
|
|
1267
|
+
* @remarks
|
|
1268
|
+
* This is more efficient than using `map` followed by `concat`, as it only iterates once.
|
|
1269
|
+
*
|
|
1270
|
+
* @example
|
|
1271
|
+
* ```ts
|
|
1272
|
+
* const flattenArrays = East.function([ArrayType(ArrayType(IntegerType))], ArrayType(IntegerType), ($, arr) => {
|
|
1273
|
+
* $.return(arr.flatMap());
|
|
1274
|
+
* });
|
|
1275
|
+
* const compiled = East.compile(flattenArrays.toIR(), []);
|
|
1276
|
+
* compiled([[1n, 2n], [3n, 4n], [5n]]); // [1n, 2n, 3n, 4n, 5n]
|
|
1277
|
+
* ```
|
|
1278
|
+
*
|
|
1279
|
+
* @example
|
|
1280
|
+
* ```ts
|
|
1281
|
+
* // Map and flatten in one step
|
|
1282
|
+
* const PersonType = StructType({ name: StringType, friends: ArrayType(StringType) });
|
|
1283
|
+
* const allFriends = East.function([ArrayType(PersonType)], ArrayType(StringType), ($, people) => {
|
|
1284
|
+
* $.return(people.flatMap(($, p, i) => p.friends));
|
|
1285
|
+
* });
|
|
1286
|
+
* const compiled = East.compile(allFriends.toIR(), []);
|
|
1287
|
+
* compiled([
|
|
1288
|
+
* { name: "Alice", friends: ["Bob", "Carol"] },
|
|
1289
|
+
* { name: "Bob", friends: ["Alice"] }
|
|
1290
|
+
* ]); // ["Bob", "Carol", "Alice"]
|
|
1291
|
+
* ```
|
|
1292
|
+
*
|
|
1293
|
+
* @see {@link map} to only map values, {@link concat} to only concatenate arrays
|
|
1294
|
+
* @see {@link flattenToSet} to flatten to a set instead, {@link flattenToDict} to flatten to a dictionary
|
|
1295
|
+
*/
|
|
1296
|
+
flatMap<T2>(fn: Expr<FunctionType<[T, IntegerType], ArrayType<T2>>>): ArrayExpr<T2>;
|
|
1297
|
+
flatMap<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, k: ExprType<IntegerType>) => any)>(fn: F): TypeOf<ReturnType<F>> extends ArrayType<infer U> ? ArrayExpr<U> : never;
|
|
1298
|
+
flatMap(): T extends ArrayType<infer U> ? ArrayExpr<U> : never;
|
|
1299
|
+
/**
|
|
1300
|
+
* Maps each element to a set and flattens the result into a single set.
|
|
1301
|
+
*
|
|
1302
|
+
* @param fn - Optional function to project elements to sets (omit if already an array-of-sets)
|
|
1303
|
+
* @returns A flattened SetExpr (duplicates removed)
|
|
1304
|
+
*
|
|
1305
|
+
* @remarks
|
|
1306
|
+
* The resulting sets are unioned together. Duplicates are automatically ignored.
|
|
1307
|
+
*
|
|
1308
|
+
* @example
|
|
1309
|
+
* ```ts
|
|
1310
|
+
* const flattenSets = East.function([ArrayType(SetType(IntegerType))], SetType(IntegerType), ($, arr) => {
|
|
1311
|
+
* $.return(arr.flattenToSet());
|
|
1312
|
+
* });
|
|
1313
|
+
* const compiled = East.compile(flattenSets.toIR(), []);
|
|
1314
|
+
* compiled([Set{1n, 2n}, Set{2n, 3n}, Set{3n, 4n}]); // Set{1n, 2n, 3n, 4n}
|
|
1315
|
+
* ```
|
|
1316
|
+
*
|
|
1317
|
+
* @see {@link flatMap} to flatten to an array instead, {@link flattenToDict} to flatten to a dictionary
|
|
1318
|
+
* @see {@link toSet} to convert an array to a set without flattening
|
|
1319
|
+
*/
|
|
1320
|
+
flattenToSet<K2>(fn: Expr<FunctionType<[T, IntegerType], SetType<K2>>>): SetExpr<K2>;
|
|
1321
|
+
flattenToSet<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, k: ExprType<IntegerType>) => any)>(fn: F): TypeOf<ReturnType<F>> extends SetType<infer U> ? SetExpr<U> : never;
|
|
1322
|
+
flattenToSet(): T extends SetType<infer U> ? SetExpr<U> : never;
|
|
1323
|
+
/**
|
|
1324
|
+
* Maps each element to a dictionary and flattens the result into a single dictionary.
|
|
1325
|
+
*
|
|
1326
|
+
* @param fn - Optional function to project elements to dicts (omit if already an array-of-dicts)
|
|
1327
|
+
* @param onConflict - Optional function to handle duplicate keys (defaults to throwing an error)
|
|
1328
|
+
* @returns A flattened DictExpr
|
|
1329
|
+
*
|
|
1330
|
+
* @throws East runtime error if duplicate keys are encountered and no onConflict function is provided
|
|
1331
|
+
*
|
|
1332
|
+
* @remarks
|
|
1333
|
+
* The resulting dictionaries are merged together.
|
|
1334
|
+
*
|
|
1335
|
+
* @example
|
|
1336
|
+
* ```ts
|
|
1337
|
+
* const flattenDicts = East.function([ArrayType(DictType(StringType, IntegerType))], DictType(StringType, IntegerType), ($, arr) => {
|
|
1338
|
+
* $.return(arr.flattenToDict());
|
|
1339
|
+
* });
|
|
1340
|
+
* const compiled = East.compile(flattenDicts.toIR(), []);
|
|
1341
|
+
* compiled([Dict{"a": 1n, "b": 2n}, Dict{"c": 3n}]); // Dict{"a": 1n, "b": 2n, "c": 3n}
|
|
1342
|
+
* ```
|
|
1343
|
+
*
|
|
1344
|
+
* @see {@link flatMap} to flatten to an array instead, {@link flattenToSet} to flatten to a set
|
|
1345
|
+
* @see {@link toDict} to convert an array to a dictionary without flattening
|
|
1346
|
+
*/
|
|
1347
|
+
flattenToDict<K2, V2>(fn: Expr<FunctionType<[T, IntegerType], DictType<K2, V2>>>, onConflict?: SubtypeExprOrValue<FunctionType<[NoInfer<V2>, NoInfer<V2>, NoInfer<K2>], NoInfer<V2>>>): DictExpr<K2, V2>;
|
|
1348
|
+
flattenToDict<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, k: ExprType<IntegerType>) => any)>(fn: F, onConflict?: SubtypeExprOrValue<FunctionType<[TypeOf<ReturnType<NoInfer<F>>> extends DictType<any, infer V2> ? V2 : never, TypeOf<ReturnType<NoInfer<F>>> extends DictType<any, infer V2> ? V2 : never, TypeOf<ReturnType<NoInfer<F>>> extends DictType<infer K2, any> ? K2 : never], TypeOf<ReturnType<NoInfer<F>>> extends DictType<any, infer V2> ? V2 : never>>): TypeOf<ReturnType<F>> extends DictType<infer K2, infer V2> ? DictExpr<K2, V2> : never;
|
|
1349
|
+
flattenToDict(): T extends DictType<infer K2, infer V2> ? DictExpr<K2, V2> : never;
|
|
1350
|
+
/**
|
|
1351
|
+
* Group array elements by a key function, initialize each group, and reduce within each group.
|
|
1352
|
+
*
|
|
1353
|
+
* This method partitions the array into groups based on a key function, initializes each group
|
|
1354
|
+
* with a starting value (which can depend on the group key), and then reduces all elements
|
|
1355
|
+
* within each group using an accumulator function.
|
|
1356
|
+
*
|
|
1357
|
+
* This is useful for computing aggregates per group where you need a custom initial value,
|
|
1358
|
+
* such as computing a weighted sum, building complex data structures, or maintaining counters
|
|
1359
|
+
* that start from a non-zero value.
|
|
1360
|
+
*
|
|
1361
|
+
* @param keyFn - Function that computes the grouping key for each element
|
|
1362
|
+
* @param initFn - Function that computes the initial value for each group (receives the group key)
|
|
1363
|
+
* @param reduceFn - Function that combines the accumulator with each element in the group
|
|
1364
|
+
* @returns Dictionary mapping each unique key to its reduced value
|
|
1365
|
+
*
|
|
1366
|
+
* @example
|
|
1367
|
+
* ```ts
|
|
1368
|
+
* // Group numbers by even/odd and sum them starting from 100
|
|
1369
|
+
* const numbers = East.value([1n, 2n, 3n, 4n]);
|
|
1370
|
+
* numbers.groupReduce(
|
|
1371
|
+
* ($, x) => x.remainder(2n), // key: 0 for even, 1 for odd
|
|
1372
|
+
* ($, key) => 100n, // start each group at 100
|
|
1373
|
+
* ($, acc, x) => acc.add(x) // sum the values
|
|
1374
|
+
* )
|
|
1375
|
+
* // Result: { 0n: 106n, 1n: 104n }
|
|
1376
|
+
* // even: 100 + 2 + 4 = 106
|
|
1377
|
+
* // odd: 100 + 1 + 3 = 104
|
|
1378
|
+
* ```
|
|
1379
|
+
*
|
|
1380
|
+
* @example
|
|
1381
|
+
* ```ts
|
|
1382
|
+
* // Group users by department and count them, starting from department size
|
|
1383
|
+
* users.groupReduce(
|
|
1384
|
+
* ($, u) => u.department,
|
|
1385
|
+
* ($, dept) => deptSizes.get(dept), // initial count from base data
|
|
1386
|
+
* ($, count, user, idx) => count.add(1n)
|
|
1387
|
+
* )
|
|
1388
|
+
* ```
|
|
1389
|
+
*
|
|
1390
|
+
* @see {@link toDict} to create a dictionary without reduction, or for using a conflict handler instead of reduction.
|
|
1391
|
+
* @see {@link reduce} for reducing the entire array without grouping.
|
|
1392
|
+
*/
|
|
1393
|
+
groupReduce<K2, T2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, initFn: Expr<FunctionType<[K2], T2>>, reduceFn: SubtypeExprOrValue<FunctionType<[T2, T, IntegerType], T2>>): DictExpr<K2, T2>;
|
|
1394
|
+
groupReduce<K2, InitFn extends ($: BlockBuilder<NeverType>, k2: ExprType<NoInfer<K2>>) => any>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, initFn: InitFn, reduceFn: SubtypeExprOrValue<FunctionType<[TypeOf<ReturnType<NoInfer<InitFn>>>, T, IntegerType], TypeOf<ReturnType<NoInfer<InitFn>>>>>): DictExpr<K2, TypeOf<ReturnType<InitFn>>>;
|
|
1395
|
+
groupReduce<KeyFn extends ($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any, T2>(keyFn: KeyFn, initFn: Expr<FunctionType<[TypeOf<ReturnType<NoInfer<KeyFn>>>], T2>>, reduceFn: SubtypeExprOrValue<FunctionType<[T2, T, IntegerType], T2>>): DictExpr<TypeOf<ReturnType<KeyFn>>, T2>;
|
|
1396
|
+
groupReduce<KeyFn extends ($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any, InitFn extends ($: BlockBuilder<NeverType>, k2: ExprType<TypeOf<ReturnType<NoInfer<KeyFn>>>>) => any>(keyFn: KeyFn, initFn: InitFn, reduceFn: SubtypeExprOrValue<FunctionType<[TypeOf<ReturnType<NoInfer<InitFn>>>, T, IntegerType], TypeOf<ReturnType<NoInfer<InitFn>>>>>): DictExpr<TypeOf<ReturnType<KeyFn>>, TypeOf<ReturnType<InitFn>>>;
|
|
1397
|
+
/**
|
|
1398
|
+
* Count the number of elements in each group.
|
|
1399
|
+
*
|
|
1400
|
+
* Groups elements by a key function and returns a dictionary mapping each unique key
|
|
1401
|
+
* to the count of elements in that group.
|
|
1402
|
+
*
|
|
1403
|
+
* @param keyFn - Function that computes the grouping key for each element (defaults to identity)
|
|
1404
|
+
* @returns Dictionary mapping each unique key to the count of elements in that group
|
|
1405
|
+
*
|
|
1406
|
+
* @example
|
|
1407
|
+
* ```ts
|
|
1408
|
+
* // Count occurrences of each number
|
|
1409
|
+
* [1n, 2n, 1n, 3n, 2n, 1n].groupSize()
|
|
1410
|
+
* // Result: { 1n: 3n, 2n: 2n, 3n: 1n }
|
|
1411
|
+
*
|
|
1412
|
+
* // Group by even/odd and count
|
|
1413
|
+
* [1n, 2n, 3n, 4n, 5n, 6n].groupSize(($, x) => x.remainder(2n))
|
|
1414
|
+
* // Result: { 0n: 3n, 1n: 3n }
|
|
1415
|
+
* ```
|
|
1416
|
+
*
|
|
1417
|
+
* @see {@link groupToArrays} to collect elements instead of counting them.
|
|
1418
|
+
*/
|
|
1419
|
+
groupSize<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>): DictExpr<K2, IntegerType>;
|
|
1420
|
+
groupSize<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn): DictExpr<TypeOf<ReturnType<KeyFn>>, IntegerType>;
|
|
1421
|
+
groupSize(): DictExpr<T, IntegerType>;
|
|
1422
|
+
/**
|
|
1423
|
+
* Check if every element in each group satisfies a predicate.
|
|
1424
|
+
*
|
|
1425
|
+
* @param keyFn - Function that computes the grouping key
|
|
1426
|
+
* @param predFn - Predicate function to test each element
|
|
1427
|
+
* @returns Dictionary mapping each key to true if all elements in that group satisfy the predicate
|
|
1428
|
+
*
|
|
1429
|
+
* @example
|
|
1430
|
+
* ```ts
|
|
1431
|
+
* [1n, 2n, 3n, 4n, 5n, 6n].groupEvery(
|
|
1432
|
+
* ($, x) => x.remainder(2n),
|
|
1433
|
+
* ($, x) => x.greater(0n)
|
|
1434
|
+
* )
|
|
1435
|
+
* // Result: { 0n: true, 1n: true }
|
|
1436
|
+
* ```
|
|
1437
|
+
*/
|
|
1438
|
+
groupEvery<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, predFn: SubtypeExprOrValue<FunctionType<[T, IntegerType], BooleanType>>): DictExpr<K2, BooleanType>;
|
|
1439
|
+
groupEvery<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, predFn: SubtypeExprOrValue<FunctionType<[T, IntegerType], BooleanType>>): DictExpr<TypeOf<ReturnType<KeyFn>>, BooleanType>;
|
|
1440
|
+
/**
|
|
1441
|
+
* Check if any element in each group satisfies a predicate.
|
|
1442
|
+
*
|
|
1443
|
+
* @param keyFn - Function that computes the grouping key
|
|
1444
|
+
* @param predFn - Predicate function to test each element
|
|
1445
|
+
* @returns Dictionary mapping each key to true if at least one element in that group satisfies the predicate
|
|
1446
|
+
*
|
|
1447
|
+
* @example
|
|
1448
|
+
* ```ts
|
|
1449
|
+
* [1n, 2n, 3n, 4n].groupSome(
|
|
1450
|
+
* ($, x) => x.remainder(2n),
|
|
1451
|
+
* ($, x) => x.greater(3n)
|
|
1452
|
+
* )
|
|
1453
|
+
* // Result: { 0n: true, 1n: false }
|
|
1454
|
+
* ```
|
|
1455
|
+
*/
|
|
1456
|
+
groupSome<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, predFn: SubtypeExprOrValue<FunctionType<[T, IntegerType], BooleanType>>): DictExpr<K2, BooleanType>;
|
|
1457
|
+
groupSome<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, predFn: SubtypeExprOrValue<FunctionType<[T, IntegerType], BooleanType>>): DictExpr<TypeOf<ReturnType<KeyFn>>, BooleanType>;
|
|
1458
|
+
/**
|
|
1459
|
+
* Find all indices where a value matches, grouped by key.
|
|
1460
|
+
*
|
|
1461
|
+
* @param keyFn - Function that computes the grouping key
|
|
1462
|
+
* @param value - The value to search for
|
|
1463
|
+
* @param projFn - Optional projection function to extract the value to compare
|
|
1464
|
+
* @returns Dictionary mapping each key to an array of matching indices
|
|
1465
|
+
*
|
|
1466
|
+
* @example
|
|
1467
|
+
* ```ts
|
|
1468
|
+
* // Without projection - find all occurrences of value 2
|
|
1469
|
+
* [1n, 2n, 3n, 2n, 5n, 2n].groupFindAll(
|
|
1470
|
+
* ($, x) => x.remainder(2n),
|
|
1471
|
+
* 2n
|
|
1472
|
+
* )
|
|
1473
|
+
* // Result: { 0n: [1n, 3n, 5n], 1n: [] }
|
|
1474
|
+
*
|
|
1475
|
+
* // With projection - find all orders in "CA" grouped by customer
|
|
1476
|
+
* orders.groupFindAll(
|
|
1477
|
+
* ($, o) => o.customer,
|
|
1478
|
+
* "CA",
|
|
1479
|
+
* ($, o) => o.state
|
|
1480
|
+
* )
|
|
1481
|
+
* ```
|
|
1482
|
+
*/
|
|
1483
|
+
groupFindAll<K2, T2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, value: SubtypeExprOrValue<T2>, projFn: Expr<FunctionType<[T, IntegerType], T2>>): DictExpr<K2, ArrayType<IntegerType>>;
|
|
1484
|
+
groupFindAll<K2, ProjFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, value: ValueTypeOf<TypeOf<ReturnType<NoInfer<ProjFn>>>>, projFn: ProjFn): DictExpr<K2, ArrayType<IntegerType>>;
|
|
1485
|
+
groupFindAll<K2, ProjFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, value: Expr<SubType<TypeOf<ReturnType<NoInfer<ProjFn>>>>>, projFn: ProjFn): DictExpr<K2, ArrayType<IntegerType>>;
|
|
1486
|
+
groupFindAll<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any), T2>(keyFn: KeyFn, value: SubtypeExprOrValue<T2>, projFn: Expr<FunctionType<[T, IntegerType], T2>>): DictExpr<TypeOf<ReturnType<KeyFn>>, ArrayType<IntegerType>>;
|
|
1487
|
+
groupFindAll<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any), ProjFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, value: ValueTypeOf<TypeOf<ReturnType<NoInfer<ProjFn>>>>, projFn: ProjFn): DictExpr<TypeOf<ReturnType<KeyFn>>, ArrayType<IntegerType>>;
|
|
1488
|
+
groupFindAll<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any), ProjFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, value: Expr<SubType<TypeOf<ReturnType<NoInfer<ProjFn>>>>>, projFn: ProjFn): DictExpr<TypeOf<ReturnType<KeyFn>>, ArrayType<IntegerType>>;
|
|
1489
|
+
groupFindAll<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, value: SubtypeExprOrValue<T>): DictExpr<K2, ArrayType<IntegerType>>;
|
|
1490
|
+
groupFindAll<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, value: SubtypeExprOrValue<T>): DictExpr<TypeOf<ReturnType<KeyFn>>, ArrayType<IntegerType>>;
|
|
1491
|
+
/**
|
|
1492
|
+
* Find the first index where a value matches, grouped by key.
|
|
1493
|
+
*
|
|
1494
|
+
* @param keyFn - Function that computes the grouping key
|
|
1495
|
+
* @param value - The value to search for
|
|
1496
|
+
* @param projFn - Optional projection function to extract the value to compare
|
|
1497
|
+
* @returns Dictionary mapping each key to an Option containing the first matching index
|
|
1498
|
+
*
|
|
1499
|
+
* @example
|
|
1500
|
+
* ```ts
|
|
1501
|
+
* // Without projection - find value 4
|
|
1502
|
+
* [1n, 2n, 3n, 4n, 5n, 6n].groupFindFirst(
|
|
1503
|
+
* ($, x) => x.remainder(2n),
|
|
1504
|
+
* 4n
|
|
1505
|
+
* )
|
|
1506
|
+
* // Result: { 0n: some(3n), 1n: none }
|
|
1507
|
+
*
|
|
1508
|
+
* // With projection - find orders in "CA" grouped by customer
|
|
1509
|
+
* orders.groupFindFirst(
|
|
1510
|
+
* ($, o) => o.customer,
|
|
1511
|
+
* "CA",
|
|
1512
|
+
* ($, o) => o.state
|
|
1513
|
+
* )
|
|
1514
|
+
* ```
|
|
1515
|
+
*/
|
|
1516
|
+
groupFindFirst<K2, T2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, value: SubtypeExprOrValue<T2>, projFn: Expr<FunctionType<[T, IntegerType], T2>>): DictExpr<K2, OptionType<IntegerType>>;
|
|
1517
|
+
groupFindFirst<K2, ProjFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, value: ValueTypeOf<TypeOf<ReturnType<NoInfer<ProjFn>>>>, projFn: ProjFn): DictExpr<K2, OptionType<IntegerType>>;
|
|
1518
|
+
groupFindFirst<K2, ProjFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, value: Expr<SubType<TypeOf<ReturnType<NoInfer<ProjFn>>>>>, projFn: ProjFn): DictExpr<K2, OptionType<IntegerType>>;
|
|
1519
|
+
groupFindFirst<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any), T2>(keyFn: KeyFn, value: SubtypeExprOrValue<T2>, projFn: Expr<FunctionType<[T, IntegerType], T2>>): DictExpr<TypeOf<ReturnType<KeyFn>>, OptionType<IntegerType>>;
|
|
1520
|
+
groupFindFirst<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any), ProjFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, value: ValueTypeOf<TypeOf<ReturnType<NoInfer<ProjFn>>>>, projFn: ProjFn): DictExpr<TypeOf<ReturnType<KeyFn>>, OptionType<IntegerType>>;
|
|
1521
|
+
groupFindFirst<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any), ProjFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, value: Expr<SubType<TypeOf<ReturnType<NoInfer<ProjFn>>>>>, projFn: ProjFn): DictExpr<TypeOf<ReturnType<KeyFn>>, OptionType<IntegerType>>;
|
|
1522
|
+
groupFindFirst<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, value: SubtypeExprOrValue<T>): DictExpr<K2, OptionType<IntegerType>>;
|
|
1523
|
+
groupFindFirst<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, value: SubtypeExprOrValue<T>): DictExpr<TypeOf<ReturnType<KeyFn>>, OptionType<IntegerType>>;
|
|
1524
|
+
/**
|
|
1525
|
+
* Find the index of the minimum element in each group.
|
|
1526
|
+
*
|
|
1527
|
+
* @param keyFn - Function that computes the grouping key
|
|
1528
|
+
* @param byFn - Optional projection function for comparison
|
|
1529
|
+
* @returns Dictionary mapping each key to the index of the minimum element in that group
|
|
1530
|
+
*
|
|
1531
|
+
* @example
|
|
1532
|
+
* ```ts
|
|
1533
|
+
* [1n, 2n, 3n, 4n, 5n, 6n].groupFindMinimum(($, x) => x.remainder(2n))
|
|
1534
|
+
* // Result: { 0n: 1n, 1n: 0n }
|
|
1535
|
+
* ```
|
|
1536
|
+
*/
|
|
1537
|
+
groupFindMinimum<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, byFn?: SubtypeExprOrValue<FunctionType<[T, IntegerType], any>>): DictExpr<K2, IntegerType>;
|
|
1538
|
+
groupFindMinimum<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, byFn?: SubtypeExprOrValue<FunctionType<[T, IntegerType], any>>): DictExpr<TypeOf<ReturnType<KeyFn>>, IntegerType>;
|
|
1539
|
+
/**
|
|
1540
|
+
* Find the index of the maximum element in each group.
|
|
1541
|
+
*
|
|
1542
|
+
* @param keyFn - Function that computes the grouping key
|
|
1543
|
+
* @param byFn - Optional projection function for comparison
|
|
1544
|
+
* @returns Dictionary mapping each key to the index of the maximum element in that group
|
|
1545
|
+
*
|
|
1546
|
+
* @example
|
|
1547
|
+
* ```ts
|
|
1548
|
+
* [1n, 2n, 3n, 4n, 5n, 6n].groupFindMaximum(($, x) => x.remainder(2n))
|
|
1549
|
+
* // Result: { 0n: 5n, 1n: 4n }
|
|
1550
|
+
* ```
|
|
1551
|
+
*/
|
|
1552
|
+
groupFindMaximum<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, byFn?: SubtypeExprOrValue<FunctionType<[T, IntegerType], any>>): DictExpr<K2, IntegerType>;
|
|
1553
|
+
groupFindMaximum<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, byFn?: SubtypeExprOrValue<FunctionType<[T, IntegerType], any>>): DictExpr<TypeOf<ReturnType<KeyFn>>, IntegerType>;
|
|
1554
|
+
/**
|
|
1555
|
+
* Sum elements in each group.
|
|
1556
|
+
*
|
|
1557
|
+
* @param keyFn - Function that computes the grouping key
|
|
1558
|
+
* @param valueFn - Optional projection function for values to sum
|
|
1559
|
+
* @returns Dictionary mapping each key to the sum of elements in that group
|
|
1560
|
+
*
|
|
1561
|
+
* @example
|
|
1562
|
+
* ```ts
|
|
1563
|
+
* [1n, 2n, 3n, 4n].groupSum(($, x) => x.remainder(2n))
|
|
1564
|
+
* // Result: { 0n: 6n, 1n: 4n }
|
|
1565
|
+
* ```
|
|
1566
|
+
*/
|
|
1567
|
+
groupSum<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, valueFn: Expr<FunctionType<[T, IntegerType], IntegerType>>): DictExpr<K2, IntegerType>;
|
|
1568
|
+
groupSum<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, valueFn: Expr<FunctionType<[T, IntegerType], FloatType>>): DictExpr<K2, FloatType>;
|
|
1569
|
+
groupSum<K2, ValueFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, valueFn: ValueFn): DictExpr<K2, TypeOf<ReturnType<ValueFn>>>;
|
|
1570
|
+
groupSum<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, valueFn: Expr<FunctionType<[T, IntegerType], IntegerType>>): DictExpr<TypeOf<ReturnType<KeyFn>>, IntegerType>;
|
|
1571
|
+
groupSum<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, valueFn: Expr<FunctionType<[T, IntegerType], FloatType>>): DictExpr<TypeOf<ReturnType<KeyFn>>, FloatType>;
|
|
1572
|
+
groupSum<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any), ValueFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, valueFn: ValueFn): DictExpr<TypeOf<ReturnType<KeyFn>>, TypeOf<ReturnType<ValueFn>>>;
|
|
1573
|
+
groupSum<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>): T extends IntegerType | FloatType ? DictExpr<K2, T> : never;
|
|
1574
|
+
groupSum<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn): T extends IntegerType | FloatType ? DictExpr<TypeOf<ReturnType<KeyFn>>, T> : never;
|
|
1575
|
+
/**
|
|
1576
|
+
* Compute the mean of elements in each group.
|
|
1577
|
+
*
|
|
1578
|
+
* @param keyFn - Function that computes the grouping key
|
|
1579
|
+
* @param valueFn - Optional projection function for values
|
|
1580
|
+
* @returns Dictionary mapping each key to the mean of elements in that group
|
|
1581
|
+
*
|
|
1582
|
+
* @example
|
|
1583
|
+
* ```ts
|
|
1584
|
+
* [1n, 2n, 3n, 4n].groupMean(($, x) => x.remainder(2n))
|
|
1585
|
+
* // Result: { 0n: 3.0, 1n: 2.0 }
|
|
1586
|
+
* ```
|
|
1587
|
+
*/
|
|
1588
|
+
groupMean<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, valueFn: Expr<FunctionType<[T, IntegerType], IntegerType | FloatType>>): DictExpr<K2, FloatType>;
|
|
1589
|
+
groupMean<K2, ValueFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, valueFn: ValueFn): DictExpr<K2, FloatType>;
|
|
1590
|
+
groupMean<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, valueFn: Expr<FunctionType<[T, IntegerType], IntegerType | FloatType>>): DictExpr<TypeOf<ReturnType<KeyFn>>, FloatType>;
|
|
1591
|
+
groupMean<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any), ValueFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, valueFn: ValueFn): DictExpr<TypeOf<ReturnType<KeyFn>>, FloatType>;
|
|
1592
|
+
groupMean<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>): T extends IntegerType | FloatType ? DictExpr<K2, FloatType> : never;
|
|
1593
|
+
groupMean<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn): T extends IntegerType | FloatType ? DictExpr<TypeOf<ReturnType<KeyFn>>, FloatType> : never;
|
|
1594
|
+
/**
|
|
1595
|
+
* Collect elements in each group into arrays.
|
|
1596
|
+
*
|
|
1597
|
+
* @param keyFn - Function that computes the grouping key
|
|
1598
|
+
* @param valueFn - Optional projection function for values
|
|
1599
|
+
* @returns Dictionary mapping each key to an array of elements in that group
|
|
1600
|
+
*
|
|
1601
|
+
* @example
|
|
1602
|
+
* ```ts
|
|
1603
|
+
* [1n, 2n, 3n, 4n].groupToArrays(($, x) => x.remainder(2n))
|
|
1604
|
+
* // Result: { 0n: [2n, 4n], 1n: [1n, 3n] }
|
|
1605
|
+
* ```
|
|
1606
|
+
*/
|
|
1607
|
+
groupToArrays<K2, T2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, valueFn: Expr<FunctionType<[T, IntegerType], T2>>): DictExpr<K2, ArrayType<T2>>;
|
|
1608
|
+
groupToArrays<K2, ValueFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, valueFn: ValueFn): DictExpr<K2, ArrayType<TypeOf<ReturnType<ValueFn>>>>;
|
|
1609
|
+
groupToArrays<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any), T2>(keyFn: KeyFn, valueFn: Expr<FunctionType<[T, IntegerType], T2>>): DictExpr<TypeOf<ReturnType<KeyFn>>, ArrayType<T2>>;
|
|
1610
|
+
groupToArrays<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any), ValueFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, valueFn: ValueFn): DictExpr<TypeOf<ReturnType<KeyFn>>, ArrayType<TypeOf<ReturnType<ValueFn>>>>;
|
|
1611
|
+
groupToArrays<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>): DictExpr<K2, ArrayType<T>>;
|
|
1612
|
+
groupToArrays<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn): DictExpr<TypeOf<ReturnType<KeyFn>>, ArrayType<T>>;
|
|
1613
|
+
/**
|
|
1614
|
+
* Collect elements in each group into sets.
|
|
1615
|
+
*
|
|
1616
|
+
* @param keyFn - Function that computes the grouping key
|
|
1617
|
+
* @param valueFn - Optional projection function for values
|
|
1618
|
+
* @returns Dictionary mapping each key to a set of elements in that group
|
|
1619
|
+
*
|
|
1620
|
+
* @example
|
|
1621
|
+
* ```ts
|
|
1622
|
+
* [1n, 2n, 1n, 2n].groupToSets(($, x) => x.remainder(2n))
|
|
1623
|
+
* // Result: { 0n: Set([2n]), 1n: Set([1n]) }
|
|
1624
|
+
* ```
|
|
1625
|
+
*/
|
|
1626
|
+
groupToSets<K2, T2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, valueFn: Expr<FunctionType<[T, IntegerType], T2>>): DictExpr<K2, SetType<T2>>;
|
|
1627
|
+
groupToSets<K2, ValueFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, valueFn: ValueFn): DictExpr<K2, SetType<TypeOf<ReturnType<ValueFn>>>>;
|
|
1628
|
+
groupToSets<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any), T2>(keyFn: KeyFn, valueFn: Expr<FunctionType<[T, IntegerType], T2>>): DictExpr<TypeOf<ReturnType<KeyFn>>, SetType<T2>>;
|
|
1629
|
+
groupToSets<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any), ValueFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, valueFn: ValueFn): DictExpr<TypeOf<ReturnType<KeyFn>>, SetType<TypeOf<ReturnType<ValueFn>>>>;
|
|
1630
|
+
groupToSets<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>): DictExpr<K2, SetType<T>>;
|
|
1631
|
+
groupToSets<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn): DictExpr<TypeOf<ReturnType<KeyFn>>, SetType<T>>;
|
|
1632
|
+
/**
|
|
1633
|
+
* Find the minimum element in each group.
|
|
1634
|
+
*
|
|
1635
|
+
* @param keyFn - Function that computes the grouping key
|
|
1636
|
+
* @param byFn - Optional projection function for comparison
|
|
1637
|
+
* @returns Dictionary mapping each key to the minimum element in that group
|
|
1638
|
+
*
|
|
1639
|
+
* @example
|
|
1640
|
+
* ```ts
|
|
1641
|
+
* [1n, 2n, 3n, 4n].groupMinimum(($, x) => x.remainder(2n))
|
|
1642
|
+
* // Result: { 0n: 2n, 1n: 1n }
|
|
1643
|
+
* ```
|
|
1644
|
+
*/
|
|
1645
|
+
groupMinimum<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, byFn: Expr<FunctionType<[T, IntegerType], any>>): DictExpr<K2, T>;
|
|
1646
|
+
groupMinimum<K2, ByFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, byFn: ByFn): DictExpr<K2, T>;
|
|
1647
|
+
groupMinimum<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, byFn: Expr<FunctionType<[T, IntegerType], any>>): DictExpr<TypeOf<ReturnType<KeyFn>>, T>;
|
|
1648
|
+
groupMinimum<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any), ByFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, byFn: ByFn): DictExpr<TypeOf<ReturnType<KeyFn>>, T>;
|
|
1649
|
+
groupMinimum<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>): DictExpr<K2, T>;
|
|
1650
|
+
groupMinimum<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn): DictExpr<TypeOf<ReturnType<KeyFn>>, T>;
|
|
1651
|
+
/**
|
|
1652
|
+
* Find the maximum element in each group.
|
|
1653
|
+
*
|
|
1654
|
+
* @param keyFn - Function that computes the grouping key
|
|
1655
|
+
* @param byFn - Optional projection function for comparison
|
|
1656
|
+
* @returns Dictionary mapping each key to the maximum element in that group
|
|
1657
|
+
*
|
|
1658
|
+
* @example
|
|
1659
|
+
* ```ts
|
|
1660
|
+
* [1n, 2n, 3n, 4n].groupMaximum(($, x) => x.remainder(2n))
|
|
1661
|
+
* // Result: { 0n: 4n, 1n: 3n }
|
|
1662
|
+
* ```
|
|
1663
|
+
*/
|
|
1664
|
+
groupMaximum<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, byFn: Expr<FunctionType<[T, IntegerType], any>>): DictExpr<K2, T>;
|
|
1665
|
+
groupMaximum<K2, ByFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>, byFn: ByFn): DictExpr<K2, T>;
|
|
1666
|
+
groupMaximum<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, byFn: Expr<FunctionType<[T, IntegerType], any>>): DictExpr<TypeOf<ReturnType<KeyFn>>, T>;
|
|
1667
|
+
groupMaximum<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any), ByFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, byFn: ByFn): DictExpr<TypeOf<ReturnType<KeyFn>>, T>;
|
|
1668
|
+
groupMaximum<K2>(keyFn: Expr<FunctionType<[T, IntegerType], K2>>): DictExpr<K2, T>;
|
|
1669
|
+
groupMaximum<KeyFn extends (($: BlockBuilder<NeverType>, x: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn): DictExpr<TypeOf<ReturnType<KeyFn>>, T>;
|
|
1670
|
+
/**
|
|
1671
|
+
* Group elements into nested dictionaries.
|
|
1672
|
+
*
|
|
1673
|
+
* @param keyFn - Function that computes the outer grouping key
|
|
1674
|
+
* @param keyFn2 - Function that computes the inner dictionary key
|
|
1675
|
+
* @param valueFn - Optional projection function for inner dictionary values
|
|
1676
|
+
* @param combineFn - Optional function to resolve conflicts when the same inner key appears multiple times
|
|
1677
|
+
* @returns Dictionary-of-dictionaries mapping group keys to dictionaries
|
|
1678
|
+
*
|
|
1679
|
+
* @example
|
|
1680
|
+
* ```ts
|
|
1681
|
+
* // Without conflict handler - errors on duplicate keys
|
|
1682
|
+
* users.groupToDicts(
|
|
1683
|
+
* ($, u) => u.department,
|
|
1684
|
+
* ($, u) => u.role
|
|
1685
|
+
* )
|
|
1686
|
+
* // Result: { "eng": { "dev": user1, "lead": user2 }, "sales": { "rep": user3 } }
|
|
1687
|
+
*
|
|
1688
|
+
* // With conflict handler - merges duplicate keys
|
|
1689
|
+
* orders.groupToDicts(
|
|
1690
|
+
* ($, o) => o.customer,
|
|
1691
|
+
* ($, o) => o.product,
|
|
1692
|
+
* ($, o) => o.quantity,
|
|
1693
|
+
* ($, a, b) => a.add(b)
|
|
1694
|
+
* )
|
|
1695
|
+
* // Sums quantities for same customer+product
|
|
1696
|
+
* ```
|
|
1697
|
+
*/
|
|
1698
|
+
groupToDicts<K1, K2, T2>(keyFn: Expr<FunctionType<[T, IntegerType], K1>>, keyFn2: Expr<FunctionType<[T, IntegerType], K2>>, valueFn: Expr<FunctionType<[T, IntegerType], T2>>, combineFn?: SubtypeExprOrValue<FunctionType<[T2, T2, K1], T2>>): DictExpr<K1, DictType<K2, T2>>;
|
|
1699
|
+
groupToDicts<K1, K2, ValueFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any)>(keyFn: Expr<FunctionType<[T, IntegerType], K1>>, keyFn2: Expr<FunctionType<[T, IntegerType], K2>>, valueFn: ValueFn, combineFn?: SubtypeExprOrValue<FunctionType<[TypeOf<ReturnType<NoInfer<ValueFn>>>, TypeOf<ReturnType<NoInfer<ValueFn>>>, K1], TypeOf<ReturnType<NoInfer<ValueFn>>>>>): DictExpr<K1, DictType<K2, TypeOf<ReturnType<ValueFn>>>>;
|
|
1700
|
+
groupToDicts<K1, KeyFn2 extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any), T2>(keyFn: Expr<FunctionType<[T, IntegerType], K1>>, keyFn2: KeyFn2, valueFn: Expr<FunctionType<[T, IntegerType], T2>>, combineFn?: SubtypeExprOrValue<FunctionType<[T2, T2, K1], T2>>): DictExpr<K1, DictType<TypeOf<ReturnType<KeyFn2>>, T2>>;
|
|
1701
|
+
groupToDicts<K1, KeyFn2 extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any), ValueFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any)>(keyFn: Expr<FunctionType<[T, IntegerType], K1>>, keyFn2: KeyFn2, valueFn: ValueFn, combineFn?: SubtypeExprOrValue<FunctionType<[TypeOf<ReturnType<NoInfer<ValueFn>>>, TypeOf<ReturnType<NoInfer<ValueFn>>>, K1], TypeOf<ReturnType<NoInfer<ValueFn>>>>>): DictExpr<K1, DictType<TypeOf<ReturnType<KeyFn2>>, TypeOf<ReturnType<ValueFn>>>>;
|
|
1702
|
+
groupToDicts<KeyFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any), K2, T2>(keyFn: KeyFn, keyFn2: Expr<FunctionType<[T, IntegerType], K2>>, valueFn: Expr<FunctionType<[T, IntegerType], T2>>, combineFn?: SubtypeExprOrValue<FunctionType<[T2, T2, TypeOf<ReturnType<NoInfer<KeyFn>>>], T2>>): DictExpr<TypeOf<ReturnType<KeyFn>>, DictType<K2, T2>>;
|
|
1703
|
+
groupToDicts<KeyFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any), K2, ValueFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, keyFn2: Expr<FunctionType<[T, IntegerType], K2>>, valueFn: ValueFn, combineFn?: SubtypeExprOrValue<FunctionType<[TypeOf<ReturnType<NoInfer<ValueFn>>>, TypeOf<ReturnType<NoInfer<ValueFn>>>, TypeOf<ReturnType<NoInfer<KeyFn>>>], TypeOf<ReturnType<NoInfer<ValueFn>>>>>): DictExpr<TypeOf<ReturnType<KeyFn>>, DictType<K2, TypeOf<ReturnType<ValueFn>>>>;
|
|
1704
|
+
groupToDicts<KeyFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any), KeyFn2 extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any), T2>(keyFn: KeyFn, keyFn2: KeyFn2, valueFn: Expr<FunctionType<[T, IntegerType], T2>>, combineFn?: SubtypeExprOrValue<FunctionType<[T2, T2, TypeOf<ReturnType<NoInfer<KeyFn>>>], T2>>): DictExpr<TypeOf<ReturnType<KeyFn>>, DictType<TypeOf<ReturnType<KeyFn2>>, T2>>;
|
|
1705
|
+
groupToDicts<KeyFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any), KeyFn2 extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any), ValueFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, keyFn2: KeyFn2, valueFn: ValueFn, combineFn?: SubtypeExprOrValue<FunctionType<[TypeOf<ReturnType<NoInfer<ValueFn>>>, TypeOf<ReturnType<NoInfer<ValueFn>>>, TypeOf<ReturnType<NoInfer<KeyFn>>>], TypeOf<ReturnType<NoInfer<ValueFn>>>>>): DictExpr<TypeOf<ReturnType<KeyFn>>, DictType<TypeOf<ReturnType<KeyFn2>>, TypeOf<ReturnType<ValueFn>>>>;
|
|
1706
|
+
groupToDicts<K1, K2>(keyFn: Expr<FunctionType<[T, IntegerType], K1>>, keyFn2: Expr<FunctionType<[T, IntegerType], K2>>): DictExpr<K1, DictType<K2, T>>;
|
|
1707
|
+
groupToDicts<K1, KeyFn2 extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any)>(keyFn: Expr<FunctionType<[T, IntegerType], K1>>, keyFn2: KeyFn2): DictExpr<K1, DictType<TypeOf<ReturnType<KeyFn2>>, T>>;
|
|
1708
|
+
groupToDicts<KeyFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any), K2>(keyFn: KeyFn, keyFn2: Expr<FunctionType<[T, IntegerType], K2>>): DictExpr<TypeOf<ReturnType<KeyFn>>, DictType<K2, T>>;
|
|
1709
|
+
groupToDicts<KeyFn extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any), KeyFn2 extends (($: BlockBuilder<NeverType>, v: ExprType<T>, i: IntegerExpr) => any)>(keyFn: KeyFn, keyFn2: KeyFn2): DictExpr<TypeOf<ReturnType<KeyFn>>, DictType<TypeOf<ReturnType<KeyFn2>>, T>>;
|
|
1710
|
+
}
|
|
1711
|
+
//# sourceMappingURL=array.d.ts.map
|