replaceFirstWhere method
Finds the first item that satisfies the provided test
,
and replace it with to
.
- If
addIfNotFound
isfalse
, return the unchanged list if no item satisfies thetest
. - If
addIfNotFound
istrue
, add the item to the end of the list if no item satisfies thetest
.
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;
}