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