replaceFirstWhere method
Finds the first item that satisfies the provided test
,
and replace it with the result of replacement
.
-
If
addIfNotFound
isfalse
, return the unchanged list if no item satisfies thetest
. -
If
addIfNotFound
istrue
, add thereplacement
to the end of the list if no item satisfies thetest
.
Implementation
@useResult
IList<T> replaceFirstWhere(
bool Function(T item) test,
T Function(T? item) replacement, {
bool addIfNotFound = false,
}) {
final int index = indexWhere(test);
return (index != -1)
? put(index, replacement(this[index]))
: addIfNotFound
? add(replacement(null))
: this;
}