All files / src/iterators SelectManyIterator.js

100% Statements 7/7
100% Branches 2/2
100% Functions 2/2
100% Lines 7/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22        53x   53x 2x     51x       45x 157x 273x          
import Iterator from './Iterator';
 
export default class SelectManyIterator extends Iterator {
  constructor(arr, callback) {
    super(arr);
 
    if (typeof callback !== 'function') {
      throw new Error('Callback must be a function');
    }
 
    this.callback = callback;
  }
 
  *[Symbol.iterator]() {
    for (let item of this.arr) {
      for (let subItem of this.callback(item)) {
        yield subItem;
      }
    }
  }
}