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

View File

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

View File

@@ -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>) {