Skip to content

unify soft()

Eugene Lazutkin edited this page Apr 6, 2026 · 2 revisions

Wraps an object to be treated as "soft" during unification.

Introduction

Marks an object as "soft" — bidirectional open matching that merges missing properties from each side. When two soft objects are unified, each gains the other's unique properties.

import {soft} from 'deep6/unify.js';
import unify from 'deep6/unify.js';

// Soft pattern allows more flexible matching
const pattern = soft({a: 1, b: 2});

unify({a: 1, b: 2, c: 3}, pattern); // truthy - extra properties allowed
unify({a: 1, b: 2}, pattern); // truthy

API

soft(o)

Arguments:

  • o — a required object to wrap. Can be a plain object, array, Map, or Set.

Returns a wrapped version of o that will be treated as "soft" during unification.

Details

When an object is marked as "soft":

  • Common properties are compared normally.
  • Extra properties on either side are copied to the other side.
  • The soft object is mutated to collect all properties after unification.

This is useful for accumulating properties across multiple unifications. See Wrapping for detailed examples.

See Also

  • isSoft() — check if an object is wrapped as soft.
  • open() — wrap an object as "open".
  • isWrapped() — check if an object is wrapped.

Clone this wiki locally