fill method

Iterable<T> fill(
  1. int length,
  2. T generator(
    1. int index
    )
)

If length is greater than the current number, returns Iterable filled with elements generated by generator.

If the length of Iterable is greater than or equal to length, it is returned as is.

現在の数よりlengthが多い場合、generatorで生成された要素で埋められたIterableを返します。

Iterableの長さがlength以上の場合、そのまま返します。

Implementation

Iterable<T> fill(int length, T Function(int index) generator) {
  if (this == null) {
    return List<T>.generate(length, generator);
  }
  if (this.length >= length) {
    return this!;
  }
  final res = List<T>.from(this!);
  for (var i = this.length; i < length; i++) {
    res.add(generator.call(i));
  }
  return res;
}