Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | /**
* Returns an IterableIterator that maps the values of a given IterableIterator
*/
export class MappedIterator<T, TT> implements IterableIterator<TT> {
private readonly iterator: Iterator<T>;
private readonly mapFunction: (val: T) => TT;
constructor(iterator: Iterator<T>, mapFunction: (val: T) => TT) {
this.iterator = iterator;
this.mapFunction = mapFunction;
}
next(): IteratorResult<TT> {
const nextValue = this.iterator.next();
return {
done: nextValue.done,
value: this.mapFunction(nextValue.value),
};
}
[Symbol.iterator](): MappedIterator<T, TT> {
return this;
}
}
|