Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*[Symbol.iterator](): Iterator {
const keySelector = this._keySelector;
const set = this._keyEqualer ? new HashSet() : new Set();
for (const element of this._left) {
if (TryAdd(set, keySelector(element))) {
yield element;
}
}
for (const element of this._right) {
if (TryAdd(set, keySelector(element))) {
yield element;
}
}
}
}
*[Symbol.iterator](): Iterator {
const keySelector = this._keySelector;
const rightKeys = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
const right = this._keyEqualer ? new HashMap(this._keyEqualer) : new Map();
for (const element of this._right) {
const key = keySelector(element);
if (TryAdd(rightKeys, key)) {
right.set(key, element);
}
}
const set = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
for (const element of this._left) {
const key = keySelector(element);
if (TryAdd(set, key) && !right.has(key)) {
yield element;
}
}
for (const [key, element] of right) {
if (TryAdd(set, key)) {
*[Symbol.iterator](): Iterator {
const keySelector = this._keySelector;
const rightKeys = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
const right = this._keyEqualer ? new HashMap(this._keyEqualer) : new Map();
for (const element of this._right) {
const key = keySelector(element);
if (TryAdd(rightKeys, key)) {
right.set(key, element);
}
}
const set = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
for (const element of this._left) {
const key = keySelector(element);
if (TryAdd(set, key) && !right.has(key)) {
yield element;
}
}
for (const [key, element] of right) {
if (TryAdd(set, key)) {
yield element;
}
}
}
}
export function toSet(source: Queryable, elementSelector: ((element: T) => T) | Equaler = identity, equaler?: Equaler): Set | HashSet {
if (IsEqualer(elementSelector)) {
equaler = elementSelector;
elementSelector = identity;
}
assert.mustBeQueryable(source, "source");
assert.mustBeFunction(elementSelector, "elementSelector");
assert.mustBeEqualerOrUndefined(equaler, "equaler");
const set = equaler ? new HashSet(equaler) : new Set();
for (const item of ToIterable(source)) {
const element = elementSelector(item);
set.add(element);
}
return set;
}
async *[Symbol.asyncIterator](): AsyncIterator {
const set = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
const selector = this._keySelector;
for await (const element of this._source) {
const key = selector(element);
if (!set.has(key)) {
set.add(key);
yield element;
}
}
}
}
*[Symbol.iterator](): Iterator {
const set = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
const keySelector = this._keySelector;
for (const element of this._source) {
const key = keySelector(element);
if (!set.has(key)) {
set.add(key);
yield element;
}
}
}
}
export async function toSetAsync(source: AsyncQueryable, elementSelector: ((element: T) => T | PromiseLike) | Equaler = identity, equaler?: Equaler): Promise | HashSet> {
if (IsEqualer(elementSelector)) {
equaler = elementSelector;
elementSelector = identity;
}
assert.mustBeAsyncQueryable(source, "source");
assert.mustBeFunction(elementSelector, "elementSelector");
assert.mustBeEqualerOrUndefined(equaler, "equaler");
const set = equaler ? new HashSet(equaler) : new Set();
for await (const item of ToPossiblyAsyncIterable(source)) {
const element = await elementSelector(item);
set.add(element);
}
return set;
}
async *[Symbol.asyncIterator](): AsyncIterator {
const keySelector = this._keySelector;
const rightKeys = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
const right = this._keyEqualer ? new HashMap(this._keyEqualer) : new Map();
for await (const element of this._right) {
const key = keySelector(element);
if (TryAdd(rightKeys, key)) {
right.set(key, element);
}
}
const set = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
for await (const element of this._left) {
const key = keySelector(element);
if (TryAdd(set, key) && !right.has(key)) {
yield element;
}
}
for (const [key, element] of right) {
if (TryAdd(set, key)) {
async *[Symbol.asyncIterator](): AsyncIterator {
const keySelector = this._keySelector;
const rightKeys = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
const right = this._keyEqualer ? new HashMap(this._keyEqualer) : new Map();
for await (const element of this._right) {
const key = keySelector(element);
if (TryAdd(rightKeys, key)) {
right.set(key, element);
}
}
const set = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
for await (const element of this._left) {
const key = keySelector(element);
if (TryAdd(set, key) && !right.has(key)) {
yield element;
}
}
for (const [key, element] of right) {
if (TryAdd(set, key)) {
yield element;
}
}
}
}
async *[Symbol.asyncIterator](): AsyncIterator {
const keySelector = this._keySelector;
const set = this._keyEqualer ? new HashSet(this._keyEqualer) : new Set();
for await (const element of this._left) {
if (TryAdd(set, keySelector(element))) {
yield element;
}
}
for await (const element of this._right) {
if (TryAdd(set, keySelector(element))) {
yield element;
}
}
}
}