@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.
Files changed (251) hide show
  1. package/LICENSE.md +682 -0
  2. package/README.md +276 -0
  3. package/dist/src/analyze.d.ts +95 -0
  4. package/dist/src/analyze.d.ts.map +1 -0
  5. package/dist/src/analyze.js +1110 -0
  6. package/dist/src/analyze.js.map +1 -0
  7. package/dist/src/ast.d.ts +263 -0
  8. package/dist/src/ast.d.ts.map +1 -0
  9. package/dist/src/ast.js +151 -0
  10. package/dist/src/ast.js.map +1 -0
  11. package/dist/src/ast_to_ir.d.ts +24 -0
  12. package/dist/src/ast_to_ir.d.ts.map +1 -0
  13. package/dist/src/ast_to_ir.js +834 -0
  14. package/dist/src/ast_to_ir.js.map +1 -0
  15. package/dist/src/builtins.d.ts +18 -0
  16. package/dist/src/builtins.d.ts.map +1 -0
  17. package/dist/src/builtins.js +1105 -0
  18. package/dist/src/builtins.js.map +1 -0
  19. package/dist/src/comparison.d.ts +28 -0
  20. package/dist/src/comparison.d.ts.map +1 -0
  21. package/dist/src/comparison.js +1017 -0
  22. package/dist/src/comparison.js.map +1 -0
  23. package/dist/src/compile.d.ts +22 -0
  24. package/dist/src/compile.d.ts.map +1 -0
  25. package/dist/src/compile.js +3260 -0
  26. package/dist/src/compile.js.map +1 -0
  27. package/dist/src/containers/ref.d.ts +106 -0
  28. package/dist/src/containers/ref.d.ts.map +1 -0
  29. package/dist/src/containers/ref.js +100 -0
  30. package/dist/src/containers/ref.js.map +1 -0
  31. package/dist/src/containers/sortedmap.d.ts +165 -0
  32. package/dist/src/containers/sortedmap.d.ts.map +1 -0
  33. package/dist/src/containers/sortedmap.js +237 -0
  34. package/dist/src/containers/sortedmap.js.map +1 -0
  35. package/dist/src/containers/sortedset.d.ts +185 -0
  36. package/dist/src/containers/sortedset.d.ts.map +1 -0
  37. package/dist/src/containers/sortedset.js +312 -0
  38. package/dist/src/containers/sortedset.js.map +1 -0
  39. package/dist/src/containers/variant.d.ts +131 -0
  40. package/dist/src/containers/variant.d.ts.map +1 -0
  41. package/dist/src/containers/variant.js +68 -0
  42. package/dist/src/containers/variant.js.map +1 -0
  43. package/dist/src/datetime_format/parse.d.ts +50 -0
  44. package/dist/src/datetime_format/parse.d.ts.map +1 -0
  45. package/dist/src/datetime_format/parse.js +908 -0
  46. package/dist/src/datetime_format/parse.js.map +1 -0
  47. package/dist/src/datetime_format/print.d.ts +35 -0
  48. package/dist/src/datetime_format/print.d.ts.map +1 -0
  49. package/dist/src/datetime_format/print.js +157 -0
  50. package/dist/src/datetime_format/print.js.map +1 -0
  51. package/dist/src/datetime_format/tokenize.d.ts +76 -0
  52. package/dist/src/datetime_format/tokenize.d.ts.map +1 -0
  53. package/dist/src/datetime_format/tokenize.js +271 -0
  54. package/dist/src/datetime_format/tokenize.js.map +1 -0
  55. package/dist/src/datetime_format/types.d.ts +99 -0
  56. package/dist/src/datetime_format/types.d.ts.map +1 -0
  57. package/dist/src/datetime_format/types.js +103 -0
  58. package/dist/src/datetime_format/types.js.map +1 -0
  59. package/dist/src/datetime_format/validate.d.ts +51 -0
  60. package/dist/src/datetime_format/validate.d.ts.map +1 -0
  61. package/dist/src/datetime_format/validate.js +208 -0
  62. package/dist/src/datetime_format/validate.js.map +1 -0
  63. package/dist/src/default.d.ts +21 -0
  64. package/dist/src/default.d.ts.map +1 -0
  65. package/dist/src/default.js +82 -0
  66. package/dist/src/default.js.map +1 -0
  67. package/dist/src/eastir.d.ts +33 -0
  68. package/dist/src/eastir.d.ts.map +1 -0
  69. package/dist/src/eastir.js +92 -0
  70. package/dist/src/eastir.js.map +1 -0
  71. package/dist/src/error.d.ts +13 -0
  72. package/dist/src/error.d.ts.map +1 -0
  73. package/dist/src/error.js +8 -0
  74. package/dist/src/error.js.map +1 -0
  75. package/dist/src/expr/array.d.ts +1711 -0
  76. package/dist/src/expr/array.d.ts.map +1 -0
  77. package/dist/src/expr/array.js +1805 -0
  78. package/dist/src/expr/array.js.map +1 -0
  79. package/dist/src/expr/ast.d.ts +17 -0
  80. package/dist/src/expr/ast.d.ts.map +1 -0
  81. package/dist/src/expr/ast.js +302 -0
  82. package/dist/src/expr/ast.js.map +1 -0
  83. package/dist/src/expr/blob.d.ts +141 -0
  84. package/dist/src/expr/blob.d.ts.map +1 -0
  85. package/dist/src/expr/blob.js +198 -0
  86. package/dist/src/expr/blob.js.map +1 -0
  87. package/dist/src/expr/block.d.ts +201 -0
  88. package/dist/src/expr/block.d.ts.map +1 -0
  89. package/dist/src/expr/block.js +1505 -0
  90. package/dist/src/expr/block.js.map +1 -0
  91. package/dist/src/expr/boolean.d.ts +207 -0
  92. package/dist/src/expr/boolean.d.ts.map +1 -0
  93. package/dist/src/expr/boolean.js +261 -0
  94. package/dist/src/expr/boolean.js.map +1 -0
  95. package/dist/src/expr/datetime.d.ts +544 -0
  96. package/dist/src/expr/datetime.d.ts.map +1 -0
  97. package/dist/src/expr/datetime.js +980 -0
  98. package/dist/src/expr/datetime.js.map +1 -0
  99. package/dist/src/expr/dict.d.ts +1242 -0
  100. package/dist/src/expr/dict.d.ts.map +1 -0
  101. package/dist/src/expr/dict.js +1492 -0
  102. package/dist/src/expr/dict.js.map +1 -0
  103. package/dist/src/expr/expr.d.ts +95 -0
  104. package/dist/src/expr/expr.d.ts.map +1 -0
  105. package/dist/src/expr/expr.js +171 -0
  106. package/dist/src/expr/expr.js.map +1 -0
  107. package/dist/src/expr/float.d.ts +357 -0
  108. package/dist/src/expr/float.d.ts.map +1 -0
  109. package/dist/src/expr/float.js +637 -0
  110. package/dist/src/expr/float.js.map +1 -0
  111. package/dist/src/expr/function.d.ts +46 -0
  112. package/dist/src/expr/function.d.ts.map +1 -0
  113. package/dist/src/expr/function.js +58 -0
  114. package/dist/src/expr/function.js.map +1 -0
  115. package/dist/src/expr/index.d.ts +450 -0
  116. package/dist/src/expr/index.d.ts.map +1 -0
  117. package/dist/src/expr/index.js +423 -0
  118. package/dist/src/expr/index.js.map +1 -0
  119. package/dist/src/expr/integer.d.ts +256 -0
  120. package/dist/src/expr/integer.d.ts.map +1 -0
  121. package/dist/src/expr/integer.js +311 -0
  122. package/dist/src/expr/integer.js.map +1 -0
  123. package/dist/src/expr/libs/array.d.ts +106 -0
  124. package/dist/src/expr/libs/array.d.ts.map +1 -0
  125. package/dist/src/expr/libs/array.js +140 -0
  126. package/dist/src/expr/libs/array.js.map +1 -0
  127. package/dist/src/expr/libs/blob.d.ts +42 -0
  128. package/dist/src/expr/libs/blob.d.ts.map +1 -0
  129. package/dist/src/expr/libs/blob.js +70 -0
  130. package/dist/src/expr/libs/blob.js.map +1 -0
  131. package/dist/src/expr/libs/datetime.d.ts +479 -0
  132. package/dist/src/expr/libs/datetime.d.ts.map +1 -0
  133. package/dist/src/expr/libs/datetime.js +624 -0
  134. package/dist/src/expr/libs/datetime.js.map +1 -0
  135. package/dist/src/expr/libs/dict.d.ts +66 -0
  136. package/dist/src/expr/libs/dict.d.ts.map +1 -0
  137. package/dist/src/expr/libs/dict.js +77 -0
  138. package/dist/src/expr/libs/dict.js.map +1 -0
  139. package/dist/src/expr/libs/float.d.ts +299 -0
  140. package/dist/src/expr/libs/float.d.ts.map +1 -0
  141. package/dist/src/expr/libs/float.js +564 -0
  142. package/dist/src/expr/libs/float.js.map +1 -0
  143. package/dist/src/expr/libs/integer.d.ts +228 -0
  144. package/dist/src/expr/libs/integer.d.ts.map +1 -0
  145. package/dist/src/expr/libs/integer.js +398 -0
  146. package/dist/src/expr/libs/integer.js.map +1 -0
  147. package/dist/src/expr/libs/set.d.ts +59 -0
  148. package/dist/src/expr/libs/set.d.ts.map +1 -0
  149. package/dist/src/expr/libs/set.js +69 -0
  150. package/dist/src/expr/libs/set.js.map +1 -0
  151. package/dist/src/expr/libs/string.d.ts +71 -0
  152. package/dist/src/expr/libs/string.d.ts.map +1 -0
  153. package/dist/src/expr/libs/string.js +75 -0
  154. package/dist/src/expr/libs/string.js.map +1 -0
  155. package/dist/src/expr/never.d.ts +15 -0
  156. package/dist/src/expr/never.d.ts.map +1 -0
  157. package/dist/src/expr/never.js +12 -0
  158. package/dist/src/expr/never.js.map +1 -0
  159. package/dist/src/expr/null.d.ts +15 -0
  160. package/dist/src/expr/null.d.ts.map +1 -0
  161. package/dist/src/expr/null.js +12 -0
  162. package/dist/src/expr/null.js.map +1 -0
  163. package/dist/src/expr/ref.d.ts +103 -0
  164. package/dist/src/expr/ref.d.ts.map +1 -0
  165. package/dist/src/expr/ref.js +131 -0
  166. package/dist/src/expr/ref.js.map +1 -0
  167. package/dist/src/expr/regex_validation.d.ts +25 -0
  168. package/dist/src/expr/regex_validation.d.ts.map +1 -0
  169. package/dist/src/expr/regex_validation.js +130 -0
  170. package/dist/src/expr/regex_validation.js.map +1 -0
  171. package/dist/src/expr/set.d.ts +1071 -0
  172. package/dist/src/expr/set.d.ts.map +1 -0
  173. package/dist/src/expr/set.js +1137 -0
  174. package/dist/src/expr/set.js.map +1 -0
  175. package/dist/src/expr/string.d.ts +414 -0
  176. package/dist/src/expr/string.d.ts.map +1 -0
  177. package/dist/src/expr/string.js +683 -0
  178. package/dist/src/expr/string.js.map +1 -0
  179. package/dist/src/expr/struct.d.ts +48 -0
  180. package/dist/src/expr/struct.d.ts.map +1 -0
  181. package/dist/src/expr/struct.js +65 -0
  182. package/dist/src/expr/struct.js.map +1 -0
  183. package/dist/src/expr/types.d.ts +68 -0
  184. package/dist/src/expr/types.d.ts.map +1 -0
  185. package/dist/src/expr/types.js +6 -0
  186. package/dist/src/expr/types.js.map +1 -0
  187. package/dist/src/expr/variant.d.ts +137 -0
  188. package/dist/src/expr/variant.d.ts.map +1 -0
  189. package/dist/src/expr/variant.js +105 -0
  190. package/dist/src/expr/variant.js.map +1 -0
  191. package/dist/src/fuzz.d.ts +80 -0
  192. package/dist/src/fuzz.d.ts.map +1 -0
  193. package/dist/src/fuzz.js +300 -0
  194. package/dist/src/fuzz.js.map +1 -0
  195. package/dist/src/index.d.ts +21 -0
  196. package/dist/src/index.d.ts.map +1 -0
  197. package/dist/src/index.js +21 -0
  198. package/dist/src/index.js.map +1 -0
  199. package/dist/src/internal.d.ts +36 -0
  200. package/dist/src/internal.d.ts.map +1 -0
  201. package/dist/src/internal.js +11 -0
  202. package/dist/src/internal.js.map +1 -0
  203. package/dist/src/ir.d.ts +1571 -0
  204. package/dist/src/ir.d.ts.map +1 -0
  205. package/dist/src/ir.js +56 -0
  206. package/dist/src/ir.js.map +1 -0
  207. package/dist/src/location.d.ts +48 -0
  208. package/dist/src/location.d.ts.map +1 -0
  209. package/dist/src/location.js +62 -0
  210. package/dist/src/location.js.map +1 -0
  211. package/dist/src/platform.d.ts +21 -0
  212. package/dist/src/platform.d.ts.map +1 -0
  213. package/dist/src/platform.js +8 -0
  214. package/dist/src/platform.js.map +1 -0
  215. package/dist/src/serialization/beast.d.ts +39 -0
  216. package/dist/src/serialization/beast.d.ts.map +1 -0
  217. package/dist/src/serialization/beast.js +555 -0
  218. package/dist/src/serialization/beast.js.map +1 -0
  219. package/dist/src/serialization/beast2-stream.d.ts +38 -0
  220. package/dist/src/serialization/beast2-stream.d.ts.map +1 -0
  221. package/dist/src/serialization/beast2-stream.js +665 -0
  222. package/dist/src/serialization/beast2-stream.js.map +1 -0
  223. package/dist/src/serialization/beast2.d.ts +41 -0
  224. package/dist/src/serialization/beast2.d.ts.map +1 -0
  225. package/dist/src/serialization/beast2.js +489 -0
  226. package/dist/src/serialization/beast2.js.map +1 -0
  227. package/dist/src/serialization/binary-utils.d.ts +151 -0
  228. package/dist/src/serialization/binary-utils.d.ts.map +1 -0
  229. package/dist/src/serialization/binary-utils.js +929 -0
  230. package/dist/src/serialization/binary-utils.js.map +1 -0
  231. package/dist/src/serialization/east.d.ts +84 -0
  232. package/dist/src/serialization/east.d.ts.map +1 -0
  233. package/dist/src/serialization/east.js +1802 -0
  234. package/dist/src/serialization/east.js.map +1 -0
  235. package/dist/src/serialization/index.d.ts +11 -0
  236. package/dist/src/serialization/index.d.ts.map +1 -0
  237. package/dist/src/serialization/index.js +12 -0
  238. package/dist/src/serialization/index.js.map +1 -0
  239. package/dist/src/serialization/json.d.ts +36 -0
  240. package/dist/src/serialization/json.d.ts.map +1 -0
  241. package/dist/src/serialization/json.js +849 -0
  242. package/dist/src/serialization/json.js.map +1 -0
  243. package/dist/src/type_of_type.d.ts +115 -0
  244. package/dist/src/type_of_type.d.ts.map +1 -0
  245. package/dist/src/type_of_type.js +362 -0
  246. package/dist/src/type_of_type.js.map +1 -0
  247. package/dist/src/types.d.ts +648 -0
  248. package/dist/src/types.d.ts.map +1 -0
  249. package/dist/src/types.js +1631 -0
  250. package/dist/src/types.js.map +1 -0
  251. package/package.json +87 -0
@@ -0,0 +1,1071 @@
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 { SetType, BooleanType, FunctionType, IntegerType, NullType, NeverType, DictType, FloatType, ArrayType, VariantType } from "../types.js";
7
+ import type { BooleanExpr } from "./boolean.js";
8
+ import type { IntegerExpr } from "./integer.js";
9
+ import { Expr, type ToExpr } from "./expr.js";
10
+ import type { ExprType, SubtypeExprOrValue, TypeOf } from "./types.js";
11
+ import type { NullExpr } from "./null.js";
12
+ import type { DictExpr } from "./dict.js";
13
+ import type { BlockBuilder } from "./block.js";
14
+ import type { FloatExpr } from "./float.js";
15
+ import type { ArrayExpr } from "./array.js";
16
+ /**
17
+ * Expression representing set (sorted unique collection) values and operations.
18
+ *
19
+ * SetExpr provides methods for working with sorted sets including membership testing, insertion,
20
+ * deletion, iteration, mapping, filtering, set operations (union, intersection, difference), and
21
+ * aggregation operations. Sets maintain their elements sorted by key using East's total ordering
22
+ * and guarantee uniqueness.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * // Creating and manipulating sets
27
+ * const buildSet = East.function([ArrayType(StringType)], SetType(StringType), ($, items) => {
28
+ * const uniqueItems = Expr.from(new Set(), SetType(StringType));
29
+ * $(items.forEach(($, item) => {
30
+ * $(uniqueItems.tryInsert(item));
31
+ * }));
32
+ * $.return(uniqueItems);
33
+ * });
34
+ * const compiled = East.compile(buildSet.toIR(), []);
35
+ * compiled(["apple", "banana", "apple", "cherry"]); // Set(["apple", "banana", "cherry"])
36
+ * ```
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * // Set operations
41
+ * const unionSets = East.function([SetType(IntegerType), SetType(IntegerType)], SetType(IntegerType), ($, set1, set2) => {
42
+ * $.return(set1.union(set2));
43
+ * });
44
+ * const compiled = East.compile(unionSets.toIR(), []);
45
+ * compiled(new Set([1n, 2n, 3n]), new Set([3n, 4n, 5n])); // Set([1n, 2n, 3n, 4n, 5n])
46
+ * ```
47
+ */
48
+ export declare class SetExpr<K extends any> extends Expr<SetType<K>> {
49
+ private key_type;
50
+ constructor(key_type: K, ast: AST, createExpr: ToExpr);
51
+ /**
52
+ * Returns the number of elements in the set.
53
+ *
54
+ * @returns An IntegerExpr representing the count of elements
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const getSize = East.function([SetType(StringType)], IntegerType, ($, set) => {
59
+ * $.return(set.size());
60
+ * });
61
+ * const compiled = East.compile(getSize.toIR(), []);
62
+ * compiled(new Set(["a", "b", "c"])); // 3n
63
+ * compiled(new Set()); // 0n
64
+ * ```
65
+ */
66
+ size(): IntegerExpr;
67
+ /**
68
+ * Checks if an element exists in the set.
69
+ *
70
+ * @param key - The element to search for
71
+ * @returns A BooleanExpr that is true if the element exists, false otherwise
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const hasElement = East.function([SetType(StringType), StringType], BooleanType, ($, set, element) => {
76
+ * $.return(set.has(element));
77
+ * });
78
+ * const compiled = East.compile(hasElement.toIR(), []);
79
+ * const set = new Set(["a", "b", "c"]);
80
+ * compiled(set, "b"); // true
81
+ * compiled(set, "d"); // false
82
+ * ```
83
+ */
84
+ has(key: SubtypeExprOrValue<K>): BooleanExpr;
85
+ /**
86
+ * Inserts a new element into the set.
87
+ *
88
+ * @param key - The element to insert
89
+ * @returns A NullExpr
90
+ *
91
+ * @throws East runtime error if the element already exists in the set
92
+ *
93
+ * @see {@link tryInsert} for a version that doesn't error on duplicates
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * const insertElement = East.function([SetType(StringType), StringType], NullType, ($, set, element) => {
98
+ * $(set.insert(element));
99
+ * $.return(null);
100
+ * });
101
+ * const compiled = East.compile(insertElement.toIR(), []);
102
+ * const set = new Set(["a", "b"]);
103
+ * compiled(set, "c"); // set now has Set(["a", "b", "c"])
104
+ * // compiled(set, "a") would throw error (duplicate element)
105
+ * ```
106
+ */
107
+ insert(key: SubtypeExprOrValue<K>): NullExpr;
108
+ /**
109
+ * Tries to insert an element into the set, returning whether it was inserted.
110
+ *
111
+ * @param key - The element to insert
112
+ * @returns A BooleanExpr that is true if the element was inserted, false if it already existed
113
+ *
114
+ * @see {@link insert} for a version that errors on duplicates
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * const tryInsertElement = East.function([SetType(StringType), StringType], BooleanType, ($, set, element) => {
119
+ * $.return(set.tryInsert(element));
120
+ * });
121
+ * const compiled = East.compile(tryInsertElement.toIR(), []);
122
+ * const set = new Set(["a", "b"]);
123
+ * compiled(set, "c"); // true (set now has Set(["a", "b", "c"]))
124
+ * compiled(set, "a"); // false (element already exists, set unchanged)
125
+ * ```
126
+ */
127
+ tryInsert(key: SubtypeExprOrValue<K>): BooleanExpr;
128
+ /**
129
+ * Deletes an element from the set.
130
+ *
131
+ * @param key - The element to delete
132
+ * @returns A NullExpr
133
+ *
134
+ * @throws East runtime error if the element does not exist
135
+ *
136
+ * @see {@link tryDelete} for a version that doesn't error on missing elements
137
+ * @see {@link clear} to remove all elements
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * const deleteElement = East.function([SetType(StringType), StringType], NullType, ($, set, element) => {
142
+ * $(set.delete(element));
143
+ * $.return(null);
144
+ * });
145
+ * const compiled = East.compile(deleteElement.toIR(), []);
146
+ * const set = new Set(["a", "b", "c"]);
147
+ * compiled(set, "b"); // set now has Set(["a", "c"])
148
+ * // compiled(set, "d") would throw error (element not found)
149
+ * ```
150
+ */
151
+ delete(key: SubtypeExprOrValue<K>): NullExpr;
152
+ /**
153
+ * Tries to delete an element from the set, returning whether it was deleted.
154
+ *
155
+ * @param key - The element to delete
156
+ * @returns A BooleanExpr that is true if the element was deleted, false if it didn't exist
157
+ *
158
+ * @see {@link delete} for a version that errors on missing elements
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * const tryDeleteElement = East.function([SetType(StringType), StringType], BooleanType, ($, set, element) => {
163
+ * $.return(set.tryDelete(element));
164
+ * });
165
+ * const compiled = East.compile(tryDeleteElement.toIR(), []);
166
+ * const set = new Set(["a", "b", "c"]);
167
+ * compiled(set, "b"); // true (set now has Set(["a", "c"]))
168
+ * compiled(set, "d"); // false (element not found, set unchanged)
169
+ * ```
170
+ */
171
+ tryDelete(key: SubtypeExprOrValue<K>): BooleanExpr;
172
+ /**
173
+ * Removes all elements from the set.
174
+ *
175
+ * @returns A NullExpr
176
+ *
177
+ * @see {@link delete} or {@link tryDelete} to remove individual elements
178
+ *
179
+ * @example
180
+ * ```ts
181
+ * const clearSet = East.function([SetType(StringType)], NullType, ($, set) => {
182
+ * $(set.clear());
183
+ * $.return(null);
184
+ * });
185
+ * const compiled = East.compile(clearSet.toIR(), []);
186
+ * const set = new Set(["a", "b", "c"]);
187
+ * compiled(set); // set is now Set([])
188
+ * ```
189
+ */
190
+ clear(): NullExpr;
191
+ /**
192
+ * Unions another set into this one in place.
193
+ *
194
+ * @param other - The set whose elements to add to this set
195
+ * @returns A NullExpr
196
+ *
197
+ * @see {@link union} for a version that returns a new set
198
+ *
199
+ * @example
200
+ * ```ts
201
+ * const unionInPlace = East.function([SetType(IntegerType), SetType(IntegerType)], NullType, ($, set1, set2) => {
202
+ * $(set1.unionInPlace(set2));
203
+ * $.return(null);
204
+ * });
205
+ * const compiled = East.compile(unionInPlace.toIR(), []);
206
+ * const set1 = new Set([1n, 2n, 3n]);
207
+ * const set2 = new Set([3n, 4n, 5n]);
208
+ * compiled(set1, set2); // set1 now has Set([1n, 2n, 3n, 4n, 5n])
209
+ * ```
210
+ */
211
+ unionInPlace(other: SubtypeExprOrValue<SetType<K>>): NullExpr;
212
+ /**
213
+ * Returns the union of two sets (all elements from both sets).
214
+ *
215
+ * @param other - The set to union with this set
216
+ * @returns A new SetExpr containing all elements from both sets
217
+ *
218
+ * @see {@link unionInPlace} to modify this set in place
219
+ *
220
+ * @example
221
+ * ```ts
222
+ * const unionSets = East.function([SetType(IntegerType), SetType(IntegerType)], SetType(IntegerType), ($, set1, set2) => {
223
+ * $.return(set1.union(set2));
224
+ * });
225
+ * const compiled = East.compile(unionSets.toIR(), []);
226
+ * compiled(new Set([1n, 2n, 3n]), new Set([3n, 4n, 5n])); // Set([1n, 2n, 3n, 4n, 5n])
227
+ * ```
228
+ */
229
+ union(other: SubtypeExprOrValue<SetType<K>>): SetExpr<K>;
230
+ /**
231
+ * Returns the intersection of two sets (elements common to both).
232
+ *
233
+ * @param other - The set to intersect with this set
234
+ * @returns A new SetExpr containing only elements present in both sets
235
+ *
236
+ * @example
237
+ * ```ts
238
+ * const intersectSets = East.function([SetType(IntegerType), SetType(IntegerType)], SetType(IntegerType), ($, set1, set2) => {
239
+ * $.return(set1.intersection(set2));
240
+ * });
241
+ * const compiled = East.compile(intersectSets.toIR(), []);
242
+ * compiled(new Set([1n, 2n, 3n]), new Set([2n, 3n, 4n])); // Set([2n, 3n])
243
+ * ```
244
+ */
245
+ intersection(other: SubtypeExprOrValue<SetType<K>>): SetExpr<K>;
246
+ /**
247
+ * Returns the difference between two sets (elements in this set but not in the other).
248
+ *
249
+ * @param other - The set to subtract from this set
250
+ * @returns A new SetExpr containing elements in this set but not in the other
251
+ *
252
+ * @example
253
+ * ```ts
254
+ * const diffSets = East.function([SetType(IntegerType), SetType(IntegerType)], SetType(IntegerType), ($, set1, set2) => {
255
+ * $.return(set1.difference(set2));
256
+ * });
257
+ * const compiled = East.compile(diffSets.toIR(), []);
258
+ * compiled(new Set([1n, 2n, 3n]), new Set([2n, 3n, 4n])); // Set([1n])
259
+ * ```
260
+ */
261
+ difference(other: SubtypeExprOrValue<SetType<K>>): SetExpr<K>;
262
+ /**
263
+ * Returns the symmetric difference between two sets (elements in either set but not in both).
264
+ *
265
+ * @param other - The set to compute symmetric difference with
266
+ * @returns A new SetExpr containing elements in either set but not in both
267
+ *
268
+ * @example
269
+ * ```ts
270
+ * const symDiffSets = East.function([SetType(IntegerType), SetType(IntegerType)], SetType(IntegerType), ($, set1, set2) => {
271
+ * $.return(set1.symmetricDifference(set2));
272
+ * });
273
+ * const compiled = East.compile(symDiffSets.toIR(), []);
274
+ * compiled(new Set([1n, 2n, 3n]), new Set([2n, 3n, 4n])); // Set([1n, 4n])
275
+ * ```
276
+ */
277
+ symmetricDifference(other: SubtypeExprOrValue<SetType<K>>): SetExpr<K>;
278
+ /**
279
+ * Checks if this set is a subset of another set (all elements in this set are in the other).
280
+ *
281
+ * @param other - The set to check against
282
+ * @returns A BooleanExpr that is true if this set is a subset of the other
283
+ *
284
+ * @example
285
+ * ```ts
286
+ * const checkSubset = East.function([SetType(IntegerType), SetType(IntegerType)], BooleanType, ($, set1, set2) => {
287
+ * $.return(set1.isSubsetOf(set2));
288
+ * });
289
+ * const compiled = East.compile(checkSubset.toIR(), []);
290
+ * compiled(new Set([1n, 2n]), new Set([1n, 2n, 3n])); // true
291
+ * compiled(new Set([1n, 4n]), new Set([1n, 2n, 3n])); // false
292
+ * ```
293
+ */
294
+ isSubsetOf(other: SubtypeExprOrValue<SetType<K>>): BooleanExpr;
295
+ /**
296
+ * Checks if this set is a superset of another set (all elements in the other set are in this set).
297
+ *
298
+ * @param other - The set to check against
299
+ * @returns A BooleanExpr that is true if this set is a superset of the other
300
+ *
301
+ * @example
302
+ * ```ts
303
+ * const checkSuperset = East.function([SetType(IntegerType), SetType(IntegerType)], BooleanType, ($, set1, set2) => {
304
+ * $.return(set1.isSupersetOf(set2));
305
+ * });
306
+ * const compiled = East.compile(checkSuperset.toIR(), []);
307
+ * compiled(new Set([1n, 2n, 3n]), new Set([1n, 2n])); // true
308
+ * compiled(new Set([1n, 2n]), new Set([1n, 2n, 3n])); // false
309
+ * ```
310
+ */
311
+ isSupersetOf(other: SubtypeExprOrValue<SetType<K>>): BooleanExpr;
312
+ /**
313
+ * Checks if this set is disjoint from another set (no common elements).
314
+ *
315
+ * @param other - The set to check against
316
+ * @returns A BooleanExpr that is true if the sets have no elements in common
317
+ *
318
+ * @example
319
+ * ```ts
320
+ * const checkDisjoint = East.function([SetType(IntegerType), SetType(IntegerType)], BooleanType, ($, set1, set2) => {
321
+ * $.return(set1.isDisjointFrom(set2));
322
+ * });
323
+ * const compiled = East.compile(checkDisjoint.toIR(), []);
324
+ * compiled(new Set([1n, 2n]), new Set([3n, 4n])); // true
325
+ * compiled(new Set([1n, 2n]), new Set([2n, 3n])); // false
326
+ * ```
327
+ */
328
+ isDisjointFrom(other: SubtypeExprOrValue<SetType<K>>): BooleanExpr;
329
+ /**
330
+ * Creates a shallow copy of the set.
331
+ *
332
+ * @returns A new SetExpr containing the same elements
333
+ *
334
+ * @example
335
+ * ```ts
336
+ * const copySet = East.function([SetType(StringType)], SetType(StringType), ($, set) => {
337
+ * $.return(set.copy());
338
+ * });
339
+ * const compiled = East.compile(copySet.toIR(), []);
340
+ * const set = new Set(["a", "b", "c"]);
341
+ * const copy = compiled(set); // Set(["a", "b", "c"])
342
+ * // Modifying copy doesn't affect set
343
+ * ```
344
+ */
345
+ copy(): SetExpr<K>;
346
+ /**
347
+ * Filters the set using a predicate function.
348
+ *
349
+ * @param pred - Function that returns true to keep an element, false to discard it
350
+ * @returns A new SetExpr containing only elements for which the predicate returned true
351
+ *
352
+ * @example
353
+ * ```ts
354
+ * const filterEven = East.function([SetType(IntegerType)], SetType(IntegerType), ($, set) => {
355
+ * $.return(set.filter(($, x) => x.modulo(2n).equal(0n)));
356
+ * });
357
+ * const compiled = East.compile(filterEven.toIR(), []);
358
+ * compiled(new Set([1n, 2n, 3n, 4n, 5n, 6n])); // Set([2n, 4n, 6n])
359
+ * ```
360
+ */
361
+ filter(pred: SubtypeExprOrValue<FunctionType<[K], BooleanType>>): SetExpr<K>;
362
+ /** Combined filter and map operation using Option types.
363
+ *
364
+ * Applies a function to each key in the set. If the function returns `some(value)`,
365
+ * the key is included in the result dictionary with the transformed value. If it returns `none`,
366
+ * the key is excluded.
367
+ *
368
+ * @param fn - Function that takes a key and returns an option containing the transformed value
369
+ * @returns A dictionary mapping keys to transformed values for keys where the function returned `some`
370
+ *
371
+ * @example
372
+ * ```ts
373
+ * const s = new Set([1n, 2n, 3n, 4n, 5n])
374
+ * // Only include even numbers, mapping them to their string representation
375
+ * const result = s.filterMap(($, x) =>
376
+ * x.remainder(2n).equal(0n).if(
377
+ * () => East.some(East.print(x)),
378
+ * () => East.none
379
+ * )
380
+ * )
381
+ * // Result: { 2: "2", 4: "4" }
382
+ * ```
383
+ */
384
+ filterMap<V2>(fn: Expr<FunctionType<[K], VariantType<{
385
+ none: NullType;
386
+ some: V2;
387
+ }>>>): DictExpr<K, V2>;
388
+ filterMap<F extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(fn: F): DictExpr<K, any>;
389
+ /**
390
+ * Find the first key where the mapping function returns `some(value)`, and return that value wrapped in an Option.
391
+ *
392
+ * The supplied function must return an Option type. This method stops iterating as soon as the first `some` value is found,
393
+ * making it efficient for early termination searches.
394
+ *
395
+ * Returns `none` if no key produces a `some` value, or `some(value)` with the first mapped result.
396
+ *
397
+ * @param fn - Function that maps each key to an Option type
398
+ * @returns Option containing the first successfully mapped value, or `none` if none found
399
+ *
400
+ * @example
401
+ * ```ts
402
+ * const s = new Set([1n, 2n, 3n, 4n, 5n])
403
+ * // Find the first even number and return its square
404
+ * const result = s.firstMap(($, x) =>
405
+ * x.remainder(2n).equal(0n).ifElse(
406
+ * () => East.some(x.multiply(x)),
407
+ * () => East.none
408
+ * )
409
+ * )
410
+ * // Result: some(4n)
411
+ * ```
412
+ *
413
+ * @see {@link filterMap} to collect all mapped values that return `some` (scans entire set).
414
+ */
415
+ firstMap<T2>(fn: Expr<FunctionType<[K], VariantType<{
416
+ none: NullType;
417
+ some: T2;
418
+ }>>>): Expr<VariantType<{
419
+ none: NullType;
420
+ some: T2;
421
+ }>>;
422
+ firstMap<F extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(fn: F): ExprType<TypeOf<ReturnType<F>>>;
423
+ /**
424
+ * Iterates over each element in the set, applying a function to each.
425
+ *
426
+ * @param fn - Function to apply to each element
427
+ * @returns A NullExpr
428
+ *
429
+ * @example
430
+ * ```ts
431
+ * const printElements = East.function([SetType(StringType)], NullType, ($, set) => {
432
+ * $(set.forEach(($, element) => {
433
+ * // In a real platform, you could use a platform function to log
434
+ * }));
435
+ * $.return(null);
436
+ * });
437
+ * const compiled = East.compile(printElements.toIR(), []);
438
+ * compiled(new Set(["a", "b", "c"])); // Iterates over all elements
439
+ * ```
440
+ */
441
+ forEach(fn: SubtypeExprOrValue<FunctionType<[K], undefined>>): NullExpr;
442
+ /**
443
+ * Creates a dictionary by mapping each element through a function.
444
+ *
445
+ * The dictionary keys are the original set elements, and the values are the results of the mapping function.
446
+ *
447
+ * @param fn - Function that maps each element to a value
448
+ * @returns A DictExpr with set elements as keys and mapped values as values
449
+ *
450
+ * @example
451
+ * ```ts
452
+ * const mapToLengths = East.function([SetType(StringType)], DictType(StringType, IntegerType), ($, set) => {
453
+ * $.return(set.map(($, str) => str.size()));
454
+ * });
455
+ * const compiled = East.compile(mapToLengths.toIR(), []);
456
+ * compiled(new Set(["a", "hello", "world"])); // Map([["a", 1n], ["hello", 5n], ["world", 5n]])
457
+ * ```
458
+ */
459
+ map<T2>(fn: Expr<FunctionType<[K], T2>>): DictExpr<K, T2>;
460
+ map<F extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(fn: F): DictExpr<K, TypeOf<ReturnType<F>>>;
461
+ /**
462
+ * Reduce set to single value using projection and accumulator functions.
463
+ *
464
+ * The first element of the set is used as initial value and reduction starts from the second element.
465
+ * If the set is empty, an error is thrown.
466
+ *
467
+ * @param mapFn - Function that projects each key to a value
468
+ * @param combineFn - Function that combines two projected values
469
+ * @returns The final reduced value
470
+ *
471
+ * @example
472
+ * ```ts
473
+ * const s = new Set([1n, 2n, 3n, 4n, 5n])
474
+ * // Sum of squares
475
+ * const result = s.mapReduce(
476
+ * ($, x) => x.multiply(x),
477
+ * ($, a, b) => a.add(b)
478
+ * )
479
+ * // Result: 55n (1 + 4 + 9 + 16 + 25)
480
+ * ```
481
+ *
482
+ * @see {@link reduce} for a version with an initial value
483
+ */
484
+ mapReduce<T2>(mapFn: Expr<FunctionType<[K], T2>>, combineFn: SubtypeExprOrValue<FunctionType<[previous: NoInfer<T2>, value: NoInfer<T2>], NoInfer<T2>>>): ExprType<T2>;
485
+ mapReduce<F extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(mapFn: F, combineFn: SubtypeExprOrValue<FunctionType<[previous: NoInfer<TypeOf<ReturnType<F>>>, value: NoInfer<TypeOf<ReturnType<F>>>], NoInfer<TypeOf<ReturnType<F>>>>>): ExprType<TypeOf<ReturnType<F>>>;
486
+ /**
487
+ * Reduces the set to a single value using an accumulator function.
488
+ *
489
+ * @param fn - Function accepting (accumulator, element) and returning the new accumulator value
490
+ * @param init - Initial value for the accumulator
491
+ * @returns The final accumulated value
492
+ *
493
+ * @see {@link mapReduce} for a version that projects elements before combining
494
+ *
495
+ * @example
496
+ * ```ts
497
+ * const sumSet = East.function([SetType(IntegerType)], IntegerType, ($, set) => {
498
+ * $.return(set.reduce(($, acc, element) => acc.add(element), 0n));
499
+ * });
500
+ * const compiled = East.compile(sumSet.toIR(), []);
501
+ * compiled(new Set([1n, 2n, 3n, 4n])); // 10n
502
+ * ```
503
+ */
504
+ reduce<T2>(fn: SubtypeExprOrValue<FunctionType<[TypeOf<NoInfer<T2>>, K], TypeOf<NoInfer<T2>>>>, init: T2): ExprType<TypeOf<NoInfer<T2>>>;
505
+ /**
506
+ * Creates an array from the set by mapping each element through a function.
507
+ *
508
+ * If no function is provided, the set elements are copied as-is.
509
+ *
510
+ * @param fn - Optional function to map each element to an array value
511
+ * @returns An ArrayExpr containing the mapped values
512
+ *
513
+ * @example
514
+ * ```ts
515
+ * const setToArray = East.function([SetType(IntegerType)], ArrayType(IntegerType), ($, set) => {
516
+ * $.return(set.toArray());
517
+ * });
518
+ * const compiled = East.compile(setToArray.toIR(), []);
519
+ * compiled(new Set([3n, 1n, 2n])); // [1n, 2n, 3n] (sorted order)
520
+ * ```
521
+ *
522
+ * @example
523
+ * ```ts
524
+ * // With mapping function
525
+ * const doubleToArray = East.function([SetType(IntegerType)], ArrayType(IntegerType), ($, set) => {
526
+ * $.return(set.toArray(($, x) => x.multiply(2n)));
527
+ * });
528
+ * const compiled = East.compile(doubleToArray.toIR(), []);
529
+ * compiled(new Set([1n, 2n, 3n])); // [2n, 4n, 6n]
530
+ * ```
531
+ */
532
+ toArray<T2>(fn: Expr<FunctionType<[K], T2>>): ArrayExpr<T2>;
533
+ toArray<F extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(fn: F): ArrayExpr<TypeOf<ReturnType<F>>>;
534
+ toArray(): K extends IntegerType | FloatType | BooleanType | NullType | string ? ArrayExpr<K> : never;
535
+ /**
536
+ * Creates a new set by mapping each element through a function.
537
+ *
538
+ * Duplicates produced by the mapping function are ignored, and only unique values are kept.
539
+ *
540
+ * @param fn - Function to map each element to a new set element
541
+ * @returns A SetExpr containing the unique mapped values
542
+ *
543
+ * @example
544
+ * ```ts
545
+ * const extractFirstChar = East.function([SetType(StringType)], SetType(StringType), ($, set) => {
546
+ * $.return(set.toSet(($, str) => str.substring(0n, 1n)));
547
+ * });
548
+ * const compiled = East.compile(extractFirstChar.toIR(), []);
549
+ * compiled(new Set(["apple", "apricot", "banana", "blueberry"])); // Set(["a", "b"])
550
+ * ```
551
+ */
552
+ toSet<K2>(fn: Expr<FunctionType<[K], K2>>): SetExpr<K2>;
553
+ toSet<F extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(fn: F): SetExpr<TypeOf<ReturnType<F>>>;
554
+ /**
555
+ * Converts the set to a dictionary using custom key and value functions.
556
+ *
557
+ * @param keyFn - Optional function that maps each element to a dictionary key (defaults to identity)
558
+ * @param valueFn - Optional function that maps each element to a dictionary value (defaults to identity)
559
+ * @param onConflict - Optional function to handle duplicate keys, receives (existing_value, new_value, key) and returns the value to keep
560
+ * @returns A DictExpr containing the converted elements
561
+ *
562
+ * @throws East runtime error if duplicate keys are produced and no conflict handler is provided
563
+ *
564
+ * @see {@link toArray} to convert to an array, {@link toSet} to transform element types
565
+ *
566
+ * @example
567
+ * ```ts
568
+ * // Convert set to dict with custom keys and values
569
+ * const convertToDict = East.function([SetType(StringType)], DictType(IntegerType, StringType), ($, words) => {
570
+ * $.return(words.toDict(
571
+ * ($, word) => word.size(), // Key: word length
572
+ * ($, word) => word.upper(), // Value: uppercase word
573
+ * ($, existing, newVal, key) => existing // Keep first value on conflict
574
+ * ));
575
+ * });
576
+ * const compiled = East.compile(convertToDict.toIR(), []);
577
+ * compiled(new Set(["hi", "bye", "up"])); // { 2n: "HI", 3n: "BYE" }
578
+ * ```
579
+ *
580
+ * @example
581
+ * ```ts
582
+ * // Simple conversion with identity functions
583
+ * const identityDict = East.function([SetType(StringType)], DictType(StringType, StringType), ($, items) => {
584
+ * $.return(items.toDict()); // Same key and value
585
+ * });
586
+ * const compiled = East.compile(identityDict.toIR(), []);
587
+ * compiled(new Set(["a", "b"])); // { "a": "a", "b": "b" }
588
+ * ```
589
+ */
590
+ toDict<K2, T2>(keyFn: Expr<FunctionType<[K], K2>>, valueFn: Expr<FunctionType<[K], T2>>, onConflict?: SubtypeExprOrValue<FunctionType<[NoInfer<T2>, NoInfer<T2>, NoInfer<K2>], NoInfer<T2>>>): DictExpr<K2, T2>;
591
+ toDict<K2, ValueFn extends (($: BlockBuilder<NeverType>, k: ExprType<K>) => any)>(keyFn: Expr<FunctionType<[K], 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>>>;
592
+ toDict<KeyFn extends (($: BlockBuilder<NeverType>, k: ExprType<K>) => any), T2>(keyFn: KeyFn, valueFn: Expr<FunctionType<[K], T2>>, onConflict?: SubtypeExprOrValue<FunctionType<[NoInfer<T2>, NoInfer<T2>, TypeOf<ReturnType<NoInfer<KeyFn>>>], NoInfer<T2>>>): DictExpr<TypeOf<ReturnType<KeyFn>>, T2>;
593
+ toDict<KeyFn extends (($: BlockBuilder<NeverType>, k: ExprType<K>) => any), ValueFn extends (($: BlockBuilder<NeverType>, k: ExprType<K>) => 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>>>;
594
+ toDict<K2>(keyFn: Expr<FunctionType<[K], K2>>): DictExpr<K2, K>;
595
+ toDict<KeyFn extends (($: BlockBuilder<NeverType>, k: ExprType<K>) => any)>(keyFn: KeyFn): DictExpr<TypeOf<ReturnType<KeyFn>>, K>;
596
+ toDict(): DictExpr<K, K>;
597
+ /**
598
+ * Maps each element to an array and concatenates all resulting arrays into a single array.
599
+ *
600
+ * @param fn - Function that maps each element to an array
601
+ * @returns An ArrayExpr containing all elements from all arrays, concatenated in order
602
+ *
603
+ * @remarks The function must return an Array type. Use this for one-to-many transformations.
604
+ *
605
+ * @see {@link toArray} to create an array with the same number of elements, {@link flattenToSet} to flatten to a set, {@link flattenToDict} to flatten to a dictionary
606
+ *
607
+ * @example
608
+ * ```ts
609
+ * // Expand each number to a range of numbers
610
+ * const expandRanges = East.function([SetType(IntegerType)], ArrayType(IntegerType), ($, numbers) => {
611
+ * $.return(numbers.flattenToArray(($, n) => {
612
+ * const result = Expr.from([], ArrayType(IntegerType));
613
+ * $(Expr.for(0n, n, ($, i) => {
614
+ * $(result.push(i));
615
+ * }));
616
+ * return result;
617
+ * }));
618
+ * });
619
+ * const compiled = East.compile(expandRanges.toIR(), []);
620
+ * compiled(new Set([2n, 3n])); // [0n, 1n, 0n, 1n, 2n]
621
+ * ```
622
+ */
623
+ flattenToArray<T2>(fn: Expr<FunctionType<[K], ArrayType<T2>>>): ArrayExpr<T2>;
624
+ flattenToArray<F extends (($: BlockBuilder<NeverType>, k: ExprType<K>) => any)>(fn: F): TypeOf<ReturnType<F>> extends ArrayType<infer U> ? ArrayExpr<U> : never;
625
+ /**
626
+ * Maps each element to a set and unions all resulting sets into a single set.
627
+ *
628
+ * @param fn - Function that maps each element to a set
629
+ * @returns A SetExpr containing all unique elements from all sets
630
+ *
631
+ * @remarks The function must return a Set type. Duplicates are automatically removed.
632
+ *
633
+ * @see {@link flattenToArray} to flatten to an array, {@link flattenToDict} to flatten to a dictionary, {@link toSet} to map without flattening
634
+ *
635
+ * @example
636
+ * ```ts
637
+ * // Generate multiples for each number
638
+ * const generateMultiples = East.function([SetType(IntegerType)], SetType(IntegerType), ($, numbers) => {
639
+ * $.return(numbers.flattenToSet(($, n) => {
640
+ * const multiples = Expr.from(new Set(), SetType(IntegerType));
641
+ * $(multiples.insert(n.multiply(2n)));
642
+ * $(multiples.insert(n.multiply(3n)));
643
+ * return multiples;
644
+ * }));
645
+ * });
646
+ * const compiled = East.compile(generateMultiples.toIR(), []);
647
+ * compiled(new Set([2n, 3n])); // Set([4n, 6n, 9n]) (6n appears once)
648
+ * ```
649
+ */
650
+ flattenToSet<K2>(fn: Expr<FunctionType<[K], SetType<K2>>>): SetExpr<K2>;
651
+ flattenToSet<F extends (($: BlockBuilder<NeverType>, k: ExprType<K>) => any)>(fn: F): TypeOf<ReturnType<F>> extends SetType<infer U> ? SetExpr<U> : never;
652
+ /**
653
+ * Maps each element to a dictionary and merges all resulting dictionaries into a single dictionary.
654
+ *
655
+ * @param fn - Function that maps each element to a dictionary
656
+ * @param onConflict - Optional function to handle duplicate keys, receives (existing_value, new_value, key) and returns the value to keep
657
+ * @returns A DictExpr containing all entries from all dictionaries
658
+ *
659
+ * @throws East runtime error if duplicate keys are produced and no conflict handler is provided
660
+ *
661
+ * @remarks The function must return a Dict type. Use this for one-to-many transformations with key-value pairs.
662
+ *
663
+ * @see {@link flattenToArray} to flatten to an array, {@link flattenToSet} to flatten to a set, {@link toDict} to convert without flattening
664
+ *
665
+ * @example
666
+ * ```ts
667
+ * // Generate word statistics for each prefix
668
+ * const wordStats = East.function([SetType(StringType)], DictType(StringType, IntegerType), ($, prefixes) => {
669
+ * $.return(prefixes.flattenToDict(($, prefix) => {
670
+ * const stats = Expr.from(new Map(), DictType(StringType, IntegerType));
671
+ * $(stats.set(Expr.str`${prefix}_count`, prefix.size()));
672
+ * $(stats.set(Expr.str`${prefix}_double`, prefix.size().multiply(2n)));
673
+ * return stats;
674
+ * }));
675
+ * });
676
+ * const compiled = East.compile(wordStats.toIR(), []);
677
+ * compiled(new Set(["hi", "bye"])); // { "hi_count": 2n, "hi_double": 4n, "bye_count": 3n, "bye_double": 6n }
678
+ * ```
679
+ */
680
+ flattenToDict<K2, V2>(fn: Expr<FunctionType<[K], DictType<K2, V2>>>, onConflict?: SubtypeExprOrValue<FunctionType<[NoInfer<V2>, NoInfer<V2>, NoInfer<K2>], NoInfer<V2>>>): DictExpr<K2, V2>;
681
+ flattenToDict<F extends (($: BlockBuilder<NeverType>, k: ExprType<K>) => 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;
682
+ /**
683
+ * Groups elements by a key and performs a fold/reduce operation on each group.
684
+ *
685
+ * @param keyFn - Function that maps each element to a group key
686
+ * @param initFn - Function that creates the initial accumulator value for each group
687
+ * @param reduceFn - Function that combines the accumulator with each element in the group
688
+ * @returns A DictExpr mapping group keys to reduced values
689
+ *
690
+ * @see {@link groupToArrays} to collect elements into arrays, {@link groupToSets} to collect into sets
691
+ *
692
+ * @example
693
+ * ```ts
694
+ * // Group by even/odd and sum each group
695
+ * const groupSum = East.function([SetType(IntegerType)], DictType(StringType, IntegerType), ($, numbers) => {
696
+ * $.return(numbers.groupReduce(
697
+ * ($, x) => x.remainder(2n).equal(0n).ifElse(() => "even", () => "odd"),
698
+ * ($, groupKey) => 0n,
699
+ * ($, acc, x) => acc.add(x)
700
+ * ));
701
+ * });
702
+ * const compiled = East.compile(groupSum.toIR(), []);
703
+ * compiled(new Set([1n, 2n, 3n, 4n, 5n, 6n])); // { "even": 12n, "odd": 9n }
704
+ * ```
705
+ */
706
+ groupReduce<K2, T2>(keyFn: Expr<FunctionType<[K], K2>>, initFn: Expr<FunctionType<[K2], T2>>, reduceFn: SubtypeExprOrValue<FunctionType<[T2, K], T2>>): DictExpr<K2, T2>;
707
+ groupReduce<K2, InitFn extends ($: BlockBuilder<NeverType>, k2: ExprType<NoInfer<K2>>) => any>(keyFn: Expr<FunctionType<[K], K2>>, initFn: InitFn, reduceFn: SubtypeExprOrValue<FunctionType<[TypeOf<ReturnType<NoInfer<InitFn>>>, K], TypeOf<ReturnType<NoInfer<InitFn>>>>>): DictExpr<K2, TypeOf<ReturnType<InitFn>>>;
708
+ groupReduce<KeyFn extends ($: BlockBuilder<NeverType>, key: ExprType<K>) => any, T2>(keyFn: KeyFn, initFn: Expr<FunctionType<[TypeOf<ReturnType<NoInfer<KeyFn>>>], T2>>, reduceFn: SubtypeExprOrValue<FunctionType<[T2, K], T2>>): DictExpr<TypeOf<ReturnType<KeyFn>>, T2>;
709
+ groupReduce<KeyFn extends ($: BlockBuilder<NeverType>, key: ExprType<K>) => any, InitFn extends ($: BlockBuilder<NeverType>, k2: ExprType<TypeOf<ReturnType<NoInfer<KeyFn>>>>) => any>(keyFn: KeyFn, initFn: InitFn, reduceFn: SubtypeExprOrValue<FunctionType<[TypeOf<ReturnType<NoInfer<InitFn>>>, K], TypeOf<ReturnType<NoInfer<InitFn>>>>>): DictExpr<TypeOf<ReturnType<KeyFn>>, TypeOf<ReturnType<InitFn>>>;
710
+ /**
711
+ * Groups elements by a key and collects each group into an array.
712
+ *
713
+ * @param keyFn - Function that computes the grouping key
714
+ * @param valueFn - Optional projection function for values (defaults to identity)
715
+ * @returns A DictExpr mapping each group key to an array of elements
716
+ *
717
+ * @see {@link groupToSets} to collect into sets, {@link groupReduce} for custom aggregation
718
+ *
719
+ * @example
720
+ * ```ts
721
+ * const groupByParity = East.function([SetType(IntegerType)], DictType(IntegerType, ArrayType(IntegerType)), ($, numbers) => {
722
+ * $.return(numbers.groupToArrays(($, x) => x.remainder(2n)));
723
+ * });
724
+ * const compiled = East.compile(groupByParity.toIR(), []);
725
+ * compiled(new Set([1n, 2n, 3n, 4n])); // { 0n: [2n, 4n], 1n: [1n, 3n] }
726
+ * ```
727
+ */
728
+ groupToArrays<K2, T2>(keyFn: Expr<FunctionType<[K], K2>>, valueFn: Expr<FunctionType<[K], T2>>): DictExpr<K2, ArrayType<T2>>;
729
+ groupToArrays<K2, ValueFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: Expr<FunctionType<[K], K2>>, valueFn: ValueFn): DictExpr<K2, ArrayType<TypeOf<ReturnType<ValueFn>>>>;
730
+ groupToArrays<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), T2>(keyFn: KeyFn, valueFn: Expr<FunctionType<[K], T2>>): DictExpr<TypeOf<ReturnType<KeyFn>>, ArrayType<T2>>;
731
+ groupToArrays<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), ValueFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn, valueFn: ValueFn): DictExpr<TypeOf<ReturnType<KeyFn>>, ArrayType<TypeOf<ReturnType<ValueFn>>>>;
732
+ groupToArrays<K2>(keyFn: Expr<FunctionType<[K], K2>>): DictExpr<K2, ArrayType<K>>;
733
+ groupToArrays<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn): DictExpr<TypeOf<ReturnType<KeyFn>>, ArrayType<K>>;
734
+ /**
735
+ * Groups elements by a key and collects each group into a set.
736
+ *
737
+ * @param keyFn - Function that computes the grouping key
738
+ * @param valueFn - Optional projection function for values (defaults to identity)
739
+ * @returns A DictExpr mapping each group key to a set of unique elements
740
+ *
741
+ * @see {@link groupToArrays} to collect into arrays, {@link groupReduce} for custom aggregation
742
+ *
743
+ * @example
744
+ * ```ts
745
+ * const groupByParity = East.function([SetType(IntegerType)], DictType(IntegerType, SetType(IntegerType)), ($, numbers) => {
746
+ * $.return(numbers.groupToSets(($, x) => x.remainder(2n)));
747
+ * });
748
+ * const compiled = East.compile(groupByParity.toIR(), []);
749
+ * compiled(new Set([1n, 2n, 1n, 2n])); // { 0n: Set([2n]), 1n: Set([1n]) }
750
+ * ```
751
+ */
752
+ groupToSets<K2, T2>(keyFn: Expr<FunctionType<[K], K2>>, valueFn: Expr<FunctionType<[K], T2>>): DictExpr<K2, SetType<T2>>;
753
+ groupToSets<K2, ValueFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: Expr<FunctionType<[K], K2>>, valueFn: ValueFn): DictExpr<K2, SetType<TypeOf<ReturnType<ValueFn>>>>;
754
+ groupToSets<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), T2>(keyFn: KeyFn, valueFn: Expr<FunctionType<[K], T2>>): DictExpr<TypeOf<ReturnType<KeyFn>>, SetType<T2>>;
755
+ groupToSets<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), ValueFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn, valueFn: ValueFn): DictExpr<TypeOf<ReturnType<KeyFn>>, SetType<TypeOf<ReturnType<ValueFn>>>>;
756
+ groupToSets<K2>(keyFn: Expr<FunctionType<[K], K2>>): DictExpr<K2, SetType<K>>;
757
+ groupToSets<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn): DictExpr<TypeOf<ReturnType<KeyFn>>, SetType<K>>;
758
+ /**
759
+ * Groups elements into nested dictionaries (dictionary-of-dictionaries).
760
+ *
761
+ * @param keyFn - Function that computes the outer grouping key
762
+ * @param keyFn2 - Function that computes the inner dictionary key
763
+ * @param valueFn - Optional projection function for inner dictionary values (defaults to identity)
764
+ * @param combineFn - Optional function to resolve conflicts when the same inner key appears multiple times
765
+ * @returns A DictExpr mapping group keys to dictionaries
766
+ *
767
+ * @throws East runtime error if duplicate inner keys are produced and no conflict handler is provided
768
+ *
769
+ * @see {@link groupToArrays} to collect into arrays, {@link groupToSets} to collect into sets
770
+ *
771
+ * @example
772
+ * ```ts
773
+ * // Group numbers by parity, then by sign
774
+ * const nestedGroup = East.function([SetType(IntegerType)], DictType(StringType, DictType(StringType, IntegerType)), ($, numbers) => {
775
+ * $.return(numbers.groupToDicts(
776
+ * ($, n) => n.remainder(2n).equal(0n).ifElse(() => "even", () => "odd"),
777
+ * ($, n) => n.greaterThan(0n).ifElse(() => "positive", () => "negative"),
778
+ * ($, n) => n,
779
+ * ($, existing, newVal, key) => existing // Keep first on conflict
780
+ * ));
781
+ * });
782
+ * const compiled = East.compile(nestedGroup.toIR(), []);
783
+ * compiled(new Set([1n, -2n, 3n, -4n])); // { "even": { "negative": -2n, "positive": ... }, "odd": { ... } }
784
+ * ```
785
+ */
786
+ groupToDicts<K1, K2, T2>(keyFn: Expr<FunctionType<[K], K1>>, keyFn2: Expr<FunctionType<[K], K2>>, valueFn: Expr<FunctionType<[K], T2>>, combineFn?: SubtypeExprOrValue<FunctionType<[T2, T2, K1], T2>>): DictExpr<K1, DictType<K2, T2>>;
787
+ groupToDicts<K1, K2, ValueFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: Expr<FunctionType<[K], K1>>, keyFn2: Expr<FunctionType<[K], 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>>>>;
788
+ groupToDicts<K1, KeyFn2 extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), T2>(keyFn: Expr<FunctionType<[K], K1>>, keyFn2: KeyFn2, valueFn: Expr<FunctionType<[K], T2>>, combineFn?: SubtypeExprOrValue<FunctionType<[T2, T2, K1], T2>>): DictExpr<K1, DictType<TypeOf<ReturnType<KeyFn2>>, T2>>;
789
+ groupToDicts<K1, KeyFn2 extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), ValueFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: Expr<FunctionType<[K], 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>>>>;
790
+ groupToDicts<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), K2, T2>(keyFn: KeyFn, keyFn2: Expr<FunctionType<[K], K2>>, valueFn: Expr<FunctionType<[K], T2>>, combineFn?: SubtypeExprOrValue<FunctionType<[T2, T2, TypeOf<ReturnType<NoInfer<KeyFn>>>], T2>>): DictExpr<TypeOf<ReturnType<KeyFn>>, DictType<K2, T2>>;
791
+ groupToDicts<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), K2, ValueFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn, keyFn2: Expr<FunctionType<[K], 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>>>>;
792
+ groupToDicts<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), KeyFn2 extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), T2>(keyFn: KeyFn, keyFn2: KeyFn2, valueFn: Expr<FunctionType<[K], T2>>, combineFn?: SubtypeExprOrValue<FunctionType<[T2, T2, TypeOf<ReturnType<NoInfer<KeyFn>>>], T2>>): DictExpr<TypeOf<ReturnType<KeyFn>>, DictType<TypeOf<ReturnType<KeyFn2>>, T2>>;
793
+ groupToDicts<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), KeyFn2 extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), ValueFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => 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>>>>;
794
+ groupToDicts<K1, K2>(keyFn: Expr<FunctionType<[K], K1>>, keyFn2: Expr<FunctionType<[K], K2>>): DictExpr<K1, DictType<K2, K>>;
795
+ groupToDicts<K1, KeyFn2 extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: Expr<FunctionType<[K], K1>>, keyFn2: KeyFn2): DictExpr<K1, DictType<TypeOf<ReturnType<KeyFn2>>, K>>;
796
+ groupToDicts<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), K2>(keyFn: KeyFn, keyFn2: Expr<FunctionType<[K], K2>>): DictExpr<TypeOf<ReturnType<KeyFn>>, DictType<K2, K>>;
797
+ groupToDicts<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), KeyFn2 extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn, keyFn2: KeyFn2): DictExpr<TypeOf<ReturnType<KeyFn>>, DictType<TypeOf<ReturnType<KeyFn2>>, K>>;
798
+ /**
799
+ * Counts the number of elements in each group.
800
+ *
801
+ * @param keyFn - Optional function that computes the grouping key (defaults to identity)
802
+ * @returns A DictExpr mapping each group key to the count of elements
803
+ *
804
+ * @see {@link groupToArrays} to collect elements instead of counting them
805
+ *
806
+ * @example
807
+ * ```ts
808
+ * // Group by parity and count
809
+ * const countByParity = East.function([SetType(IntegerType)], DictType(IntegerType, IntegerType), ($, numbers) => {
810
+ * $.return(numbers.groupSize(($, x) => x.remainder(2n)));
811
+ * });
812
+ * const compiled = East.compile(countByParity.toIR(), []);
813
+ * compiled(new Set([1n, 2n, 3n, 4n, 5n, 6n])); // { 0n: 3n, 1n: 3n }
814
+ * ```
815
+ */
816
+ groupSize<K2>(keyFn: Expr<FunctionType<[K], K2>>): DictExpr<K2, IntegerType>;
817
+ groupSize<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn): DictExpr<TypeOf<ReturnType<KeyFn>>, IntegerType>;
818
+ groupSize(): DictExpr<K, IntegerType>;
819
+ /**
820
+ * Checks if every element in each group satisfies a predicate.
821
+ *
822
+ * @param keyFn - Function that computes the grouping key
823
+ * @param predFn - Predicate function to test each element
824
+ * @returns A DictExpr mapping each group key to true if all elements satisfy the predicate
825
+ *
826
+ * @see {@link groupSome} to check if at least one element satisfies the predicate
827
+ *
828
+ * @example
829
+ * ```ts
830
+ * // Check if all numbers in each parity group are positive
831
+ * const allPositive = East.function([SetType(IntegerType)], DictType(IntegerType, BooleanType), ($, numbers) => {
832
+ * $.return(numbers.groupEvery(
833
+ * ($, x) => x.remainder(2n),
834
+ * ($, x) => x.greaterThan(0n)
835
+ * ));
836
+ * });
837
+ * const compiled = East.compile(allPositive.toIR(), []);
838
+ * compiled(new Set([1n, 2n, 3n, 4n])); // { 0n: true, 1n: true }
839
+ * ```
840
+ */
841
+ groupEvery<K2>(keyFn: Expr<FunctionType<[K], K2>>, predFn: SubtypeExprOrValue<FunctionType<[K], BooleanType>>): DictExpr<K2, BooleanType>;
842
+ groupEvery<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn, predFn: SubtypeExprOrValue<FunctionType<[K], BooleanType>>): DictExpr<TypeOf<ReturnType<KeyFn>>, BooleanType>;
843
+ /**
844
+ * Checks if at least one element in each group satisfies a predicate.
845
+ *
846
+ * @param keyFn - Function that computes the grouping key
847
+ * @param predFn - Predicate function to test each element
848
+ * @returns A DictExpr mapping each group key to true if any element satisfies the predicate
849
+ *
850
+ * @see {@link groupEvery} to check if all elements satisfy the predicate
851
+ *
852
+ * @example
853
+ * ```ts
854
+ * // Check if any number in each parity group is greater than 3
855
+ * const anyLarge = East.function([SetType(IntegerType)], DictType(IntegerType, BooleanType), ($, numbers) => {
856
+ * $.return(numbers.groupSome(
857
+ * ($, x) => x.remainder(2n),
858
+ * ($, x) => x.greaterThan(3n)
859
+ * ));
860
+ * });
861
+ * const compiled = East.compile(anyLarge.toIR(), []);
862
+ * compiled(new Set([1n, 2n, 3n, 4n])); // { 0n: true, 1n: false }
863
+ * ```
864
+ */
865
+ groupSome<K2>(keyFn: Expr<FunctionType<[K], K2>>, predFn: SubtypeExprOrValue<FunctionType<[K], BooleanType>>): DictExpr<K2, BooleanType>;
866
+ groupSome<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn, predFn: SubtypeExprOrValue<FunctionType<[K], BooleanType>>): DictExpr<TypeOf<ReturnType<KeyFn>>, BooleanType>;
867
+ /**
868
+ * Computes the sum of elements in each group.
869
+ *
870
+ * @param keyFn - Function that computes the grouping key
871
+ * @param valueFn - Optional projection function for values to sum (defaults to identity)
872
+ * @returns A DictExpr mapping each group key to the sum
873
+ *
874
+ * @see {@link groupMean} to calculate the mean instead of sum
875
+ *
876
+ * @example
877
+ * ```ts
878
+ * // Sum numbers in each parity group
879
+ * const sumByParity = East.function([SetType(IntegerType)], DictType(IntegerType, IntegerType), ($, numbers) => {
880
+ * $.return(numbers.groupSum(($, x) => x.remainder(2n)));
881
+ * });
882
+ * const compiled = East.compile(sumByParity.toIR(), []);
883
+ * compiled(new Set([1n, 2n, 3n, 4n])); // { 0n: 6n, 1n: 4n }
884
+ * ```
885
+ */
886
+ groupSum<K2>(keyFn: Expr<FunctionType<[K], K2>>, valueFn: Expr<FunctionType<[K], IntegerType>>): DictExpr<K2, IntegerType>;
887
+ groupSum<K2>(keyFn: Expr<FunctionType<[K], K2>>, valueFn: Expr<FunctionType<[K], FloatType>>): DictExpr<K2, FloatType>;
888
+ groupSum<K2, ValueFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: Expr<FunctionType<[K], K2>>, valueFn: ValueFn): DictExpr<K2, TypeOf<ReturnType<ValueFn>>>;
889
+ groupSum<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn, valueFn: Expr<FunctionType<[K], IntegerType>>): DictExpr<TypeOf<ReturnType<KeyFn>>, IntegerType>;
890
+ groupSum<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn, valueFn: Expr<FunctionType<[K], FloatType>>): DictExpr<TypeOf<ReturnType<KeyFn>>, FloatType>;
891
+ groupSum<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), ValueFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn, valueFn: ValueFn): DictExpr<TypeOf<ReturnType<KeyFn>>, TypeOf<ReturnType<ValueFn>>>;
892
+ groupSum<K2>(keyFn: Expr<FunctionType<[K], K2>>): K extends IntegerType | FloatType ? DictExpr<K2, K> : never;
893
+ groupSum<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn): K extends IntegerType | FloatType ? DictExpr<TypeOf<ReturnType<KeyFn>>, K> : never;
894
+ /**
895
+ * Computes the arithmetic mean (average) of elements in each group.
896
+ *
897
+ * @param keyFn - Function that computes the grouping key
898
+ * @param valueFn - Optional projection function for values (defaults to identity)
899
+ * @returns A DictExpr mapping each group key to the mean value (always float)
900
+ *
901
+ * @see {@link groupSum} to calculate the sum instead of mean
902
+ *
903
+ * @example
904
+ * ```ts
905
+ * // Calculate mean of numbers in each parity group
906
+ * const meanByParity = East.function([SetType(IntegerType)], DictType(IntegerType, FloatType), ($, numbers) => {
907
+ * $.return(numbers.groupMean(($, x) => x.remainder(2n)));
908
+ * });
909
+ * const compiled = East.compile(meanByParity.toIR(), []);
910
+ * compiled(new Set([1n, 2n, 3n, 4n])); // { 0n: 3.0, 1n: 2.0 }
911
+ * ```
912
+ */
913
+ groupMean<K2>(keyFn: Expr<FunctionType<[K], K2>>, valueFn: Expr<FunctionType<[K], IntegerType | FloatType>>): DictExpr<K2, FloatType>;
914
+ groupMean<K2, ValueFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: Expr<FunctionType<[K], K2>>, valueFn: ValueFn): DictExpr<K2, FloatType>;
915
+ groupMean<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn, valueFn: Expr<FunctionType<[K], IntegerType | FloatType>>): DictExpr<TypeOf<ReturnType<KeyFn>>, FloatType>;
916
+ groupMean<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any), ValueFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn, valueFn: ValueFn): DictExpr<TypeOf<ReturnType<KeyFn>>, FloatType>;
917
+ groupMean<K2>(keyFn: Expr<FunctionType<[K], K2>>): K extends IntegerType | FloatType ? DictExpr<K2, FloatType> : never;
918
+ groupMean<KeyFn extends (($: BlockBuilder<NeverType>, key: ExprType<K>) => any)>(keyFn: KeyFn): K extends IntegerType | FloatType ? DictExpr<TypeOf<ReturnType<KeyFn>>, FloatType> : never;
919
+ /**
920
+ * Returns true if all elements satisfy a condition (or are true for boolean sets).
921
+ *
922
+ * @param fn - Optional predicate function to test each element (required for non-boolean sets)
923
+ * @returns A BooleanExpr that is true if all elements pass the test, false otherwise
924
+ *
925
+ * @remarks
926
+ * - Empty sets always return true
927
+ * - Short-circuits on the first false element for efficiency
928
+ * - For boolean sets, the function parameter can be omitted
929
+ *
930
+ * @see {@link some} to check if at least one element satisfies the condition
931
+ *
932
+ * @example
933
+ * ```ts
934
+ * // Check if all numbers are positive
935
+ * const allPositive = East.function([SetType(IntegerType)], BooleanType, ($, numbers) => {
936
+ * $.return(numbers.every(($, n) => n.greaterThan(0n)));
937
+ * });
938
+ * const compiled = East.compile(allPositive.toIR(), []);
939
+ * compiled(new Set([1n, 2n, 3n])); // true
940
+ * compiled(new Set([1n, -2n, 3n])); // false
941
+ * compiled(new Set([])); // true (empty set)
942
+ * ```
943
+ *
944
+ * @example
945
+ * ```ts
946
+ * // For boolean sets, no function needed
947
+ * const allTrue = East.function([SetType(BooleanType)], BooleanType, ($, flags) => {
948
+ * $.return(flags.every());
949
+ * });
950
+ * const compiled = East.compile(allTrue.toIR(), []);
951
+ * compiled(new Set([true, true])); // true
952
+ * compiled(new Set([true, false])); // false
953
+ * ```
954
+ */
955
+ every(fn?: SubtypeExprOrValue<FunctionType<[K], BooleanType>>): BooleanExpr;
956
+ /**
957
+ * Returns true if at least one element satisfies a condition (or is true for boolean sets).
958
+ *
959
+ * @param fn - Optional predicate function to test each element (required for non-boolean sets)
960
+ * @returns A BooleanExpr that is true if any element passes the test, false otherwise
961
+ *
962
+ * @remarks
963
+ * - Empty sets always return false
964
+ * - Short-circuits on the first true element for efficiency
965
+ * - For boolean sets, the function parameter can be omitted
966
+ *
967
+ * @see {@link every} to check if all elements satisfy the condition
968
+ *
969
+ * @example
970
+ * ```ts
971
+ * // Check if any number is negative
972
+ * const hasNegative = East.function([SetType(IntegerType)], BooleanType, ($, numbers) => {
973
+ * $.return(numbers.some(($, n) => n.lessThan(0n)));
974
+ * });
975
+ * const compiled = East.compile(hasNegative.toIR(), []);
976
+ * compiled(new Set([1n, 2n, 3n])); // false
977
+ * compiled(new Set([1n, -2n, 3n])); // true
978
+ * compiled(new Set([])); // false (empty set)
979
+ * ```
980
+ *
981
+ * @example
982
+ * ```ts
983
+ * // For boolean sets, no function needed
984
+ * const anyTrue = East.function([SetType(BooleanType)], BooleanType, ($, flags) => {
985
+ * $.return(flags.some());
986
+ * });
987
+ * const compiled = East.compile(anyTrue.toIR(), []);
988
+ * compiled(new Set([false, false])); // false
989
+ * compiled(new Set([false, true])); // true
990
+ * ```
991
+ */
992
+ some(fn?: SubtypeExprOrValue<FunctionType<[K], BooleanType>>): BooleanExpr;
993
+ /**
994
+ * Computes the sum of all elements in the set.
995
+ *
996
+ * @param fn - Optional function to map each element to a number (required for non-numeric sets)
997
+ * @returns An IntegerExpr or FloatExpr containing the sum
998
+ *
999
+ * @remarks
1000
+ * - For integer sets, returns an IntegerExpr
1001
+ * - For float sets, returns a FloatExpr
1002
+ * - Empty sets return 0n (integer) or 0.0 (float)
1003
+ * - For non-numeric sets, a mapping function must be provided
1004
+ *
1005
+ * @see {@link mean} to calculate the average value
1006
+ *
1007
+ * @example
1008
+ * ```ts
1009
+ * // Sum numeric elements
1010
+ * const sumNumbers = East.function([SetType(IntegerType)], IntegerType, ($, numbers) => {
1011
+ * $.return(numbers.sum());
1012
+ * });
1013
+ * const compiled = East.compile(sumNumbers.toIR(), []);
1014
+ * compiled(new Set([1n, 2n, 3n, 4n])); // 10n
1015
+ * ```
1016
+ *
1017
+ * @example
1018
+ * ```ts
1019
+ * // Sum with mapping function
1020
+ * const sumLengths = East.function([SetType(StringType)], IntegerType, ($, words) => {
1021
+ * $.return(words.sum(($, word) => word.size()));
1022
+ * });
1023
+ * const compiled = East.compile(sumLengths.toIR(), []);
1024
+ * compiled(new Set(["hi", "bye"])); // 5n (2 + 3)
1025
+ * ```
1026
+ */
1027
+ sum(fn: Expr<FunctionType<[K], IntegerType>>): IntegerExpr;
1028
+ sum(fn: Expr<FunctionType<[K], FloatType>>): FloatExpr;
1029
+ sum<F extends (($: BlockBuilder<NeverType>, k: ExprType<K>) => any)>(fn: F): TypeOf<ReturnType<F>> extends IntegerType ? IntegerExpr : TypeOf<ReturnType<F>> extends FloatType ? FloatExpr : never;
1030
+ sum(): K extends IntegerType | FloatType ? ExprType<K> : never;
1031
+ /**
1032
+ * Computes the arithmetic mean (average) of all elements in the set.
1033
+ *
1034
+ * @param fn - Optional function to map each element to a number (required for non-numeric sets)
1035
+ * @returns A FloatExpr containing the mean value
1036
+ *
1037
+ * @remarks
1038
+ * - Always returns a float, even for integer sets
1039
+ * - Empty sets return NaN
1040
+ * - Integer values are automatically converted to floats
1041
+ * - For non-numeric sets, a mapping function must be provided
1042
+ *
1043
+ * @see {@link sum} to calculate the total sum
1044
+ *
1045
+ * @example
1046
+ * ```ts
1047
+ * // Calculate mean of numbers
1048
+ * const average = East.function([SetType(IntegerType)], FloatType, ($, numbers) => {
1049
+ * $.return(numbers.mean());
1050
+ * });
1051
+ * const compiled = East.compile(average.toIR(), []);
1052
+ * compiled(new Set([1n, 2n, 3n, 4n])); // 2.5
1053
+ * compiled(new Set([])); // NaN
1054
+ * ```
1055
+ *
1056
+ * @example
1057
+ * ```ts
1058
+ * // Mean with mapping function
1059
+ * const avgLength = East.function([SetType(StringType)], FloatType, ($, words) => {
1060
+ * $.return(words.mean(($, word) => word.size()));
1061
+ * });
1062
+ * const compiled = East.compile(avgLength.toIR(), []);
1063
+ * compiled(new Set(["hi", "hello"])); // 3.5 ((2 + 5) / 2)
1064
+ * ```
1065
+ */
1066
+ mean(fn: Expr<FunctionType<[K], IntegerType>>): FloatExpr;
1067
+ mean(fn: Expr<FunctionType<[K], FloatType>>): FloatExpr;
1068
+ mean<F extends (($: BlockBuilder<NeverType>, k: ExprType<K>) => any)>(fn: F): TypeOf<ReturnType<F>> extends IntegerType | FloatType ? FloatExpr : never;
1069
+ mean(): K extends IntegerType | FloatType ? FloatExpr : never;
1070
+ }
1071
+ //# sourceMappingURL=set.d.ts.map