updateAt method

ImmortalList<T> updateAt(
  1. int index,
  2. T update(
    1. T value
    )
)

Returns a copy of this list replacing the value at the given index by applying the function update to its value.

If there is no element at the provided index, the list is returned unchanged. The resulting list will have the same length as the original list.

Implementation

ImmortalList<T> updateAt(int index, T Function(T value) update) =>
    elementAtAsOptional(index)
        .map(
          (value) => set(index, update(value)),
        )
        .orElse(this);