refactor
This commit is contained in:
@@ -216,27 +216,29 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
}
|
||||
|
||||
async #tryGetLast(predicate?: MaybeAsyncAnyPredicate<TElement>): Promise<FindElementResult<TElement>> {
|
||||
let found = false;
|
||||
let result: TElement | undefined = undefined;
|
||||
let result: FindElementResult<TElement> = {
|
||||
found: false
|
||||
};
|
||||
|
||||
if (predicate) {
|
||||
for await (const element of this) {
|
||||
if (await predicate(element)) {
|
||||
found = true;
|
||||
result = element;
|
||||
result = {
|
||||
found: true,
|
||||
element
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for await (const element of this) {
|
||||
found = true;
|
||||
result = element;
|
||||
result = {
|
||||
found: true,
|
||||
element
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
found,
|
||||
element: result
|
||||
} as FindElementResult<TElement>;
|
||||
return result;
|
||||
}
|
||||
|
||||
async last(predicate?: MaybeAsyncAnyPredicate<TElement>) {
|
||||
@@ -1687,7 +1689,7 @@ class TakeAsyncSequence<T> extends BaseAsyncSequence<T> {
|
||||
return;
|
||||
}
|
||||
|
||||
yield next.value as T;
|
||||
yield next.value;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@ import { Converter } from "../types.js";
|
||||
import { Nullable } from "../utils.js";
|
||||
import { EqualityComparer, EqualityComparison, EqualityComparisonOrComparer } from "./types.js";
|
||||
|
||||
export function looseEquals<T>(a: T, b: T) {
|
||||
export function looseEquals(a: any, b: any) {
|
||||
return a == b;
|
||||
}
|
||||
|
||||
export function strictEquals<T>(a: T, b: T) {
|
||||
export function strictEquals(a: any, b: any) {
|
||||
return a === b;
|
||||
}
|
||||
|
||||
export function sameValue<T>(a: T, b: T) {
|
||||
export function sameValue(a: any, b: any) {
|
||||
return Object.is(a, b);
|
||||
}
|
||||
|
||||
|
||||
@@ -225,27 +225,29 @@ export abstract class BaseSequence<TElement> extends SequenceMarker implements S
|
||||
}
|
||||
|
||||
#tryGetLast(predicate?: AnyPredicate<TElement>): FindElementResult<TElement> {
|
||||
let found = false;
|
||||
let result: TElement | undefined = undefined;
|
||||
let result: FindElementResult<TElement> = {
|
||||
found: false
|
||||
};
|
||||
|
||||
if (predicate) {
|
||||
for (const element of this) {
|
||||
if (predicate(element)) {
|
||||
found = true;
|
||||
result = element;
|
||||
result = {
|
||||
found: true,
|
||||
element
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (const element of this) {
|
||||
found = true;
|
||||
result = element;
|
||||
result = {
|
||||
found: true,
|
||||
element
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
found,
|
||||
element: result
|
||||
} as FindElementResult<TElement>;
|
||||
return result;
|
||||
}
|
||||
|
||||
last(predicate?: AnyPredicate<TElement>) {
|
||||
|
||||
Reference in New Issue
Block a user