resizeWith method

void resizeWith(
  1. int newLen,
  2. T f()
)

Resizes the Vec in-place so that len is equal to newLen. If newLen is greater than len, the Vec is extended by the difference, with each additional slot filled with the result of f. If new_len is less than len, the Vec is simply truncated.

Implementation

void resizeWith(int newLen, T Function() f) {
  if (newLen > length) {
    final doFor = newLen - length;
    for (int i = 0; i < doFor; i++) {
      add(f());
    }
  } else {
    length = newLen;
  }
}