Add timestamp iterator

This commit is contained in:
David Payr
2024-12-28 23:46:47 +01:00
parent 792d9bd396
commit bffe0e60a6
9 changed files with 526 additions and 217 deletions
+15 -1
View File
@@ -165,7 +165,7 @@ export const binarySearchExact = <T>(arr: T[], key: number, valueGetter: (x: T)
if (midVal === key) {
res = mid;
high = mid - 1; // continue searching left to find the lowest index
high = mid - 1; // Continue searching left to find the lowest index
} else if (midVal < key) {
low = mid + 1;
} else {
@@ -213,3 +213,17 @@ export const removeItem = <T>(arr: T[], item: T) => {
arr.splice(index, 1);
}
};
export type AnyIterable<T> =
| Iterable<T>
| AsyncIterable<T>;
export const toAsyncIterator = async function* <T>(source: AnyIterable<T>): AsyncGenerator<T, void, unknown> {
if (Symbol.iterator in source) {
// @ts-expect-error Trust me
yield* source[Symbol.iterator]();
} else {
// @ts-expect-error Trust me
yield* source[Symbol.asyncIterator]();
}
};