Skip to content

Commit

Permalink
Now using util functions from utils
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebGerman committed Feb 8, 2024
1 parent e1abc4d commit 0882512
Showing 1 changed file with 1 addition and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { VersionCompare } from "../api/VersionCompare.js";
import { Changeset, NamedVersion } from "../clients/iModelsClient.js";

import "./VersionCompareSelectWidget.scss";
import { splitBeforeEach, flatten, map, skip } from "../utils/utils.js";

/** Options for VersionCompareSelectComponent. */
export interface VersionCompareSelectorProps {
Expand Down Expand Up @@ -352,58 +353,6 @@ function usePagedNamedVersionLoader(
return result;
}

async function* map<T, U>(iterable: AsyncIterable<T>, transform: (value: T) => U): AsyncGenerator<U> {
for await (const value of iterable) {
yield transform(value);
}
}

async function* flatten<T>(iterable: AsyncIterable<T[]>): AsyncGenerator<T> {
for await (const values of iterable) {
for (const value of values) {
yield value;
}
}
}

async function* splitBeforeEach<T, U>(
iterable: AsyncIterable<T>,
selector: (value: T) => U,
markers: U[],
): AsyncGenerator<T[]> {
let accumulator: T[] = [];
let currentMarkerIndex = 0;
for await (const value of iterable) {
if (currentMarkerIndex !== markers.length && selector(value) === markers[currentMarkerIndex]) {
yield accumulator;
accumulator = [];
++currentMarkerIndex;
}

accumulator.push(value);
}

yield accumulator;
}

async function* skip<T>(iterable: AsyncIterable<T>, n: number): AsyncGenerator<T> {
const iterator = iterable[Symbol.asyncIterator]();
for (let i = 0; i < n; ++i) {
const result = await iterator.next();
if (result.done) {
return result.value;
}
}

let result = await iterator.next();
while (!result.done) {
yield result.value;
result = await iterator.next();
}

return result.value;
}

enum VersionProcessedState {
Verifying,
Processed,
Expand Down

0 comments on commit 0882512

Please sign in to comment.