ts-data-forge
    Preparing search index...
    • Computes the difference between two ISet instances, identifying added and deleted elements.

      This function performs a set difference operation to determine what elements were added and what elements were deleted when transitioning from the old set to the new set. This is useful for change detection, state management, and synchronization scenarios.

      Performance: O(n + m) where n and m are the sizes of the old and new sets respectively.

      Type Parameters

      • K extends Primitive

        The type of the elements.

      Parameters

      • oldSet: ISet<K>

        The original set representing the previous state.

      • newSet: ISet<K>

        The new set representing the current state.

      Returns ReadonlyRecord<"added" | "deleted", ISet<K>>

      An object with added and deleted properties, each containing an ISet of elements that were added or removed respectively.

      const previous = ISet.create<string>(['draft', 'review']);
      const current = ISet.create<string>(['review', 'published']);

      const { added, deleted } = ISet.diff(previous, current);

      assert.deepStrictEqual(Array.from(added), ['published']);
      assert.deepStrictEqual(Array.from(deleted), ['draft']);