<commit_before>import {parseOptions} from './options';
import {isNumber} from './utility';
import {ChPause} from './pause';


// return values from the range start to final synchronously
// when between intervals of size chunk.
//
// on the chunk boundary, return a promise that resolves in delay milliseconds.
//
// an error will be thrown in case an iterator is advanced before a pending
// promise has resolved.
let __chunkify__: (
  start: number,
  final: number,
  options?: IChOptions
) => IterableIterator<number|IChPause> = function*(
  start: number,
  final: number,
  options: IChOptions
) {
  let {
    chunk,
    delay,
  } = options;
  let paused = false;
  let pause = function*() {
    paused = true;
    yield ChPause.for(delay).resume(() => { paused = false; });
  };
  for (let index = start; index < final; index++) {
    if ((index > start) && (index % (start + chunk) === 0)) {
      yield *pause();
    }
    if (paused) {
      throw new Error(`paused at index ${index}; wait ${delay} milliseconds before further invocations of .next()`);
    }
    yield index;
  }
};

export var chunkify = (start: number, final: number, options: IChOptions = {}) => {
  if (!isNumber(start)) {
    throw new Error('start index "start" of generator range must be a number');
  } else if (!isNumber(final)) {
    throw new Error('final index "final" of generator range must be a number');
  }
  return __chunkify__(start, final, parseOptions(options));
};
<commit_msg>clean doc<commit_after>import {parseOptions} from './options';
import {isNumber} from './utility';
import {ChPause} from './pause';


// return values from the range "start" to "final"
// synchronously when between intervals of size "chunk".
//
// on the boundary, return a promise that resolves in "delay" milliseconds.
//
// an error will be thrown in case an iterator is advanced before this promise resolves.
let __chunkify__: (
  start: number,
  final: number,
  options?: IChOptions
) => IterableIterator<number|IChPause> = function*(
  start: number,
  final: number,
  options: IChOptions
) {
  let {
    chunk,
    delay,
  } = options;
  let paused = false;
  let pause = function*() {
    paused = true;
    yield ChPause.for(delay).resume(() => { paused = false; });
  };
  for (let index = start; index < final; index++) {
    if ((index > start) && (index % (start + chunk) === 0)) {
      yield *pause();
    }
    if (paused) {
      throw new Error(`paused at index ${index}; wait ${delay} milliseconds before further invocations of .next()`);
    }
    yield index;
  }
};

export var chunkify = (start: number, final: number, options: IChOptions = {}) => {
  if (!isNumber(start)) {
    throw new Error('start index "start" of generator range must be a number');
  } else if (!isNumber(final)) {
    throw new Error('final index "final" of generator range must be a number');
  }
  return __chunkify__(start, final, parseOptions(options));
};

{'fraction_non_alphanumeric': 0.1401360544217687, 'fraction_numerical': 0.0006802721088435374, 'mean_word_length': 3.456060606060606, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6388164', 'n_tokens_mistral': 887, 'n_tokens_neox': 878, 'n_words': 326}