1
0
This commit is contained in:
2025-09-26 10:40:46 +02:00
parent f6a9dd97ed
commit 400644e079
3 changed files with 28 additions and 24 deletions

View File

@@ -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--;
}
}