ts-data-forge
    Preparing search index...
    • Computes the difference between two ISetMapped instances.

      Type Parameters

      • K

        The type of the elements.

      • KM extends Primitive

        The type of the mapped keys.

      Parameters

      Returns ReadonlyRecord<"added" | "deleted", ISetMapped<K, KM>>

      An object containing sets of added and deleted elements.

      type Point = Readonly<{ x: number; tag: string }>;

      const toKey = (point: Point) => JSON.stringify(point);

      // eslint-disable-next-line total-functions/no-unsafe-type-assertion
      const fromKey = (key: string) => JSON.parse(key) as Point;

      const previous = ISetMapped.create<Point, string>(
      [
      { x: 1, tag: 'a' },
      { x: 2, tag: 'b' },
      ],
      toKey,
      fromKey,
      );
      const current = ISetMapped.create<Point, string>(
      [
      { x: 2, tag: 'b' },
      { x: 3, tag: 'c' },
      ],
      toKey,
      fromKey,
      );

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

      assert.deepStrictEqual(Array.from(added), [{ x: 3, tag: 'c' }]);
      assert.deepStrictEqual(Array.from(deleted), [{ x: 1, tag: 'a' }]);