Skip to content

Commit

Permalink
Removed List implementing Set
Browse files Browse the repository at this point in the history
Renamed some `List` methods
  • Loading branch information
james-pre committed Oct 2, 2024
1 parent 8b705c4 commit 4b85e03
Showing 1 changed file with 7 additions and 36 deletions.
43 changes: 7 additions & 36 deletions src/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventEmitter } from 'eventemitter3';

export class List<T> extends EventEmitter<'update'> implements Set<T>, RelativeIndexable<T> {
export class List<T> extends EventEmitter<'update'> implements RelativeIndexable<T> {
public readonly [Symbol.toStringTag] = 'List';

public constructor(values?: readonly T[] | Iterable<T> | null) {
Expand All @@ -12,11 +12,15 @@ export class List<T> extends EventEmitter<'update'> implements Set<T>, RelativeI

protected data = new Set<T>();

public array(): T[] {
public toSet(): Set<T> {
return new Set(this.data);
}

public toArray(): T[] {
return [...this.data];
}

public json() {
public toJSON() {
return JSON.stringify([...this.data]);
}

Expand Down Expand Up @@ -103,39 +107,6 @@ export class List<T> extends EventEmitter<'update'> implements Set<T>, RelativeI
return success;
}

public union<U>(other: ReadonlySetLike<U>): List<T | U> {
return new List(this.data.union(other));
}

public intersection<U>(other: ReadonlySetLike<U>): List<T & U> {
return new List(this.data.intersection(other));
}

public difference<U>(other: ReadonlySetLike<U>): List<T> {
return new List(this.data.difference(other));
}

public symmetricDifference<U>(other: ReadonlySetLike<U>): List<T | U> {
return new List(this.data.symmetricDifference(other));
}

public isSubsetOf(other: ReadonlySetLike<unknown>): boolean {
return this.data.isSubsetOf(other);
}

public isSupersetOf(other: ReadonlySetLike<unknown>): boolean {
return this.data.isSupersetOf(other);
}

public isDisjointFrom(other: ReadonlySetLike<unknown>): boolean {
return this.data.isDisjointFrom(other);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public forEach(callbackfn: (value: T, value2: T, list: List<T>) => void, thisArg?: any): void {
this.data.forEach((v1, v2) => callbackfn.call(thisArg, v1, v2, this));
}

public has(value: T): boolean {
return this.data.has(value);
}
Expand Down

0 comments on commit 4b85e03

Please sign in to comment.