@elaraai/east 0.0.1-beta.0 → 0.0.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -10
- package/dist/src/analyze.d.ts +4 -4
- package/dist/src/analyze.d.ts.map +1 -1
- package/dist/src/analyze.js +142 -44
- package/dist/src/analyze.js.map +1 -1
- package/dist/src/ast.d.ts +18 -7
- package/dist/src/ast.d.ts.map +1 -1
- package/dist/src/ast.js +1 -146
- package/dist/src/ast.js.map +1 -1
- package/dist/src/ast_to_ir.d.ts +1 -0
- package/dist/src/ast_to_ir.d.ts.map +1 -1
- package/dist/src/ast_to_ir.js +71 -10
- package/dist/src/ast_to_ir.js.map +1 -1
- package/dist/src/builtins.d.ts.map +1 -1
- package/dist/src/builtins.js +79 -64
- package/dist/src/builtins.js.map +1 -1
- package/dist/src/comparison.d.ts.map +1 -1
- package/dist/src/comparison.js +21 -0
- package/dist/src/comparison.js.map +1 -1
- package/dist/src/compile.d.ts.map +1 -1
- package/dist/src/compile.js +114 -220
- package/dist/src/compile.js.map +1 -1
- package/dist/src/default.d.ts.map +1 -1
- package/dist/src/default.js +2 -0
- package/dist/src/default.js.map +1 -1
- package/dist/src/eastir.d.ts +12 -10
- package/dist/src/eastir.d.ts.map +1 -1
- package/dist/src/eastir.js +20 -19
- package/dist/src/eastir.js.map +1 -1
- package/dist/src/expr/array.js +51 -51
- package/dist/src/expr/array.js.map +1 -1
- package/dist/src/expr/ast.d.ts.map +1 -1
- package/dist/src/expr/ast.js +6 -0
- package/dist/src/expr/ast.js.map +1 -1
- package/dist/src/expr/asyncfunction.d.ts +49 -0
- package/dist/src/expr/asyncfunction.d.ts.map +1 -0
- package/dist/src/expr/asyncfunction.js +60 -0
- package/dist/src/expr/asyncfunction.js.map +1 -0
- package/dist/src/expr/block.d.ts +60 -6
- package/dist/src/expr/block.d.ts.map +1 -1
- package/dist/src/expr/block.js +251 -14
- package/dist/src/expr/block.js.map +1 -1
- package/dist/src/expr/dict.js +47 -47
- package/dist/src/expr/dict.js.map +1 -1
- package/dist/src/expr/expr.d.ts +9 -0
- package/dist/src/expr/expr.d.ts.map +1 -1
- package/dist/src/expr/expr.js +5 -1
- package/dist/src/expr/expr.js.map +1 -1
- package/dist/src/expr/index.d.ts +73 -2
- package/dist/src/expr/index.d.ts.map +1 -1
- package/dist/src/expr/index.js +72 -8
- package/dist/src/expr/index.js.map +1 -1
- package/dist/src/expr/libs/array.js +1 -1
- package/dist/src/expr/libs/array.js.map +1 -1
- package/dist/src/expr/libs/dict.js +3 -3
- package/dist/src/expr/libs/dict.js.map +1 -1
- package/dist/src/expr/libs/set.js +2 -2
- package/dist/src/expr/libs/set.js.map +1 -1
- package/dist/src/expr/ref.js +1 -1
- package/dist/src/expr/ref.js.map +1 -1
- package/dist/src/expr/set.js +38 -38
- package/dist/src/expr/set.js.map +1 -1
- package/dist/src/expr/struct.d.ts +2 -0
- package/dist/src/expr/struct.d.ts.map +1 -1
- package/dist/src/expr/types.d.ts +8 -5
- package/dist/src/expr/types.d.ts.map +1 -1
- package/dist/src/fuzz.d.ts.map +1 -1
- package/dist/src/fuzz.js +5 -0
- package/dist/src/fuzz.js.map +1 -1
- package/dist/src/internal.d.ts +11 -9
- package/dist/src/internal.d.ts.map +1 -1
- package/dist/src/internal.js +15 -5
- package/dist/src/internal.js.map +1 -1
- package/dist/src/ir.d.ts +231 -33
- package/dist/src/ir.d.ts.map +1 -1
- package/dist/src/ir.js +3 -1
- package/dist/src/ir.js.map +1 -1
- package/dist/src/serialization/beast.d.ts.map +1 -1
- package/dist/src/serialization/beast.js +6 -0
- package/dist/src/serialization/beast.js.map +1 -1
- package/dist/src/serialization/beast2-stream.d.ts.map +1 -1
- package/dist/src/serialization/beast2-stream.js +5 -0
- package/dist/src/serialization/beast2-stream.js.map +1 -1
- package/dist/src/serialization/beast2.d.ts.map +1 -1
- package/dist/src/serialization/beast2.js +6 -0
- package/dist/src/serialization/beast2.js.map +1 -1
- package/dist/src/serialization/east.d.ts.map +1 -1
- package/dist/src/serialization/east.js +9 -1
- package/dist/src/serialization/east.js.map +1 -1
- package/dist/src/serialization/json.d.ts.map +1 -1
- package/dist/src/serialization/json.js +8 -2
- package/dist/src/serialization/json.js.map +1 -1
- package/dist/src/type_of_type.d.ts +19 -32
- package/dist/src/type_of_type.d.ts.map +1 -1
- package/dist/src/type_of_type.js +126 -14
- package/dist/src/type_of_type.js.map +1 -1
- package/dist/src/types.d.ts +59 -44
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +191 -91
- package/dist/src/types.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/default.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAIxD;;;EAGE;AACF,wBAAgB,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,GAAG,CAAA;AACtD,wBAAgB,YAAY,CAAC,CAAC,SAAS,QAAQ,EAAE,IAAI,EAAE,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/default.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAIxD;;;EAGE;AACF,wBAAgB,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,GAAG,CAAA;AACtD,wBAAgB,YAAY,CAAC,CAAC,SAAS,QAAQ,EAAE,IAAI,EAAE,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;AAyChF;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,GAAG,CAAA;AACtD,wBAAgB,YAAY,CAAC,CAAC,SAAS,QAAQ,EAAE,IAAI,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA"}
|
package/dist/src/default.js
CHANGED
|
@@ -40,6 +40,7 @@ export function defaultValue(type) {
|
|
|
40
40
|
},
|
|
41
41
|
Recursive: _ => { throw new Error("Cannot create a default value of type .Recursive"); },
|
|
42
42
|
Function: _ => { throw new Error(`Cannot create a default value of type .Function`); },
|
|
43
|
+
AsyncFunction: _ => { throw new Error(`Cannot create a default value of type .AsyncFunction`); },
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
export function minimalValue(type) {
|
|
@@ -77,6 +78,7 @@ export function minimalValue(type) {
|
|
|
77
78
|
},
|
|
78
79
|
Recursive: _ => { throw new Error("Cannot create a default value of type .Recursive"); },
|
|
79
80
|
Function: _ => { throw new Error(`Cannot create a default value of type .Function`); },
|
|
81
|
+
AsyncFunction: _ => { throw new Error(`Cannot create a default value of type .AsyncFunction`); },
|
|
80
82
|
});
|
|
81
83
|
}
|
|
82
84
|
//# sourceMappingURL=default.js.map
|
package/dist/src/default.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.js","sourceRoot":"","sources":["../../src/default.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAsB,MAAM,mBAAmB,CAAC;AAExE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAQ1C,MAAM,UAAU,YAAY,CAAC,IAA8B;IACzD,8CAA8C;IAC9C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,KAAK,CAA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,CAAC;YACjC,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;gBAC7B,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;YAC/D,CAAC;YACD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC;YAClC,OAAO,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3C,CAAC;QACD,SAAS,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC,CAAC,CAAC;QACxF,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA,CAAC,CAAC;QACrF,aAAa,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA,CAAC,CAAC;KAChG,CAAC,CAAC;AACL,CAAC"}
|
package/dist/src/eastir.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
4
|
*/
|
|
5
5
|
import { type ValueTypeOf } from "./types.js";
|
|
6
|
-
import type { FunctionIR } from "./ir.js";
|
|
6
|
+
import type { AsyncFunctionIR, FunctionIR } from "./ir.js";
|
|
7
7
|
import type { PlatformFunction } from "./platform.js";
|
|
8
8
|
/** A helper class wrapping East's "intermediate representation" (IR) for a free function.
|
|
9
9
|
* The IR can be serialized and saved, or compiled so that the function can be executed.
|
|
@@ -13,20 +13,22 @@ export declare class EastIR<Inputs extends any[], Output extends any> {
|
|
|
13
13
|
constructor(ir: FunctionIR);
|
|
14
14
|
/** Compile the function for execution in JavaScript using a closure-compiler technique.
|
|
15
15
|
* Platform functions must be provided for the function to evaluate.
|
|
16
|
-
*
|
|
17
|
-
* This method is for synchronous platforms only. Use compileAsync() if any platform function is async.
|
|
18
|
-
* @throws {Error} if any platform function is async
|
|
19
16
|
*/
|
|
20
17
|
compile(platform: PlatformFunction[]): (...inputs: {
|
|
21
18
|
[K in keyof Inputs]: ValueTypeOf<Inputs[K]>;
|
|
22
19
|
}) => ValueTypeOf<Output>;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
}
|
|
21
|
+
/** A helper class wrapping East's "intermediate representation" (IR) for a free async function.
|
|
22
|
+
* The IR can be serialized and saved, or compiled so that the function can be executed.
|
|
23
|
+
*/
|
|
24
|
+
export declare class AsyncEastIR<Inputs extends any[], Output extends any> {
|
|
25
|
+
ir: AsyncFunctionIR;
|
|
26
|
+
constructor(ir: AsyncFunctionIR);
|
|
27
|
+
/** Compile the async function for execution in JavaScript using a closure-compiler technique.
|
|
28
|
+
* Platform functions must be provided for the function to evaluate, which may return `Promise`s.
|
|
29
|
+
* The compiled function itself returns a `Promise`.
|
|
28
30
|
*/
|
|
29
|
-
|
|
31
|
+
compile(platform: PlatformFunction[]): (...inputs: {
|
|
30
32
|
[K in keyof Inputs]: ValueTypeOf<Inputs[K]>;
|
|
31
33
|
}) => Promise<ValueTypeOf<Output>>;
|
|
32
34
|
}
|
package/dist/src/eastir.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eastir.d.ts","sourceRoot":"","sources":["../../src/eastir.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"eastir.d.ts","sourceRoot":"","sources":["../../src/eastir.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD;;GAEG;AACH,qBAAa,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,EAAE,MAAM,SAAS,GAAG;IACvC,EAAE,EAAE,UAAU;gBAAd,EAAE,EAAE,UAAU;IASjC;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE;SAAG,CAAC,IAAI,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;KAAE,KAAK,WAAW,CAAC,MAAM,CAAC;CA0B3H;AAED;;GAEG;AACH,qBAAa,WAAW,CAAC,MAAM,SAAS,GAAG,EAAE,EAAE,MAAM,SAAS,GAAG;IAC5C,EAAE,EAAE,eAAe;gBAAnB,EAAE,EAAE,eAAe;IAStC;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE;SAAG,CAAC,IAAI,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;KAAE,KAAK,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;CA4BpI"}
|
package/dist/src/eastir.js
CHANGED
|
@@ -13,7 +13,7 @@ export class EastIR {
|
|
|
13
13
|
constructor(ir) {
|
|
14
14
|
this.ir = ir;
|
|
15
15
|
if (ir.type !== "Function") {
|
|
16
|
-
throw new Error(`Expected function
|
|
16
|
+
throw new Error(`Expected function expression, got a ${ir.type}`);
|
|
17
17
|
}
|
|
18
18
|
if (ir.value.captures.length !== 0) {
|
|
19
19
|
throw new Error(`Expected free function, without captured variables`);
|
|
@@ -21,16 +21,8 @@ export class EastIR {
|
|
|
21
21
|
}
|
|
22
22
|
/** Compile the function for execution in JavaScript using a closure-compiler technique.
|
|
23
23
|
* Platform functions must be provided for the function to evaluate.
|
|
24
|
-
*
|
|
25
|
-
* This method is for synchronous platforms only. Use compileAsync() if any platform function is async.
|
|
26
|
-
* @throws {Error} if any platform function is async
|
|
27
24
|
*/
|
|
28
25
|
compile(platform) {
|
|
29
|
-
// Check that no platform functions are async
|
|
30
|
-
if (platform.some(fn => fn.type === 'async')) {
|
|
31
|
-
throw new Error(`Cannot use compile() with async platform functions: ${platform.map(f => f.name).join(', ')}. ` +
|
|
32
|
-
`Use compileAsync() instead.`);
|
|
33
|
-
}
|
|
34
26
|
// Analyse the IR
|
|
35
27
|
const analyzed_ir = analyzeIR(this.ir, platform, {});
|
|
36
28
|
// compile the function (with no variables in environment)
|
|
@@ -54,17 +46,26 @@ export class EastIR {
|
|
|
54
46
|
}
|
|
55
47
|
};
|
|
56
48
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
throw new Error(`
|
|
49
|
+
}
|
|
50
|
+
/** A helper class wrapping East's "intermediate representation" (IR) for a free async function.
|
|
51
|
+
* The IR can be serialized and saved, or compiled so that the function can be executed.
|
|
52
|
+
*/
|
|
53
|
+
export class AsyncEastIR {
|
|
54
|
+
ir;
|
|
55
|
+
constructor(ir) {
|
|
56
|
+
this.ir = ir;
|
|
57
|
+
if (ir.type !== "AsyncFunction") {
|
|
58
|
+
throw new Error(`Expected async function expression, got a ${ir.type}`);
|
|
59
|
+
}
|
|
60
|
+
if (ir.value.captures.length !== 0) {
|
|
61
|
+
throw new Error(`Expected free async function, without captured variables`);
|
|
67
62
|
}
|
|
63
|
+
}
|
|
64
|
+
/** Compile the async function for execution in JavaScript using a closure-compiler technique.
|
|
65
|
+
* Platform functions must be provided for the function to evaluate, which may return `Promise`s.
|
|
66
|
+
* The compiled function itself returns a `Promise`.
|
|
67
|
+
*/
|
|
68
|
+
compile(platform) {
|
|
68
69
|
// Analyse the IR
|
|
69
70
|
const analyzed_ir = analyzeIR(this.ir, platform, {});
|
|
70
71
|
// compile the function (with no variables in environment)
|
package/dist/src/eastir.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eastir.js","sourceRoot":"","sources":["../../src/eastir.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAoB,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,MAAM;IACE;IAAnB,YAAmB,EAAc;QAAd,OAAE,GAAF,EAAE,CAAY;QAC/B,IAAI,EAAE,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"eastir.js","sourceRoot":"","sources":["../../src/eastir.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAoB,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,MAAM;IACE;IAAnB,YAAmB,EAAc;QAAd,OAAE,GAAF,EAAE,CAAY;QAC/B,IAAI,EAAE,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,uCAAuC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAA;QACnE,CAAC;QACD,IAAI,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;QACvE,CAAC;IACH,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,QAA4B;QAClC,iBAAiB;QACjB,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;QAErD,0DAA0D;QAC1D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AE,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;QAErD,0DAA0D;QAC1D,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC7E,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAC9D,CAAC;QAEF,MAAM,aAAa,GAAG,gBAAgB,CAAC,WAAW,EAAE,EAAE,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAC;QAEvF,iDAAiD;QACjD,MAAM,qBAAqB,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;QAEhD,uBAAuB;QACvB,OAAO,KAAK,EAAE,GAAG,MAAa,EAAE,EAAE;YAChC,IAAI,CAAC;gBACH,OAAO,MAAM,qBAAqB,CAAC,GAAG,MAAM,CAAC,CAAA;YAC/C,CAAC;YAAC,OAAO,CAAU,EAAE,CAAC;gBACpB,IAAI,CAAC,YAAY,eAAe,EAAE,CAAC;oBACjC,OAAO,CAAC,CAAC,KAAK,CAAC;gBACjB,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,CAAC;gBACV,CAAC;YACH,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;CACF"}
|
package/dist/src/expr/array.js
CHANGED
|
@@ -119,7 +119,7 @@ export class ArrayExpr extends Expr {
|
|
|
119
119
|
get(key, defaultFn) {
|
|
120
120
|
const keyAst = valueOrExprToAstTyped(key, IntegerType);
|
|
121
121
|
if (defaultFn !== undefined) {
|
|
122
|
-
const defaultFnAst = valueOrExprToAstTyped(defaultFn, FunctionType([IntegerType], this.value_type
|
|
122
|
+
const defaultFnAst = valueOrExprToAstTyped(defaultFn, FunctionType([IntegerType], this.value_type));
|
|
123
123
|
return this[FactorySymbol]({
|
|
124
124
|
ast_type: "Builtin",
|
|
125
125
|
type: this.value_type,
|
|
@@ -208,7 +208,7 @@ export class ArrayExpr extends Expr {
|
|
|
208
208
|
const location = get_location(2);
|
|
209
209
|
const keyAst = valueOrExprToAstTyped(key, IntegerType);
|
|
210
210
|
const value2Type = value[TypeSymbol];
|
|
211
|
-
const updateFnExpr = Expr.from(updateFn, FunctionType([value2Type, this.value_type, IntegerType], this.value_type
|
|
211
|
+
const updateFnExpr = Expr.from(updateFn, FunctionType([value2Type, this.value_type, IntegerType], this.value_type));
|
|
212
212
|
return this[FactorySymbol]({
|
|
213
213
|
ast_type: "Builtin",
|
|
214
214
|
type: NullType,
|
|
@@ -417,7 +417,7 @@ export class ArrayExpr extends Expr {
|
|
|
417
417
|
throw new Error(`Expected array type for mergeAll, got ${array_type ? printType(array_type) : "unknown"}`);
|
|
418
418
|
}
|
|
419
419
|
const value2Type = array_type.value;
|
|
420
|
-
const mergeFnExpr = Expr.from(mergeFn, FunctionType([this.value_type, value2Type, IntegerType], this.value_type
|
|
420
|
+
const mergeFnExpr = Expr.from(mergeFn, FunctionType([this.value_type, value2Type, IntegerType], this.value_type));
|
|
421
421
|
return this[FactorySymbol]({
|
|
422
422
|
ast_type: "Builtin",
|
|
423
423
|
type: NullType,
|
|
@@ -912,7 +912,7 @@ export class ArrayExpr extends Expr {
|
|
|
912
912
|
default_function_ast = Expr.ast(default_function);
|
|
913
913
|
}
|
|
914
914
|
else {
|
|
915
|
-
const default_function_expr = Expr.from(onMissing, FunctionType([IntegerType], this.value_type
|
|
915
|
+
const default_function_expr = Expr.from(onMissing, FunctionType([IntegerType], this.value_type));
|
|
916
916
|
default_function_ast = Expr.ast(default_function_expr);
|
|
917
917
|
}
|
|
918
918
|
return this[FactorySymbol]({
|
|
@@ -1094,7 +1094,7 @@ export class ArrayExpr extends Expr {
|
|
|
1094
1094
|
}
|
|
1095
1095
|
}
|
|
1096
1096
|
filterMap(fn) {
|
|
1097
|
-
const fnAst = valueOrExprToAstTyped(fn, FunctionType([this.value_type, IntegerType], undefined
|
|
1097
|
+
const fnAst = valueOrExprToAstTyped(fn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1098
1098
|
const returnType = fnAst.type.output;
|
|
1099
1099
|
if (returnType.type !== "Variant") {
|
|
1100
1100
|
throw new Error(`Expected Function to return an Option type, got ${printType(returnType)}`);
|
|
@@ -1113,7 +1113,7 @@ export class ArrayExpr extends Expr {
|
|
|
1113
1113
|
});
|
|
1114
1114
|
}
|
|
1115
1115
|
firstMap(fn) {
|
|
1116
|
-
const fnAst = valueOrExprToAstTyped(fn, FunctionType([this.value_type, IntegerType], undefined
|
|
1116
|
+
const fnAst = valueOrExprToAstTyped(fn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1117
1117
|
const returnType = fnAst.type.output;
|
|
1118
1118
|
if (returnType.type !== "Variant") {
|
|
1119
1119
|
throw new Error(`Expected Function to return an Option type, got ${printType(returnType)}`);
|
|
@@ -1208,7 +1208,7 @@ export class ArrayExpr extends Expr {
|
|
|
1208
1208
|
reduce(combineFn, init) {
|
|
1209
1209
|
const initAst = valueOrExprToAst(init);
|
|
1210
1210
|
const returnType = initAst.type;
|
|
1211
|
-
const combineAst = valueOrExprToAstTyped(combineFn, FunctionType([returnType, this.value_type, IntegerType], returnType
|
|
1211
|
+
const combineAst = valueOrExprToAstTyped(combineFn, FunctionType([returnType, this.value_type, IntegerType], returnType));
|
|
1212
1212
|
return this[FactorySymbol]({
|
|
1213
1213
|
ast_type: "Builtin",
|
|
1214
1214
|
type: returnType,
|
|
@@ -1219,9 +1219,9 @@ export class ArrayExpr extends Expr {
|
|
|
1219
1219
|
});
|
|
1220
1220
|
}
|
|
1221
1221
|
mapReduce(mapFn, combineFn) {
|
|
1222
|
-
const mapAst = valueOrExprToAstTyped(mapFn, FunctionType([this.value_type, IntegerType], undefined
|
|
1222
|
+
const mapAst = valueOrExprToAstTyped(mapFn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1223
1223
|
const mapType = mapAst.type.output;
|
|
1224
|
-
const combineAst = valueOrExprToAstTyped(combineFn, FunctionType([mapType, mapType], mapType
|
|
1224
|
+
const combineAst = valueOrExprToAstTyped(combineFn, FunctionType([mapType, mapType], mapType));
|
|
1225
1225
|
return this[FactorySymbol]({
|
|
1226
1226
|
ast_type: "Builtin",
|
|
1227
1227
|
type: mapType,
|
|
@@ -1274,7 +1274,7 @@ export class ArrayExpr extends Expr {
|
|
|
1274
1274
|
const result = this.firstMap(($, v, _k) => v.not().ifElse(() => some(null), () => none));
|
|
1275
1275
|
return Expr.match(result, { some: () => false, none: () => true });
|
|
1276
1276
|
}
|
|
1277
|
-
const fnAst = valueOrExprToAstTyped(fn, FunctionType([this.value_type, IntegerType], BooleanType
|
|
1277
|
+
const fnAst = valueOrExprToAstTyped(fn, FunctionType([this.value_type, IntegerType], BooleanType));
|
|
1278
1278
|
// Short-circuit on first false value
|
|
1279
1279
|
const result = this.firstMap(($, v, k) => {
|
|
1280
1280
|
const result = Expr.fromAst(fnAst)(v, k);
|
|
@@ -1324,7 +1324,7 @@ export class ArrayExpr extends Expr {
|
|
|
1324
1324
|
const result = this.firstMap(($, v, _k) => v.ifElse(() => some(null), () => none));
|
|
1325
1325
|
return Expr.match(result, { some: () => true, none: () => false });
|
|
1326
1326
|
}
|
|
1327
|
-
const fnAst = valueOrExprToAstTyped(fn, FunctionType([this.value_type, IntegerType], BooleanType
|
|
1327
|
+
const fnAst = valueOrExprToAstTyped(fn, FunctionType([this.value_type, IntegerType], BooleanType));
|
|
1328
1328
|
// Short-circuit on first true value
|
|
1329
1329
|
const result = this.firstMap(($, v, k) => {
|
|
1330
1330
|
const result = Expr.fromAst(fnAst)(v, k);
|
|
@@ -1341,7 +1341,7 @@ export class ArrayExpr extends Expr {
|
|
|
1341
1341
|
return this.reduce(($, previous, value) => previous.add(value), zero);
|
|
1342
1342
|
}
|
|
1343
1343
|
else {
|
|
1344
|
-
const fnAst = valueOrExprToAstTyped(fn, FunctionType([this.value_type, IntegerType], undefined
|
|
1344
|
+
const fnAst = valueOrExprToAstTyped(fn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1345
1345
|
const returnType = fnAst.type.output;
|
|
1346
1346
|
if (!(isTypeEqual(returnType, IntegerType) || isTypeEqual(returnType, FloatType))) {
|
|
1347
1347
|
throw new Error(`Can only perform sum on array of numbers (Integer or Float), got ${printType(returnType)}`);
|
|
@@ -1363,7 +1363,7 @@ export class ArrayExpr extends Expr {
|
|
|
1363
1363
|
}
|
|
1364
1364
|
}
|
|
1365
1365
|
else {
|
|
1366
|
-
const fnAst = valueOrExprToAstTyped(fn, FunctionType([this.value_type, IntegerType], undefined
|
|
1366
|
+
const fnAst = valueOrExprToAstTyped(fn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1367
1367
|
const returnType = fnAst.type.output;
|
|
1368
1368
|
if (isTypeEqual(returnType, IntegerType)) {
|
|
1369
1369
|
return this.reduce(($, previous, value, key) => previous.add(Expr.fromAst(fnAst)(value, key).toFloat()), 0.0).divide(this.size().toFloat());
|
|
@@ -1522,7 +1522,7 @@ export class ArrayExpr extends Expr {
|
|
|
1522
1522
|
});
|
|
1523
1523
|
}
|
|
1524
1524
|
toSet(keyFn) {
|
|
1525
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined
|
|
1525
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined));
|
|
1526
1526
|
const keyType = keyFnAst.type.output;
|
|
1527
1527
|
return this[FactorySymbol]({
|
|
1528
1528
|
ast_type: "Builtin",
|
|
@@ -1534,9 +1534,9 @@ export class ArrayExpr extends Expr {
|
|
|
1534
1534
|
});
|
|
1535
1535
|
}
|
|
1536
1536
|
toDict(keyFn, valueFn, onConflictFn) {
|
|
1537
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn ?? ((_$, x, i) => i), FunctionType([this.value_type, IntegerType], undefined
|
|
1537
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn ?? ((_$, x, i) => i), FunctionType([this.value_type, IntegerType], undefined));
|
|
1538
1538
|
const keyType = keyFnAst.type.output;
|
|
1539
|
-
const valueFnAst = valueOrExprToAstTyped(valueFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined
|
|
1539
|
+
const valueFnAst = valueOrExprToAstTyped(valueFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined));
|
|
1540
1540
|
const valueType = valueFnAst.type.output;
|
|
1541
1541
|
let onConflictAst;
|
|
1542
1542
|
if (onConflictFn === undefined) {
|
|
@@ -1545,7 +1545,7 @@ export class ArrayExpr extends Expr {
|
|
|
1545
1545
|
onConflictAst = Expr.ast(onConflictFunction);
|
|
1546
1546
|
}
|
|
1547
1547
|
else {
|
|
1548
|
-
onConflictAst = valueOrExprToAstTyped(onConflictFn, FunctionType([valueType, valueType, keyType], valueType
|
|
1548
|
+
onConflictAst = valueOrExprToAstTyped(onConflictFn, FunctionType([valueType, valueType, keyType], valueType));
|
|
1549
1549
|
}
|
|
1550
1550
|
return this[FactorySymbol]({
|
|
1551
1551
|
ast_type: "Builtin",
|
|
@@ -1557,7 +1557,7 @@ export class ArrayExpr extends Expr {
|
|
|
1557
1557
|
});
|
|
1558
1558
|
}
|
|
1559
1559
|
flatMap(fn) {
|
|
1560
|
-
const fnAst = valueOrExprToAstTyped(fn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined
|
|
1560
|
+
const fnAst = valueOrExprToAstTyped(fn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined));
|
|
1561
1561
|
const returnType = fnAst.type.output;
|
|
1562
1562
|
if (returnType.type !== "Array") {
|
|
1563
1563
|
throw new Error(`Expected Function to return an Array type, got ${printType(returnType)}`);
|
|
@@ -1573,7 +1573,7 @@ export class ArrayExpr extends Expr {
|
|
|
1573
1573
|
});
|
|
1574
1574
|
}
|
|
1575
1575
|
flattenToSet(fn) {
|
|
1576
|
-
const fnAst = valueOrExprToAstTyped(fn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined
|
|
1576
|
+
const fnAst = valueOrExprToAstTyped(fn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined));
|
|
1577
1577
|
const returnType = fnAst.type.output;
|
|
1578
1578
|
if (returnType.type !== "Set") {
|
|
1579
1579
|
throw new Error(`Expected Function to return a Set type, got ${printType(returnType)}`);
|
|
@@ -1589,7 +1589,7 @@ export class ArrayExpr extends Expr {
|
|
|
1589
1589
|
});
|
|
1590
1590
|
}
|
|
1591
1591
|
flattenToDict(fn, onConflictFn) {
|
|
1592
|
-
const fnAst = valueOrExprToAstTyped(fn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined
|
|
1592
|
+
const fnAst = valueOrExprToAstTyped(fn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined));
|
|
1593
1593
|
const returnType = fnAst.type.output;
|
|
1594
1594
|
if (returnType.type !== "Dict") {
|
|
1595
1595
|
throw new Error(`Expected Function to return a Dict type, got ${printType(returnType)}`);
|
|
@@ -1603,7 +1603,7 @@ export class ArrayExpr extends Expr {
|
|
|
1603
1603
|
onConflictAst = Expr.ast(onConflictFunction);
|
|
1604
1604
|
}
|
|
1605
1605
|
else {
|
|
1606
|
-
onConflictAst = valueOrExprToAstTyped(onConflictFn, FunctionType([valueType, valueType, keyType], valueType
|
|
1606
|
+
onConflictAst = valueOrExprToAstTyped(onConflictFn, FunctionType([valueType, valueType, keyType], valueType));
|
|
1607
1607
|
}
|
|
1608
1608
|
return this[FactorySymbol]({
|
|
1609
1609
|
ast_type: "Builtin",
|
|
@@ -1616,11 +1616,11 @@ export class ArrayExpr extends Expr {
|
|
|
1616
1616
|
}
|
|
1617
1617
|
groupReduce(keyFn, initFn, reduceFn) {
|
|
1618
1618
|
// Note - initFn has to be before reduceFn, otherwise the TypeScript type inference doesn't work properly
|
|
1619
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined
|
|
1619
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1620
1620
|
const keyType = keyFnAst.type.output;
|
|
1621
|
-
const initFnAst = valueOrExprToAstTyped(initFn, FunctionType([keyType], undefined
|
|
1621
|
+
const initFnAst = valueOrExprToAstTyped(initFn, FunctionType([keyType], undefined));
|
|
1622
1622
|
const initType = initFnAst.type.output;
|
|
1623
|
-
const reduceFnAst = valueOrExprToAstTyped(reduceFn, FunctionType([initType, this.value_type, IntegerType], initType
|
|
1623
|
+
const reduceFnAst = valueOrExprToAstTyped(reduceFn, FunctionType([initType, this.value_type, IntegerType], initType));
|
|
1624
1624
|
return this[FactorySymbol]({
|
|
1625
1625
|
ast_type: "Builtin",
|
|
1626
1626
|
type: DictType(keyType, initType),
|
|
@@ -1631,27 +1631,27 @@ export class ArrayExpr extends Expr {
|
|
|
1631
1631
|
});
|
|
1632
1632
|
}
|
|
1633
1633
|
groupSize(keyFn) {
|
|
1634
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined
|
|
1634
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined));
|
|
1635
1635
|
return this.toDict(((_$, elem, idx) => Expr.fromAst(keyFnAst)(elem, idx)), ((_$) => 1n), ((_$, a, b) => a.add(b)));
|
|
1636
1636
|
}
|
|
1637
1637
|
groupEvery(keyFn, predFn) {
|
|
1638
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined
|
|
1639
|
-
const predFnAst = valueOrExprToAstTyped(predFn, FunctionType([this.value_type, IntegerType], BooleanType
|
|
1638
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1639
|
+
const predFnAst = valueOrExprToAstTyped(predFn, FunctionType([this.value_type, IntegerType], BooleanType));
|
|
1640
1640
|
return this.groupReduce(((_$, elem, idx) => Expr.fromAst(keyFnAst)(elem, idx)), (() => true), ((_$, acc, elem, idx) => {
|
|
1641
1641
|
const pred = Expr.fromAst(predFnAst)(elem, idx);
|
|
1642
1642
|
return acc.and(() => pred);
|
|
1643
1643
|
}));
|
|
1644
1644
|
}
|
|
1645
1645
|
groupSome(keyFn, predFn) {
|
|
1646
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined
|
|
1647
|
-
const predFnAst = valueOrExprToAstTyped(predFn, FunctionType([this.value_type, IntegerType], BooleanType
|
|
1646
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1647
|
+
const predFnAst = valueOrExprToAstTyped(predFn, FunctionType([this.value_type, IntegerType], BooleanType));
|
|
1648
1648
|
return this.groupReduce(((_$, elem, idx) => Expr.fromAst(keyFnAst)(elem, idx)), (() => false), ((_$, acc, elem, idx) => {
|
|
1649
1649
|
const pred = Expr.fromAst(predFnAst)(elem, idx);
|
|
1650
1650
|
return acc.or(() => pred);
|
|
1651
1651
|
}));
|
|
1652
1652
|
}
|
|
1653
1653
|
groupFindAll(keyFn, value, projFn) {
|
|
1654
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined
|
|
1654
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1655
1655
|
const keyFnExpr = Expr.fromAst(keyFnAst);
|
|
1656
1656
|
if (projFn === undefined) {
|
|
1657
1657
|
// Without projection: find where element == value
|
|
@@ -1673,7 +1673,7 @@ export class ArrayExpr extends Expr {
|
|
|
1673
1673
|
}
|
|
1674
1674
|
}
|
|
1675
1675
|
groupFindFirst(keyFn, value, projFn) {
|
|
1676
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined
|
|
1676
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1677
1677
|
const keyFnExpr = Expr.fromAst(keyFnAst);
|
|
1678
1678
|
if (projFn === undefined) {
|
|
1679
1679
|
// Without projection: find where element == value
|
|
@@ -1695,18 +1695,18 @@ export class ArrayExpr extends Expr {
|
|
|
1695
1695
|
}
|
|
1696
1696
|
}
|
|
1697
1697
|
groupFindMinimum(keyFn, byFn) {
|
|
1698
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined
|
|
1699
|
-
const byFnAst = valueOrExprToAstTyped(byFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined
|
|
1698
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1699
|
+
const byFnAst = valueOrExprToAstTyped(byFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined));
|
|
1700
1700
|
return this.toDict(((_$, elem, idx) => Expr.fromAst(keyFnAst)(elem, idx)), ((_$, elem, idx) => ({ by: Expr.fromAst(byFnAst)(elem, idx), index: idx })), ((_$, a, b) => Expr.lessEqual(a.by, b.by).ifElse(() => a, () => b))).map(((_$, v) => v.index));
|
|
1701
1701
|
}
|
|
1702
1702
|
groupFindMaximum(keyFn, byFn) {
|
|
1703
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined
|
|
1704
|
-
const byFnAst = valueOrExprToAstTyped(byFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined
|
|
1703
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1704
|
+
const byFnAst = valueOrExprToAstTyped(byFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined));
|
|
1705
1705
|
return this.toDict(((_$, elem, idx) => Expr.fromAst(keyFnAst)(elem, idx)), ((_$, elem, idx) => ({ by: Expr.fromAst(byFnAst)(elem, idx), index: idx })), ((_$, a, b) => Expr.greaterEqual(a.by, b.by).ifElse(() => a, () => b))).map(((_$, v) => v.index));
|
|
1706
1706
|
}
|
|
1707
1707
|
groupSum(keyFn, valueFn) {
|
|
1708
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined
|
|
1709
|
-
const valueFnAst = valueOrExprToAstTyped(valueFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined
|
|
1708
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1709
|
+
const valueFnAst = valueOrExprToAstTyped(valueFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined));
|
|
1710
1710
|
const valueType = valueFnAst.type.output;
|
|
1711
1711
|
const isInteger = isTypeEqual(valueType, IntegerType);
|
|
1712
1712
|
const isFloat = isTypeEqual(valueType, FloatType);
|
|
@@ -1716,8 +1716,8 @@ export class ArrayExpr extends Expr {
|
|
|
1716
1716
|
return this.toDict(((_$, elem, idx) => Expr.fromAst(keyFnAst)(elem, idx)), ((_$, elem, idx) => Expr.fromAst(valueFnAst)(elem, idx)), ((_$, a, b) => a.add(b)));
|
|
1717
1717
|
}
|
|
1718
1718
|
groupMean(keyFn, valueFn) {
|
|
1719
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined
|
|
1720
|
-
const valueFnAst = valueOrExprToAstTyped(valueFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined
|
|
1719
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1720
|
+
const valueFnAst = valueOrExprToAstTyped(valueFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined));
|
|
1721
1721
|
const valueType = valueFnAst.type.output;
|
|
1722
1722
|
const isInteger = isTypeEqual(valueType, IntegerType);
|
|
1723
1723
|
const isFloat = isTypeEqual(valueType, FloatType);
|
|
@@ -1730,8 +1730,8 @@ export class ArrayExpr extends Expr {
|
|
|
1730
1730
|
}), ((_$, a, b) => ({ sum: a.sum.add(b.sum), count: a.count.add(b.count) }))).map(((_$, v) => v.sum.divide(v.count.toFloat())));
|
|
1731
1731
|
}
|
|
1732
1732
|
groupToArrays(keyFn, valueFn) {
|
|
1733
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined
|
|
1734
|
-
const valueFnAst = valueOrExprToAstTyped(valueFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined
|
|
1733
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1734
|
+
const valueFnAst = valueOrExprToAstTyped(valueFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined));
|
|
1735
1735
|
const keyFnExpr = Expr.fromAst(keyFnAst);
|
|
1736
1736
|
const valueFnExpr = Expr.fromAst(valueFnAst);
|
|
1737
1737
|
const valueType = valueFnAst.type.output;
|
|
@@ -1742,8 +1742,8 @@ export class ArrayExpr extends Expr {
|
|
|
1742
1742
|
}));
|
|
1743
1743
|
}
|
|
1744
1744
|
groupToSets(keyFn, valueFn) {
|
|
1745
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined
|
|
1746
|
-
const valueFnAst = valueOrExprToAstTyped(valueFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined
|
|
1745
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1746
|
+
const valueFnAst = valueOrExprToAstTyped(valueFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined));
|
|
1747
1747
|
const keyFnExpr = Expr.fromAst(keyFnAst);
|
|
1748
1748
|
const valueFnExpr = Expr.fromAst(valueFnAst);
|
|
1749
1749
|
const valueType = valueFnAst.type.output;
|
|
@@ -1754,19 +1754,19 @@ export class ArrayExpr extends Expr {
|
|
|
1754
1754
|
}));
|
|
1755
1755
|
}
|
|
1756
1756
|
groupMinimum(keyFn, byFn) {
|
|
1757
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined
|
|
1758
|
-
const byFnAst = valueOrExprToAstTyped(byFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined
|
|
1757
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1758
|
+
const byFnAst = valueOrExprToAstTyped(byFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined));
|
|
1759
1759
|
return this.toDict(((_$, elem, idx) => Expr.fromAst(keyFnAst)(elem, idx)), ((_$, elem, idx) => ({ by: Expr.fromAst(byFnAst)(elem, idx), elem })), ((_$, a, b) => Expr.lessEqual(a.by, b.by).ifElse(() => a, () => b))).map(((_$, v) => v.elem));
|
|
1760
1760
|
}
|
|
1761
1761
|
groupMaximum(keyFn, byFn) {
|
|
1762
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined
|
|
1763
|
-
const byFnAst = valueOrExprToAstTyped(byFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined
|
|
1762
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1763
|
+
const byFnAst = valueOrExprToAstTyped(byFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined));
|
|
1764
1764
|
return this.toDict(((_$, elem, idx) => Expr.fromAst(keyFnAst)(elem, idx)), ((_$, elem, idx) => ({ by: Expr.fromAst(byFnAst)(elem, idx), elem })), ((_$, a, b) => Expr.greaterEqual(a.by, b.by).ifElse(() => a, () => b))).map(((_$, v) => v.elem));
|
|
1765
1765
|
}
|
|
1766
1766
|
groupToDicts(keyFn, keyFn2, valueFn, combineFn) {
|
|
1767
|
-
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined
|
|
1768
|
-
const keyFn2Ast = valueOrExprToAstTyped(keyFn2, FunctionType([this.value_type, IntegerType], undefined
|
|
1769
|
-
const valueFnAst = valueOrExprToAstTyped(valueFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined
|
|
1767
|
+
const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
|
|
1768
|
+
const keyFn2Ast = valueOrExprToAstTyped(keyFn2, FunctionType([this.value_type, IntegerType], undefined));
|
|
1769
|
+
const valueFnAst = valueOrExprToAstTyped(valueFn ?? ((_$, x) => x), FunctionType([this.value_type, IntegerType], undefined));
|
|
1770
1770
|
const keyFnExpr = Expr.fromAst(keyFnAst);
|
|
1771
1771
|
const keyFn2Expr = Expr.fromAst(keyFn2Ast);
|
|
1772
1772
|
const valueFnExpr = Expr.fromAst(valueFnAst);
|
|
@@ -1774,7 +1774,7 @@ export class ArrayExpr extends Expr {
|
|
|
1774
1774
|
const valueType = valueFnAst.type.output;
|
|
1775
1775
|
if (combineFn !== undefined) {
|
|
1776
1776
|
// With conflict resolution - use tryGet + match to check existence, then insert or combine
|
|
1777
|
-
const combineFnAst = valueOrExprToAstTyped(combineFn, FunctionType([valueType, valueType], valueType
|
|
1777
|
+
const combineFnAst = valueOrExprToAstTyped(combineFn, FunctionType([valueType, valueType], valueType));
|
|
1778
1778
|
const combineFnExpr = Expr.fromAst(combineFnAst);
|
|
1779
1779
|
return this.groupReduce(((_$, elem, idx) => keyFnExpr(elem, idx)), ((_$, _key) => Expr.from(new Map(), DictType(key2Type, valueType))), (($, dict, elem, idx) => {
|
|
1780
1780
|
const innerKey = keyFn2Expr(elem, idx);
|