replaceAt<T> static method

List<T> replaceAt<T>(
  1. Iterable<T> list,
  2. int index,
  3. T value
)

Returns a new list with the element at index replaced by value. Throws RangeError when index is out of range.

Implementation

static List<T> replaceAt<T>(Iterable<T> list, int index, T value) {
  final source = list.toList();
  if (index < 0 || index >= source.length) {
    throw RangeError.index(index, source);
  }
  source[index] = value;
  return source;
}