MVFM

zod/lazy

Schema for self-referential and mutually recursive data structures

const app = mvfm(prelude, zod);
const prog = app({ value: "object" }, ($) => {
  const Category = $.zod.object({
    name: $.zod.string(),
    subcategories: $.zod.lazy(() => $.zod.array(Category)),
  });
  return Category.parse($.input.value);
});
await fold(
  defaults(app),
  injectInput(prog, { 
    value: { 
      name: "Electronics", 
      subcategories: [
        { name: "Laptops", subcategories: [] }
      ]
    }
  })
);
Ctrl+Enter