Skip to content

Commit

Permalink
Clarify types in TimelineIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixHenninger committed Jul 29, 2022
1 parent d8e9166 commit f48d26e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/library/src/base/util/iterators/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export class SliceIterable<T> {
#extractIterator: (
v: NestedIterable<T>,
) => Promise<Iterator<T | NestedIterable<T>>>
#checkIterator: (v: NestedIterable<T>) => boolean
#checkIterator: (v: NestedIterable<T> | T) => boolean

// TODO: Helper functions are necessary because components
// do not follow the iterator protocol; when this change
// is implemented, the helpers can be removed.
constructor(
root: NestedIterable<T>,
extractIterator = async (v: NestedIterable<T>) => v[Symbol.iterator](),
checkIterator = (v: NestedIterable<T>) => Symbol.iterator in v,
checkIterator = (v: NestedIterable<T> | T) => Symbol.iterator in v,
) {
this.#root = root
this.#extractIterator = extractIterator
Expand Down Expand Up @@ -82,7 +82,9 @@ export class SliceIterable<T> {
} else {
if (this.#checkIterator(value)) {
outputStack.push(value)
iteratorStack.push(await this.#extractIterator(value))
// We know that the value is an iterator
// courtesy of the condition above
iteratorStack.push(await this.#extractIterator(value as NestedIterable<T>))
} else {
return { value: [...outputStack, value], done: false }
}
Expand Down

0 comments on commit f48d26e

Please sign in to comment.