firstWhereOrAdd<V> function

V firstWhereOrAdd<V>(
  1. List<V> list,
  2. bool test(
    1. V element
    ),
  3. OrAdd<V> orAdd
)

Returns the first element that satisfies the test if there isn't one add a new one and return it.

Implementation

V firstWhereOrAdd<V>(
    List<V> list, bool Function(V element) test, OrAdd<V> orAdd) {
  for (final V element in list) {
    if (test(element)) return element;
  }
  V newElement = orAdd();
  list.add(newElement);
  return newElement;
}