Skip to content

traverse assemble()

Eugene Lazutkin edited this page Apr 3, 2026 · 4 revisions

Assembles a new object by resolving variables using environment bindings.

Introduction

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]}

API

assemble(source [, env] [, options])

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.
    • loose — a boolean flag for loose equality.
    • ignoreFunctions — a boolean flag to ignore function properties.
    • context — a custom context object.
    • processObject — a custom object processor.
    • processOther — a custom value processor.
    • processCircular — a custom circular reference processor.

The function returns a new value with all variables replaced.

Registry

The assemble module exports registry and filters arrays for custom type handling:

import assemble from 'deep6/traverse/assemble.js';

assemble.registry.push(MyClass, processMyClass);

Notes

Implemented using walk().

Clone this wiki locally