MVFM

dagql/wrapByName

Insert a wrapper node above a target — parents get rewired to the wrapper.

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

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

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

// 3. dagql: find the add node, wrap it, then splice to round-trip
const addIds = selectWhere(injected.__nexpr, byKind("num/add"));
const addId = [...addIds][0];
const wrapped = wrapByName(injected.__nexpr, addId, "num/mul");

// wrap then splice is a round-trip — the wrapper is removed
const roundTrip = spliceWhere(commit(wrapped), byKind("num/mul"));

// 4. fold the round-tripped result: still 5+10=15
await fold(roundTrip, defaults(app));
Ctrl+Enter