MVFM

dagql/mapWhere

Transform matching nodes via callback — change kind, children, or metadata.

// 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: mapWhere gives you the full entry to transform
const rewritten = commit(
  mapWhere(injected.__nexpr, byKind("num/add"), (entry) => ({
    kind: "num/sub",
    children: entry.children,
    out: entry.out,
  }))
);

// 4. fold: was (5+10)*2=30, now (5-10)*2=-10
await fold(rewritten, defaults(app));
Ctrl+Enter