A Set-like collection with SoHL tracking and iterable enhancements.

SohlSet<T> behaves like a native Set<T> but supports parent linkage and persistence signaling. All iteration methods return Itr<T> for compatibility with functional helpers.

Used when order doesn't matter, but tracking of additions/removals is needed for data persistence or lifecycle. Supports expandingEntries() to allow for dynamic set mutation during iteration.

const s = new SohlSet<ValueModifier>();
s.add(new ValueModifier());
for (const v of s) {
console.log(v);
}

Type Parameters

  • T

Constructors

  • Create a set, optionally seeded from an iterable of initial values.

    Type Parameters

    • T

    Parameters

    • Optionaldata: Iterable<T>

      Optional iterable whose values seed the set.

    Returns SohlSet<T>

Methods

  • Default iterator for the set.

    Allows iteration over the set's values using for...of, spread syntax, or other iterable mechanisms. Delegates to .values(), which returns an Itr<T>.

    Returns Itr<T>

    An iterable iterator over the set's values.

    for (const value of mySet) {
    console.log(value);
    }
  • Adds a value to the set.

    Inserts the specified value into the set if it does not already exist. Tracks the insertion for persistence and lifecycle if supported.

    Parameters

    • value: T

      The value to add.

    Returns this

    The set itself, for chaining.

    mySet.add("newItem").add("anotherItem");
    
  • Removes all values from the set.

    Empties the set completely. This operation marks the set as changed and may notify the persistence system depending on implementation.

    Returns void

    mySet.clear();
    
  • Removes a value from the set.

    Deletes the specified value from the set if present. Marks the set as changed for persistence.

    Parameters

    • value: T

      The value to remove.

    Returns boolean

    true if the value was found and removed, false otherwise.

    const removed = mySet.delete("oldItem");
    
  • Returns an iterator over [value, value] pairs.

    Mimics the behavior of Set.prototype.entries() in JavaScript. Each entry is a pair of [value, value], for compatibility with Map iteration.

    Returns Itr<[T, T]>

    An Itr<[T, T]> for iteration with destructuring.

    for (const [a, b] of mySet.entries()) {
    console.log(a, b); // a === b
    }
  • Iterates entries while allowing dynamic expansion.

    Provides a breadth-first iterator over all entries in the collection, including new items added during the iteration itself. This allows your logic to traverse all known items and process new ones as they are introduced dynamically.

    Unlike standard .entries() iteration, which operates over a fixed snapshot of the data, expandingEntries() reflects live state. As entries are added, they are queued and subsequently included in the iteration.

    Returns Itr<[T, T]>

    The mutating iterator.

    • This method guarantees that every element currently in the collection or added while iterating will be visited once.
    • The order is breadth-first, preserving logical consistency when traversal depends on the state of prior elements.
    const set = new SohlSet<string>();
    set.add("one");

    for (const [value] of set.expandingEntries()) {
    if (value === "one") set.add("two"); // 'two' will be iterated after
    }
  • Returns an iterator over the set's keys (same as values).

    For compatibility with Map, this returns the same iterator as .values(). This is useful for polymorphism with other collection types.

    Returns Itr<T>

    An Itr<T> representing the values/keys of the set.

    for (const key of mySet.keys()) {
    console.log(key);
    }
  • Returns an iterator over the set's values.

    Provides a custom Itr<T> instance for use with chaining and functional operations.

    Returns Itr<T>

    An Itr<T> representing the values in the set.

    mySet.values().filter(v => v.active).forEach(console.log);