Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
*[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 async function toMapAsync(source: AsyncQueryable, keySelector: (element: T) => K, elementSelector: ((element: T) => T | PromiseLike) | Equaler = identity, keyEqualer?: Equaler): Promise | HashMap> {
if (IsEqualer(elementSelector)) {
keyEqualer = elementSelector;
elementSelector = identity;
}
assert.mustBeAsyncQueryable(source, "source");
assert.mustBeFunction(keySelector, "keySelector");
assert.mustBeFunction(elementSelector, "elementSelector");
assert.mustBeEqualerOrUndefined(keyEqualer, "keyEqualer");
const map = keyEqualer ? new HashMap(keyEqualer) : new Map();
for await (const item of ToPossiblyAsyncIterable(source)) {
const key = keySelector(item);
const element = await elementSelector(item);
map.set(key, element);
}
return map;
}
/** @internal */ export async function CreateGroupingsAsync(source: AsyncQueryable, keySelector: (element: T) => K, elementSelector: (element: T) => V | PromiseLike, keyEqualer?: Equaler): Promise | HashMap> {
const map = keyEqualer ? new HashMap(keyEqualer) : new Map();
for await (const item of ToPossiblyAsyncIterable(source)) {
let key = keySelector(item);
let element = await elementSelector(item);
let grouping = map.get(key);
if (grouping == null) {
grouping = [];
map.set(key, grouping);
}
grouping.push(element);
}
return map;
}
export function toMap(source: Queryable, keySelector: (element: T) => K, elementSelector: ((element: T) => T) | Equaler = identity, keyEqualer?: Equaler): Map | HashMap {
if (IsEqualer(elementSelector)) {
keyEqualer = elementSelector;
elementSelector = identity;
}
assert.mustBeQueryable(source, "source");
assert.mustBeFunction(keySelector, "keySelector");
assert.mustBeFunction(elementSelector, "elementSelector");
assert.mustBeEqualerOrUndefined(keyEqualer, "keyEqualer");
const map = keyEqualer ? new HashMap(keyEqualer) : new Map();
for (const item of ToIterable(source)) {
const key = keySelector(item);
const element = elementSelector(item);
map.set(key, element);
}
return map;
}
constructor(entries: Queryable<[K, Queryable]>, keyEqualer?: Equaler) {
assert.mustBeQueryable(entries, "entries");
assert.mustBeEqualerOrUndefined(keyEqualer, "keyEqualer");
this._entries = keyEqualer ? new HashMap(ToIterable(entries), keyEqualer) : new Map(ToIterable(entries));
this._source = new LookupIterable(this._entries, CreateGrouping);
}
export function CreateGroupings(source: Queryable, keySelector: (element: T) => K, elementSelector: (element: T) => V, keyEqualer?: Equaler): Map | HashMap {
const map = keyEqualer ? new HashMap(keyEqualer) : new Map();
for (const item of ToIterable(source)) {
let key = keySelector(item);
let element = elementSelector(item);
let grouping = map.get(key);
if (grouping == null) {
grouping = [];
map.set(key, grouping);
}
grouping.push(element);
}
return map;
}