本文整理汇总了TypeScript中equatable.Equaler类的典型用法代码示例。如果您正苦于以下问题:TypeScript Equaler类的具体用法?TypeScript Equaler怎么用?TypeScript Equaler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Equaler类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: if
export function includesSequence<T>(left: Queryable<T>, right: Queryable<T>, equaler: EqualityComparison<T> | Equaler<T> = Equaler.defaultEqualer): boolean {
if (typeof equaler === "function") equaler = Equaler.create(equaler);
assert.mustBeQueryable(left, "source");
assert.mustBeQueryable(right, "other");
assert.mustBeEqualer(equaler, "equaler");
const rightArray = toArray(right);
const numRightElements = rightArray.length;
if (numRightElements <= 0) {
return true;
}
const span: T[] = [];
for (const leftValue of ToIterable(left)) {
for (;;) {
const rightValue = rightArray[span.length];
if (equaler.equals(leftValue, rightValue)) {
if (span.length + 1 >= numRightElements) {
return true;
}
span.push(leftValue);
}
else if (span.length > 0) {
span.shift();
continue;
}
break;
}
}
return false;
}
开发者ID:rbuckton,项目名称:QueryJS,代码行数:29,代码来源:includesSequence.ts
示例2: GetAsyncIterator
export async function correspondsByAsync<T, K>(left: AsyncQueryable<T>, right: AsyncQueryable<T>, leftKeySelector: (element: T) => K, rightKeySelector: (element: T) => K = leftKeySelector, keyEqualer: EqualityComparison<K> | Equaler<K> = Equaler.defaultEqualer): Promise<boolean> {
assert.mustBeAsyncQueryable<T>(left, "left");
assert.mustBeAsyncQueryable<T>(right, "right");
assert.mustBeFunction(leftKeySelector, "leftKeySelector");
assert.mustBeFunction(rightKeySelector, "rightKeySelector");
assert.mustBeObject(keyEqualer, "keyEqualer");
if (typeof keyEqualer === "function") keyEqualer = Equaler.create(keyEqualer);
const leftIterator = GetAsyncIterator(ToPossiblyAsyncIterable(left));
let leftDone = false;
let leftValue: T;
try {
const rightIterator = GetAsyncIterator(ToPossiblyAsyncIterable(right));
let rightDone = false;
let rightValue: T;
try {
for (;;) {
({ done: leftDone, value: leftValue } = await leftIterator.next());
({ done: rightDone, value: rightValue } = await rightIterator.next());
if (leftDone && rightDone) return true;
if (Boolean(leftDone) !== Boolean(rightDone) || !keyEqualer.equals(leftKeySelector(leftValue), rightKeySelector(rightValue))) return false;
}
}
finally {
if (!rightDone) await AsyncIteratorClose(rightIterator);
}
}
finally {
if (!leftDone) await AsyncIteratorClose(leftIterator);
}
}
开发者ID:rbuckton,项目名称:QueryJS,代码行数:30,代码来源:correspondsByAsync.ts
示例3: GetAsyncIterator
export async function startsWithAsync<T>(left: AsyncQueryable<T>, right: AsyncQueryable<T>, equaler: EqualityComparison<T> | Equaler<T> = Equaler.defaultEqualer): Promise<boolean> {
if (typeof equaler === "function") equaler = Equaler.create(equaler);
assert.mustBeAsyncQueryable<T>(left, "left");
assert.mustBeAsyncQueryable<T>(right, "right");
assert.mustBeEqualer(equaler, "equaler");
const leftIterator = GetAsyncIterator(ToPossiblyAsyncIterable(left));
let leftDone = false;
let leftValue: T;
try {
const rightIterator = GetAsyncIterator(ToPossiblyAsyncIterable(right));
let rightDone = false;
let rightValue: T;
try {
for (;;) {
({ done: leftDone, value: leftValue } = await leftIterator.next());
({ done: rightDone, value: rightValue } = await rightIterator.next());
if (rightDone) return true;
if (leftDone || !equaler.equals(leftValue, rightValue)) return false;
}
}
finally {
if (!rightDone) await AsyncIteratorClose(rightIterator);
}
}
finally {
if (!leftDone) await AsyncIteratorClose(leftIterator);
}
}
开发者ID:rbuckton,项目名称:QueryJS,代码行数:28,代码来源:startsWithAsync.ts
示例4:
export function includes<T>(source: Queryable<T>, value: T, equaler: EqualityComparison<T> | Equaler<T> = Equaler.defaultEqualer): boolean {
if (typeof equaler === "function") equaler = Equaler.create(equaler);
assert.mustBeQueryable(source, "source");
assert.mustBeEqualer(equaler, "equaler");
for (const element of ToIterable(source)) {
if (equaler.equals(value, element)) {
return true;
}
}
return false;
}
开发者ID:rbuckton,项目名称:QueryJS,代码行数:11,代码来源:includes.ts
示例5: await
export async function includesAsync<T>(source: AsyncQueryable<T>, value: T, equaler: EqualityComparison<T> | Equaler<T> = Equaler.defaultEqualer): Promise<boolean> {
if (typeof equaler === "function") equaler = Equaler.create(equaler);
assert.mustBeAsyncQueryable<T>(source, "source");
assert.mustBeEqualer(equaler, "equaler");
for await (const element of ToPossiblyAsyncIterable(source)) {
if (equaler.equals(value, element)) {
return true;
}
}
return false;
}
开发者ID:rbuckton,项目名称:QueryJS,代码行数:11,代码来源:includesAsync.ts
示例6: 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;
}
开发者ID:rbuckton,项目名称:QueryJS,代码行数:15,代码来源:toSet.ts
示例7: 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;
}
开发者ID:rbuckton,项目名称:QueryJS,代码行数:15,代码来源:toSetAsync.ts
示例8: 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;
}
开发者ID:rbuckton,项目名称:QueryJS,代码行数:17,代码来源:toMap.ts
示例9: 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;
}
开发者ID:rbuckton,项目名称:QueryJS,代码行数:17,代码来源:toMapAsync.ts
示例10: toArrayAsync
export async function endsWithAsync<T>(left: AsyncQueryable<T>, right: AsyncQueryable<T>, equaler: EqualityComparison<T> | Equaler<T> = Equaler.defaultEqualer): Promise<boolean> {
if (typeof equaler === "function") equaler = Equaler.create(equaler);
assert.mustBeAsyncQueryable<T>(left, "left");
assert.mustBeAsyncQueryable<T>(right, "right");
assert.mustBeEqualer(equaler, "equaler");
const rightArray = await toArrayAsync(right);
const numElements = rightArray.length;
if (numElements <= 0) {
return true;
}
const leftArray = await toArrayAsync(takeRightAsync(left, numElements));
if (leftArray.length < numElements) {
return false;
}
for (let i = 0; i < numElements; i++) {
if (!equaler.equals(leftArray[i], rightArray[i])) {
return false;
}
}
return true;
}
开发者ID:rbuckton,项目名称:QueryJS,代码行数:21,代码来源:endsWithAsync.ts
注:本文中的equatable.Equaler类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论