本文整理匯總了TypeScript中equatable.Equaler.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Equaler.default方法的具體用法?TypeScript Equaler.default怎麽用?TypeScript Equaler.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類equatable.Equaler
的用法示例。
在下文中一共展示了Equaler.default方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: elementSelector
export function toSet<T>(source: Queryable<T>, elementSelector: ((element: T) => T) | Equaler<T> = identity, equaler?: Equaler<T>): Set<T> | HashSet<T> {
if (IsEqualer(elementSelector)) {
equaler = elementSelector;
elementSelector = identity;
}
assert.mustBeQueryable(source, "source");
assert.mustBeFunction(elementSelector, "elementSelector");
assert.mustBeEqualerOrUndefined(equaler, "equaler");
const set = equaler ? new HashSet<T>(equaler) : new Set<T>();
for (const item of ToIterable(source)) {
const element = elementSelector(item);
set.add(element);
}
return set;
}
示例2: await
export async function toSetAsync<T>(source: AsyncQueryable<T>, elementSelector: ((element: T) => T | PromiseLike<T>) | Equaler<T> = identity, equaler?: Equaler<T>): Promise<Set<T> | HashSet<T>> {
if (IsEqualer(elementSelector)) {
equaler = elementSelector;
elementSelector = identity;
}
assert.mustBeAsyncQueryable<T>(source, "source");
assert.mustBeFunction(elementSelector, "elementSelector");
assert.mustBeEqualerOrUndefined(equaler, "equaler");
const set = equaler ? new HashSet<T>(equaler) : new Set<T>();
for await (const item of ToPossiblyAsyncIterable(source)) {
const element = await elementSelector(item);
set.add(element);
}
return set;
}
示例3: keySelector
export function toMap<T, K>(source: Queryable<T>, keySelector: (element: T) => K, elementSelector: ((element: T) => T) | Equaler<K> = identity, keyEqualer?: Equaler<K>): Map<K, T> | HashMap<K, T> {
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<K, T>(keyEqualer) : new Map<K, T>();
for (const item of ToIterable(source)) {
const key = keySelector(item);
const element = elementSelector(item);
map.set(key, element);
}
return map;
}
示例4: await
export async function toMapAsync<T, K>(source: AsyncQueryable<T>, keySelector: (element: T) => K, elementSelector: ((element: T) => T | PromiseLike<T>) | Equaler<K> = identity, keyEqualer?: Equaler<K>): Promise<Map<K, T> | HashMap<K, T>> {
if (IsEqualer(elementSelector)) {
keyEqualer = elementSelector;
elementSelector = identity;
}
assert.mustBeAsyncQueryable<T>(source, "source");
assert.mustBeFunction(keySelector, "keySelector");
assert.mustBeFunction(elementSelector, "elementSelector");
assert.mustBeEqualerOrUndefined(keyEqualer, "keyEqualer");
const map = keyEqualer ? new HashMap<K, T>(keyEqualer) : new Map<K, T>();
for await (const item of ToPossiblyAsyncIterable(source)) {
const key = keySelector(item);
const element = await elementSelector(item);
map.set(key, element);
}
return map;
}