MVFM

dagql/spliceWhere

Remove matched nodes from the graph, reconnecting their first child to their parents.

// 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: splice out the mul node — its first child (add) becomes the root expression
const spliced = spliceWhere(injected.__nexpr, byKind("num/mul"));

// 4. fold: mul removed, so the add result flows directly → 5+10=15
await fold(spliced, defaults(app));
Ctrl+Enter