Skip to content

The domains

A domain tells Vex which values belong to it and which ops they have. The tables below come from the domain objects of @mark1russell7/vex-domains, at the time of the build. Thus the tables and the code are the same.

  • parameters: the kinds of the arguments after the receiver. The interpreter checks them, and an argument of the wrong kind gives #VALUE!. “not checked” means that the op does not declare its parameters.
  • laws: the claims of the op. The law checker of @mark1russell7/vex-testkit tests each claim with random values. Refer to the law arena.
  • lifts numbers: a number argument becomes a domain value with fromScalar. For example, add(5) adds the vector (5, 5).
  • identity: the value that reduce gives for an empty list.
  • implementation: method calls the method of the value with the same name. fn calls a function of the domain.
Vec247 ops · fromScalar · valid · encode/decode
opparameterslawslifts numbersidentityimplementation
xnonefn
ynonefn
adddomaincommutative, associativeyesyesmethod
subtractdomainyesmethod
multiplydomaincommutative, associativeyesyesmethod
dividedomainyesmethod
mindomaincommutative, associative, idempotentyesmethod
maxdomaincommutative, associative, idempotentyesmethod
scalenumbermethod
negatenonemethod
halvenonemethod
absnonemethod
signnonemethod
roundnonemethod
floornonemethod
ceilnonemethod
clampnumber, numbermethod
swapnonemethod
composenumber, numbermethod
selectdomain, domainyesmethod
rotatenumbermethod
normalizenonemethod
minAxisnonemethod
lerpdomain, numbermethod
lengthnonemethod
lengthSqnonemethod
distancedomainmethod
dotdomaincommutativemethod
alongdomainmethod
acrossdomainmethod
crossdomainmethod
anglenonemethod
areanonemethod
sumnonemethod
minComponentnonemethod
maxComponentnonemethod
equalsdomaincommutativemethod
anyNonPositivenonemethod
allPositivenonemethod
anyNegativenonemethod
allNonNegativenonemethod
anyZerononemethod
allZerononemethod
anyLessThannumbermethod
allLessThannumbermethod
anyGreaterThannumbermethod
allGreaterThannumbermethod
NDVector17 ops · valid · encode/decode
opparameterslawslifts numbersidentityimplementation
adddomaincommutative, associativeyesmethod
subtractdomainmethod
multiplydomaincommutative, associativemethod
mindomaincommutative, associative, idempotentmethod
maxdomaincommutative, associative, idempotentmethod
mergePreferNonZerodomainassociative, idempotentmethod
scalenumbermethod
clampnumber, numbermethod
dotdomaincommutativemethod
lengthnot checkedmethod
norm1not checkedmethod
normInfnot checkedmethod
equalsdomaincommutativemethod
picknot checkedmethod
withKeysnot checkedmethod
getstringmethod
setstring, numbermethod
NDVector(lifted)17 ops · fromScalar · valid
opparameterslawslifts numbersidentityimplementation
adddomaincommutative, associativeyesyesmethod
subtractdomainyesmethod
multiplydomaincommutative, associativeyesmethod
mindomaincommutative, associative, idempotentmethod
maxdomaincommutative, associative, idempotentmethod
mergePreferNonZerodomainassociative, idempotentmethod
scalenumbermethod
clampnumber, numbermethod
dotdomaincommutativeyesmethod
lengthnot checkedmethod
norm1not checkedmethod
normInfnot checkedmethod
equalsdomaincommutativemethod
picknot checkedmethod
withKeysnot checkedmethod
getstringmethod
setstring, numbermethod
NumRecord1 ops
opparameterslawslifts numbersidentityimplementation
toNDVectornot checkedfn
Color8 ops · fromScalar · valid · encode/decode
opparameterslawslifts numbersidentityimplementation
adddomaincommutative, associativeyesmethod
multiplynumbermethod
clampnumber, numbermethod
mixdomain, numbermethod
luminancenot checkedmethod
relativeLuminancenot checkedmethod
contrastdomaincommutativemethod
equalsdomaincommutativemethod
Angle8 ops · fromScalar · valid · encode/decode
opparameterslawslifts numbersidentityimplementation
adddomaincommutative, associativeyesyesmethod
subtractdomainyesmethod
scalenumbermethod
normalizenot checkedmethod
toVec2numbermethod
sinnot checkedmethod
cosnot checkedmethod
degreesnot checkedmethod
Date13 ops · valid · encode/decode
opparameterslawslifts numbersidentityimplementation
addnumbermethod
subtractanymethod
addMonthsnumbermethod
endOfMonthnumbermethod
yearnot checkedmethod
monthnot checkedmethod
daynot checkedmethod
weekdaynot checkedmethod
gtdomainmethod
gtedomainmethod
ltdomainmethod
ltedomainmethod
eqdomaincommutativemethod
Quantity20 ops · valid · encode/decode
opparameterslawslifts numbersidentityimplementation
valuenonefn
unitnonefn
kindnonefn
convertstringfn
valueInstringfn
adddomainfn
subtractdomainfn
multiplynumberfn
dividenumberfn
ratiodomainfn
negatenonefn
absnonefn
mindomainfn
maxdomainfn
comparedomainfn
ltdomainfn
ltedomainfn
gtdomainfn
gtedomainfn
eqdomainfn
Num32 ops · valid
opparameterslawslifts numbersidentityimplementation
addnumbercommutative, associativeyesfn
subtractnumberfn
multiplynumbercommutative, associativeyesfn
dividenumberfn
modnumberfn
pownumberfn
minnumbercommutative, associative, idempotentfn
maxnumbercommutative, associative, idempotentfn
clampnumber, numberfn
absnot checkedfn
negatenot checkedfn
signnot checkedfn
sqrtnot checkedfn
lnnot checkedfn
expnot checkedfn
log10not checkedfn
sinnot checkedfn
cosnot checkedfn
asinnot checkedfn
hypotnumbercommutativefn
datenumber, numberfn
vec2numberfn
xynumberfn
insetsnumber, number, numberfn
floornot checkedfn
ceilnot checkedfn
roundnot checkedfn
gtnumberfn
gtenumberfn
ltnumberfn
ltenumberfn
eqnumbercommutativefn
Bool5 ops
opparameterslawslifts numbersidentityimplementation
andbooleancommutative, associative, idempotentyesfn
orbooleancommutative, associative, idempotentyesfn
xorbooleancommutative, associativeyesfn
notnot checkedfn
eqbooleancommutativefn
Text9 ops
opparameterslawslifts numbersidentityimplementation
concatanyfn
lengthnot checkedfn
codePointsnot checkedfn
epochMillisnonefn
uppernot checkedfn
lowernot checkedfn
trimnot checkedfn
containsstringfn
eqstringcommutativefn
Fn1 ops
opparameterslawslifts numbersidentityimplementation
invokenot checkedmethod
Maybe5 ops
opparameterslawslifts numbersidentityimplementation
isTopnot checkedmethod
isBottomnot checkedmethod
mapnot checkedmethod
chainnot checkedmethod
valueOrnot checkedmethod
Json5 ops
opparameterslawslifts numbersidentityimplementation
kindnonefn
kindsnonefn
fieldsnonefn
fieldanyfn
leavesnumberfn

A LocalDate is a day of the calendar, without a time and without a time zone. It keeps the count of days since 1970-01-01. Thus a date plus a number is a later date, and a date minus a date is a count of days. The op date of NumDomain makes a date from a year, a month and a day. A month or a day outside its range rolls over, like DATE of a spreadsheet.

import { DateDomain, LocalDate, NumDomain } from "@mark1russell7/vex-domains";
const bills = vex(NumDomain, DateDomain).over(space.array([{ issued: LocalDate.of(2026, 9, 1), terms: 30 }]));
const due = bills.from("issued")._.add("terms");
due.at("0"); // => some(LocalDate.of(2026, 10, 1))
LocalDate.of(2026, 13, 1).toString(); // => "2027-01-01"

addMonths and endOfMonth move by months, like EDATE and EOMONTH. One month after 31 January is the last day of February.

QuantityDomain of the entry @mark1russell7/vex-domains/quantity reads amounts in units as plain data, for example { value: 155, unit: "mm" }. The package @mark1russell7/quantity converts each amount exactly. Thus lte of 155 mm and 16 cm is true, and a sum of 0.1 m and 0.2 m is 0.3 m. add, subtract, min and max give the result in the unit of the receiver. Two amounts of different kinds give #CALC! with the reason. Put QuantityDomain before JsonDomain.

JsonDomain reads JSON data, for example the documents of a database. It accepts texts, finite numbers, booleans, arrays and plain objects. Put it last in the list of domains. Then add and eq go to the domains of numbers and texts first. kind gives the kind of a value. kinds gives the kind of each item or field, with "null" for null. fields gives the keys of an object, and field gives the value of one key.

leaves(o, depth) gives the leaves of the object o as a list of records with a path, a kind and a value. The walk goes into an object with fields while the path has fewer than depth keys. The schema pilot of @vex/pilots uses these ops. Its program gives one record for each field path of the documents, with the distinct kinds and the count of the documents with the path.

import { schemaOf } from "@vex/pilots";
const docs = [{ _id: "a", n: 1, tags: ["x"], o: { p: true } }, { _id: "b", n: "2", o: {} }];
JsonDomain.ops.kinds.fn({ a: 1, b: null, c: [] }); // => ["number", "null", "array"]
JsonDomain.ops.leaves.fn({ a: { b: 1 }, c: null }, 3); // => [{ path: "a.b", kind: "number", value: 1 }, { path: "c", kind: "null" }]
schemaOf(docs).map((f) => `${f.path} ${f.kinds.join(",")} ${f.count}`); // => ["_id string 2", "n number,string 2", "tags array<string> 1", "o.p boolean 1", "o object 1"]