updateAt<T> function

Option<ImmutableList<T>> Function(ImmutableList<T>) updateAt<T>(
  1. int index,
  2. T value
)

Returns a function that takes an ImmutableList<T> and updates a specified item at the given index with a new value.

This is essentially a specialized version of modifyAt where the modification function simply replaces the item with a new value.

Usage:

var myList = ImmutableList([1, 2, 3, 4, 5]);
var setItemAt2To99 = updateAt<int>(2, 99);
var newListOption = setItemAt2To99(myList); // Returns option containing ImmutableList([1, 2, 99, 4, 5])
  • Parameters:
    • index: The index of the item to be updated.
    • value: The new value to be set at the specified index.
  • Returns: A function that processes an ImmutableList<T> and returns an Option<ImmutableList<T>> containing the list with the updated item, or None<ImmutableList<T>>() if the index is out of bounds.

Implementation

option.Option<ImmutableList<T>> Function(ImmutableList<T>) updateAt<T>(
    int index, T value) {
  return modifyAt(index, (_) => value);
}