replaceFirstWhere method

IList<T> replaceFirstWhere(
  1. bool test(
    1. T item
    ),
  2. T to, {
  3. bool addIfNotFound = false,
})

Finds the first item that satisfies the provided test, and replace it with to.

  • If addIfNotFound is false, return the unchanged list if no item satisfies the test.
  • If addIfNotFound is true, add the item to the end of the list if no item satisfies the test.

Implementation

IList<T> replaceFirstWhere(bool Function(T item) test, T to, {bool addIfNotFound = false}) {
  var index = indexWhere(test);
  return (index != -1)
      ? put(index, to)
      : addIfNotFound
          ? add(to)
          : this;
}