Public
Edited
Feb 29, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
isUnifier = (value) => value && typeof value.unify === "function"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
evaluate = (policy, facts) => Evaluator.evaluate(policy, facts)
Insert cell
Insert cell
Insert cell
Insert cell
substitute = Substitutions.substitute
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
evaluate(
[
[".messages", ".", "?self"]
// ["in", "?email", "?to"],
// ["like", "?email", "*@web.mail"]
],
{
messages: [{ to: ["alice@web.mail"], message: "hello" }]
}
)
Insert cell
evaluate([["<", ".x", ".y"]], { x: 1, y: 2 })
Insert cell
evaluate(
[
[".messages[].to", "?", "?to"],
["includes", "?email", "?to"],
["like", "?email", "*@web.mail"]
],
{
messages: [{ to: ["bob@gmail.com", "alice@web.mail"], message: "hello" }]
}
)
Insert cell
query(
[
[".mail", "?", "?mail"],
["includes", "?message", "?mail"]
],
{
mail: [
{ to: ["alice@web.mail"], message: "hello" },
{ to: ["bob@gmail.com"], message: "hello" }
]
}
)
Insert cell
query(
[
[".mail", ".", "?mail"],
[".[]", "?mail", "?message"]
],
{
mail: [
{ to: ["alice@web.mail"], message: "hello" },
{ to: ["bob@gmail.com"], message: "hello" }
]
}
)
Insert cell
Insert cell
data = ({
mail: [
{ to: ["alice@web.mail", "malory@web.mail"], body: "hello alice" },
{
to: ["bob@gmail.com", "alice@web.mail"],
body: "hi bob"
}
]
})
Insert cell
Insert cell
evaluate(
[
[".mail", ".", "?msgs"]
// ["of", "?msg", "?msgs"]
// [".to", "?msg", "?to"],
// ["in", "?email", "?to"],
// ["like", "?email", "*@web.mail"]
],
data
)
Insert cell
Insert cell
query(
[
// ["includes", "?to", ".to[]"],
// we unpack each requirement
// [".required[]", ".", "?required"]
["includes", "?required", ".required[]"],
[".to[]", ".", "?to"],
// check that every single one matches requirement
["like", "?to", "?required"]
],
{
to: [
"alice@fission.codes",
"bob@protocol.ai",
"finance@fission.codes",
"fraud@fission.codes"
// should not match if removed
// "bob@gmail.com"
],
// I don't support array literals yet so we'll stick them here
required: ["*@fission.codes", "*@protocol.ai"]
}
)
Insert cell
query([["includes", "?x", [1, 2, 4]]], {})
Insert cell
unify = Reference.unify
Insert cell
satisfies = Reference.satisfies
Insert cell
Insert cell
function* tokenize(selector) {
const { length } = selector;
let offset = 0;
let column = 0;
let context = ".";
const segments = [];

while (column < length) {
const char = selector[column];
if (char === '"' && selector[column - 1] !== "\\") {
column++;
context = context === '"' ? "" : '"';
continue;
}

if (context === '"') {
column++;
continue;
}

switch (char) {
case ".": {
if (offset < column) {
yield selector.slice(offset, column);
}
offset = column;
column++;
break;
}
case "[": {
if (offset < column) {
yield selector.slice(offset, column);
}
offset = column;
column++;
break;
}
case "]": {
column++;
yield selector.slice(offset, column);
offset = column;
break;
}
default: {
column++;
}
}
}

if (offset < column && context != '"') {
yield selector.slice(offset, column);
}
}
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more