Enumerable<T>.repeat constructor
Creates an enumerable from a value repeated count
times.
A convenience factory to create an enumerable by repeating value
count
number of times. The value in value
is not copied, so every element will
point to the same object:
final mapValue = { 'a': 1 };
final enumerable = Enumerable.repeat(3, mapValue);
mapValue['a'] = 2;
print(enumerable);
// Output:
// [{ 'a': 2 }, { 'a': 2 }, { 'a': 2 }]
count
must be a non-negative number.
Implementation
factory Enumerable.repeat(T value, int count) {
RangeError.checkNotNegative(count);
if (count == 0) return Enumerable<T>.empty();
return RepeatEnumerable<T>(value, count);
}