range<T> function

Iterable<T> range<T>(
  1. T start,
  2. T stop, [
  3. dynamic step
])

Implementation

Iterable<T> range<T>(T start, T stop, [step]) {
  if (start is int && stop is int) {
    return IntRange(start, stop, step?.toInt() ?? 1) as Iterable<T>;
  } else if (start is num && stop is num) {
    return DoubleRange(
            start.toDouble(), stop.toDouble(), step?.toDouble() ?? 1.0)
        as Iterable<T>;
  } else if (T == DateTime) {
    if (step is Duration) {
      return TimeRange(start as DateTime, stop as DateTime, step)
          as Iterable<T>;
    } else if (step is int) {
      return MonthRange(start as DateTime, stop as DateTime, step)
          as Iterable<T>;
    } else {
      throw UnsupportedError(
          'step must be int or Duration for time range. but found $T');
    }
  }

  throw UnsupportedError('range is not supported for $T');
}