ts-data-forge
    Preparing search index...
    • Computes the intersection of two ISetMapped instances.

      Type Parameters

      • K

        The type of the elements.

      • KM extends Primitive

        The type of the mapped keys.

      Parameters

      Returns ISetMapped<K, KM>

      A new ISetMapped instance representing the intersection.

      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 left = ISetMapped.create<Point, string>(
      [
      { x: 1, tag: 'a' },
      { x: 2, tag: 'b' },
      ],
      toKey,
      fromKey,
      );
      const right = ISetMapped.create<Point, string>(
      [{ x: 2, tag: 'b' }],
      toKey,
      fromKey,
      );

      const overlap = ISetMapped.intersection(left, right);

      assert.deepStrictEqual(Array.from(overlap), [{ x: 2, tag: 'b' }]);