repeat<E> function
Returns an infinite iterable with a constant element
. If count
is
provided the resulting iterator is limited to count
elements.
Example expressions:
repeat(2); // [2, 2, 2, 2, 2, 2, ...]
repeat('a', count: 3); // ['a', 'a', 'a']
Implementation
Iterable<E> repeat<E>(E element, {int? count}) {
if (count == 0) {
return const [];
} else if (count == null) {
return RepeatElementIterable<E>(element);
} else {
RangeError.checkNotNegative(count, 'count');
return RepeatElementIterable<E>(element).take(count);
}
}