-
-
Notifications
You must be signed in to change notification settings - Fork 0
traverse assemble()
Eugene Lazutkin edited this page Apr 6, 2026
·
4 revisions
Assembles a new object by resolving variables using environment bindings.
Creates a new structure by replacing all Variable instances with their bound values from an Env. Unlike deref(), this creates a new object rather than modifying in place.
import {variable} from 'deep6/env.js';
import unify from 'deep6/unify.js';
import assemble from 'deep6/traverse/assemble.js';
const x = variable('x');
const y = variable('y');
const env = unify({x: 42, y: 'hello'}, {x, y});
const pattern = {a: x, b: [y, x]};
const result = assemble(pattern, env);
// result === {a: 42, b: ['hello', 42]}Arguments:
-
source— a required value containing variables to resolve. It can be anything. -
env— an optional Env with variable bindings, or an options object. -
options— an optional object. The following optional properties are recognized:-
circular— a boolean flag to handle circular references. -
symbols— a boolean flag to include symbol properties. -
allProps— a boolean flag to include non-enumerable properties. -
context— a custom context object. -
processObject— a custom object processor. -
processOther— a custom value processor. -
processCircular— a custom circular reference processor. -
registry— a custom type handler registry (flat array of Constructor/handler pairs). -
filters— custom filter functions.
-
The function returns a new value with all variables replaced.
The assemble module exports registry and filters arrays for custom type handling:
import assemble from 'deep6/traverse/assemble.js';
assemble.registry.push(MyClass, processMyClass);Implemented using walk().
Core functions
Environments and variables
Unification
Traverse
Unifiers
Utilities