{"size": 1072, "ext": "js", "max_stars_repo_path": "src/adapters/scan.js", "max_stars_repo_name": "jungomi/iterfn", "max_stars_repo_stars_event_min_datetime": "2018-03-14T16:41:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-22T21:38:08.000Z", "max_issues_repo_path": "src/adapters/scan.js", "max_issues_repo_name": "jungomi/iterfn", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/adapters/scan.js", "max_forks_repo_name": "jungomi/iterfn", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.5294117647, "max_line_length": 77, "alphanum_fraction": 0.6567164179}
/**
 * Creates an iterator which accumulates a value. This is similar to fold or
 * reduce, but instead of creating a single value, it yields each step of the
 * accumulator, making the last value equivalent to the output of fold or
 * reduce.
 *
 * @param {Iterable} iter An iterable to be scanned.
 *
 * @param {Any} initialValue The initial value of the accumulator.
 *
 * @param {Function} func A function that receives two arguments, the
 * accumulator and the current value, and returns the new accumulated value,
 * which is also yielded.
 *
 * @returns {Iterator} An iterator which yields each step of the accumulator.
 *
 * @example
 * const a = [1, 2, 3];
 *
 * const iter = scan(a, 1, (acc, x) => acc * x);
 *
 * iter.next(); // { value: 1, done: false }
 * iter.next(); // { value: 2, done: false }
 * iter.next(); // { value: 6, done: false }
 * iter.next(); // { value: undefined, done: false }
 */
export default function* scan(iter, initialValue, func) {
  let acc = initialValue;
  for (const val of iter) {
    acc = func(acc, val);
    yield acc;
  }
}
