padLeft method

Iterable<E> padLeft(
  1. int totalLength, {
  2. required E padValue,
})

Pads elements to the beginning of this Iterable to make it have the specified length.

If the length of this Iterable is already totalLength or greater, returns this Iterable.

Implementation

Iterable<E> padLeft(int totalLength, {required E padValue}) {
  if (totalLength <= length) {
    return this;
  }

  return Iterable<E>.generate(
    totalLength - length,
    (_) => padValue,
  ).followedBy(this);
}