iterate function

Iterable<int> iterate(
  1. int from,
  2. int to,
  3. int step,
  4. bool till
)

Builds Iterable of int based on a chosen details

Implementation

Iterable<int> iterate(
  int from,
  int to,
  int step,
  bool till,
) sync* {
  assert(step >= 0, "Step value must be positive.");
  if (from == to) {
    yield from;
  } else if (from < to) {
    for (int i = from; i <= to - (till ? 1 : 0); i += step) {
      yield i;
    }
  } else {
    for (int i = from; i >= to + (till ? 1 : 0); i -= step) {
      yield i;
    }
  }
}