@@ -5,12 +5,12 @@ import { Options } from './options';
55/**
66 * A Set implementation that supports deep equality for values.
77 */
8- export class DeepSet < T > extends Set < T > implements Comparable < DeepSet < T > > {
8+ export class DeepSet < V , TxV = V > extends Set < V > implements Comparable < DeepSet < V , TxV > > {
99 // Just piggy-back on a DeepMap that uses null values
10- private readonly map : DeepMap < T , null > ;
10+ private readonly map : DeepMap < V , null , TxV , null > ;
1111
1212 // NOTE: This is actually a thin wrapper. We're not using super other than to drive the (typed) API contract.
13- constructor ( values ?: readonly T [ ] | null , options ?: Options < T , null > ) {
13+ constructor ( values ?: readonly V [ ] | null , options ?: Options < V , null , TxV , null > ) {
1414 super ( ) ;
1515 const transformedEntries = values ? values . map ( ( el ) => [ el , null ] as const ) : null ;
1616 this . map = new DeepMap ( transformedEntries , options ) ;
@@ -26,22 +26,22 @@ export class DeepSet<T> extends Set<T> implements Comparable<DeepSet<T>> {
2626 /**
2727 * Returns true if the given value is present in the set.
2828 */
29- override has ( key : T ) : boolean {
30- return this . map . has ( key ) ;
29+ override has ( val : V ) : boolean {
30+ return this . map . has ( val ) ;
3131 }
3232
3333 /**
3434 * Store the given value.
3535 */
36- override add ( val : T ) : this {
36+ override add ( val : V ) : this {
3737 this . map . set ( val , null ) ;
3838 return this ;
3939 }
4040
4141 /**
4242 * Deletes the specified value.
4343 */
44- override delete ( val : T ) : boolean {
44+ override delete ( val : V ) : boolean {
4545 return this . map . delete ( val ) ;
4646 }
4747
@@ -55,7 +55,7 @@ export class DeepSet<T> extends Set<T> implements Comparable<DeepSet<T>> {
5555 /**
5656 * Standard forEach function.
5757 */
58- override forEach ( callbackfn : ( val : T , val2 : T , set : Set < T > ) => void ) : void {
58+ override forEach ( callbackfn : ( val : V , val2 : V , set : Set < V > ) => void ) : void {
5959 this . map . forEach ( ( _mapVal , mapKey , _map ) => {
6060 callbackfn ( mapKey , mapKey , this ) ;
6161 } ) ;
@@ -66,7 +66,7 @@ export class DeepSet<T> extends Set<T> implements Comparable<DeepSet<T>> {
6666 *
6767 * @yields the next value in the set
6868 */
69- override * [ Symbol . iterator ] ( ) : IterableIterator < T > {
69+ override * [ Symbol . iterator ] ( ) : IterableIterator < V > {
7070 for ( const [ key , _val ] of this . map [ Symbol . iterator ] ( ) ) {
7171 yield key ;
7272 }
@@ -77,7 +77,7 @@ export class DeepSet<T> extends Set<T> implements Comparable<DeepSet<T>> {
7777 *
7878 * @yields the next value-value pair in the set
7979 */
80- override * entries ( ) : IterableIterator < [ T , T ] > {
80+ override * entries ( ) : IterableIterator < [ V , V ] > {
8181 for ( const val of this [ Symbol . iterator ] ( ) ) {
8282 yield [ val , val ] ;
8383 }
@@ -88,7 +88,7 @@ export class DeepSet<T> extends Set<T> implements Comparable<DeepSet<T>> {
8888 *
8989 * @yields the next key in the map
9090 */
91- override * keys ( ) : IterableIterator < T > {
91+ override * keys ( ) : IterableIterator < V > {
9292 for ( const val of this [ Symbol . iterator ] ( ) ) {
9393 yield val ;
9494 }
@@ -99,7 +99,7 @@ export class DeepSet<T> extends Set<T> implements Comparable<DeepSet<T>> {
9999 *
100100 * @yields the next value in the map
101101 */
102- override * values ( ) : IterableIterator < T > {
102+ override * values ( ) : IterableIterator < V > {
103103 yield * this . keys ( ) ;
104104 }
105105
0 commit comments