dagql/pipe
Functional chaining — compose multiple DAG transformations in a single expression.
// 1. make an app
const app = mvfm(prelude, console_);
// 2. make a program: (x + 10) * 2
const prog = app({ x: "number" }, ($) =>
$.begin(
$.console.log("result:", $.mul($.add($.input.x, 10), 2)),
$.mul($.add($.input.x, 10), 2)
)
);
const injected = injectInput(prog, { x: 5 });
// 3. dagql: chain two rewrites with pipe
const rewritten = commit(
pipe(
injected.__nexpr,
(e) => replaceWhere(e, byKind("num/add"), "num/sub"),
(e) => replaceWhere(e, byKind("num/mul"), "num/add"),
)
);
// 4. fold: was (5+10)*2=30, now (5-10)+2=-3
await fold(rewritten, defaults(app)); Ctrl+Enter