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--;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user