MVFM

dagql/replaceWhere

Swap the kind of matching nodes while preserving their children and output type.

// 1. make an app
const app = mvfm(prelude, console_);

// 2. make a program: (x + 10) * 2
const prog = app({ x: "number" }, ($) =>
  $.begin(
    $.console.log("before:", $.mul($.add($.input.x, 10), 2)),
    $.mul($.add($.input.x, 10), 2)
  )
);

const injected = injectInput(prog, { x: 5 });

// 3. dagql: replace all add nodes with sub
const rewritten = commit(
  replaceWhere(injected.__nexpr, byKind("num/add"), "num/sub")
);

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