repeat method

Iterable<E> repeat({
  1. int? count,
})

Returns an infinite iterable with the elements of this iterable. If count is provided the resulting iterator is limited to count repetitions.

Example expressions:

[1, 2].repeat();               // [1, 2, 1, 2, ...]
[1, 2, 3].repeat(count: 2);    // [1, 2, 3, 1, 2, 3]

Implementation

Iterable<E> repeat({int? count}) {
  if (count == 0 || isEmpty) {
    return const [];
  } else if (count == 1 || this is InfiniteIterable) {
    return this;
  } else if (count == null) {
    return RepeatIterableIterable<E>(this);
  } else {
    RangeError.checkNotNegative(count, 'count');
    return RepeatIterableIterable<E>(this).take(count * length);
  }
}