| 10 | private previousKey = new LuaTable<T, T>(); |
| 11 | |
| 12 | constructor(values?: Iterable<T> | T[]) { |
| 13 | if (values === undefined) return; |
| 14 | |
| 15 | const iterable = values as Iterable<T>; |
| 16 | if (iterable[Symbol.iterator]) { |
| 17 | // Iterate manually because Set is compiled with ES5 which doesn't support Iterables in for...of |
| 18 | const iterator = iterable[Symbol.iterator](); |
| 19 | while (true) { |
| 20 | const result = iterator.next(); |
| 21 | if (result.done) { |
| 22 | break; |
| 23 | } |
| 24 | this.add(result.value); |
| 25 | } |
| 26 | } else { |
| 27 | const array = values as T[]; |
| 28 | for (const value of array) { |
| 29 | this.add(value); |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | public add(value: T): Set<T> { |
| 35 | const isNewValue = !this.has(value); |