@mark1russell7/vex 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +16 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +257 -59
- package/build/index.js.map +1 -1
- package/package.json +2 -2
- package/src/builder.ts +18 -0
- package/src/checked.ts +6 -0
- package/src/evaluate.ts +234 -64
- package/src/kernel.ts +34 -1
- package/src/list.ts +4 -6
package/src/list.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CHECKED } from "./checked.ts";
|
|
1
2
|
import type { Result } from "./result.ts";
|
|
2
3
|
|
|
3
4
|
/** One item of a list: the key of the target and the result of the body there. */
|
|
@@ -15,9 +16,6 @@ export interface VexList<T = unknown> {
|
|
|
15
16
|
/** This function makes a list. */
|
|
16
17
|
export const vexList = <T>(items: readonly ListItem<T>[]): VexList<T> => Object.freeze({ kind: "vex.list", items: Object.freeze([...items]) });
|
|
17
18
|
|
|
18
|
-
/** The lists that passed the check of `isVexList` and cannot change. Each list of `vexList` is frozen. */
|
|
19
|
-
const CHECKED = new WeakSet<object>();
|
|
20
|
-
|
|
21
19
|
/** This function tells if a value is an error value: a text `code`, `kind` and `message`, and a `path` (LIST.SHAPE). */
|
|
22
20
|
const isErrorValue = (u: unknown): boolean => {
|
|
23
21
|
if (typeof u !== "object" || u === null) return false;
|
|
@@ -54,15 +52,15 @@ export const isVexList = (u: unknown): u is VexList => {
|
|
|
54
52
|
/**
|
|
55
53
|
* The name of a core list op. `sortBy`, `take`, `drop`, `append`, `flat` and `without` give a list (LIST.BUILD), and
|
|
56
54
|
* the other ops give a value. `get` gives the value at a key (LIST.GET), and `indexOf` gives the position of a value
|
|
57
|
-
* (LIST.INDEXOF).
|
|
55
|
+
* (LIST.INDEXOF). `distinct` and `group` give a list, and `join` gives a text (LIST.DISTINCT, LIST.GROUP, LIST.JOIN).
|
|
58
56
|
*/
|
|
59
|
-
export type ListOp = "count" | "sum" | "min" | "max" | "mean" | "any" | "all" | "none" | "values" | "keys" | "reduce" | "first" | "errors" | "sortBy" | "take" | "nth" | "drop" | "append" | "flat" | "without" | "get" | "indexOf";
|
|
57
|
+
export type ListOp = "count" | "sum" | "min" | "max" | "mean" | "any" | "all" | "none" | "values" | "keys" | "reduce" | "first" | "errors" | "sortBy" | "take" | "nth" | "drop" | "append" | "flat" | "without" | "get" | "indexOf" | "distinct" | "group" | "join";
|
|
60
58
|
|
|
61
59
|
/**
|
|
62
60
|
* The names of the core list ops. They apply when the first argument is a list. They apply to an array too, when no
|
|
63
61
|
* domain and no function of the host has the op for it (LIST.ARRAY).
|
|
64
62
|
*/
|
|
65
|
-
export const LIST_OPS: ReadonlySet<string> = new Set<ListOp>(["count", "sum", "min", "max", "mean", "any", "all", "none", "values", "keys", "reduce", "first", "errors", "sortBy", "take", "nth", "drop", "append", "flat", "without", "get", "indexOf"]);
|
|
63
|
+
export const LIST_OPS: ReadonlySet<string> = new Set<ListOp>(["count", "sum", "min", "max", "mean", "any", "all", "none", "values", "keys", "reduce", "first", "errors", "sortBy", "take", "nth", "drop", "append", "flat", "without", "get", "indexOf", "distinct", "group", "join"]);
|
|
66
64
|
|
|
67
65
|
/** This function tells if a name is the name of a core list op. */
|
|
68
66
|
export const isListOp = (op: string): op is ListOp => LIST_OPS.has(op);
|