diff --git a/src/common/util.ts b/src/common/util.ts index 7cabb0b5ac..3a1806ddc4 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -48,16 +48,6 @@ export const entries: (o: Record) => Array<[K, V]> = export const keys: (o: Record) => K[] = Object.keys as any; -export const iterate = ( - iterator: Iterable | IterableIterator, -): 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 diff --git a/src/components/scripture/books.ts b/src/components/scripture/books.ts index 5639fae3ac..1efa43f8e9 100644 --- a/src/components/scripture/books.ts +++ b/src/components/scripture/books.ts @@ -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'; @@ -566,7 +566,7 @@ export class Book implements Iterable { } get chapters() { - return iterate(this); + return this[Symbol.iterator]().toArray(); } randomChapter(after?: Chapter) { @@ -689,7 +689,7 @@ export class Chapter implements Iterable { } get verses() { - return iterate(this); + return this[Symbol.iterator]().toArray(); } [inspect.custom]() { diff --git a/src/components/scripture/verse-equivalents.ts b/src/components/scripture/verse-equivalents.ts index f649b51de8..339ea68e53 100644 --- a/src/components/scripture/verse-equivalents.ts +++ b/src/components/scripture/verse-equivalents.ts @@ -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, @@ -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);