MVFM

dagql/gc

Remove unreachable nodes from the graph after mutations.

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

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

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

// 3. dagql: splice out mul (keeps first child = add), leaving sub orphaned
const spliced = spliceWhere(injected.__nexpr, byKind("num/mul"));

// sub node is now unreachable — gc removes it
const cleaned = commit(gc(dirty(spliced)));

console.log("before gc:", Object.keys(spliced.__adj).length, "nodes");
console.log("after gc:", Object.keys(cleaned.__adj).length, "nodes");

// 4. fold the cleaned result: add is now root → 5+10=15
await fold(cleaned, defaults(app));
Ctrl+Enter