Skip to content

Commit

Permalink
Remove our iterate() in favor of new global API
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF committed Mar 9, 2023
1 parent 6b4e038 commit c5ce0b8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
10 changes: 0 additions & 10 deletions src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ export const entries: <K extends string, V>(o: Record<K, V>) => Array<[K, V]> =
export const keys: <K extends string>(o: Record<K, unknown>) => K[] =
Object.keys as any;

export const iterate = <T>(
iterator: Iterable<T> | IterableIterator<T>,
): readonly T[] => {
const res: T[] = [];
for (const item of iterator) {
res.push(item);
}
return res;
};

/**
* Work around `in` operator not narrowing type
* https://github.com/microsoft/TypeScript/issues/21732
Expand Down
6 changes: 3 additions & 3 deletions src/components/scripture/books.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LazyGetter as Once } from 'lazy-get-decorator';
import { random, range, sumBy } from 'lodash';
import { inspect } from 'util';
import { iterate, NotFoundException } from '../../common';
import { NotFoundException } from '~/common';
import { ScriptureReference } from './dto';
import { BookDifficulty as Difficulty } from './dto/book-difficulty.enum';

Expand Down Expand Up @@ -566,7 +566,7 @@ export class Book implements Iterable<Chapter> {
}

get chapters() {
return iterate(this);
return this[Symbol.iterator]().toArray();
}

randomChapter(after?: Chapter) {
Expand Down Expand Up @@ -689,7 +689,7 @@ export class Chapter implements Iterable<Verse> {
}

get verses() {
return iterate(this);
return this[Symbol.iterator]().toArray();
}

[inspect.custom]() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/scripture/verse-equivalents.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sum, sumBy } from 'lodash';
import { iterate, Range } from '../../common';
import { Range } from '~/common';
import { Book, Verse } from './books';
import {
BookDifficulty,
Expand All @@ -14,7 +14,7 @@ export const getTotalVerseEquivalents = (
) => {
const verses = mergeScriptureRanges(refs)
.map((range) => mapRange(range, Verse.fromRef))
.flatMap((range) => iterate(splitRangeByBook(range)))
.flatMap((range) => splitRangeByBook(range).toArray())
.map((range) => {
const factor = factorOfBook(range.start.book);
return factor * (range.end.id - range.start.id + 1);
Expand Down

0 comments on commit c5ce0b8

Please sign in to comment.