firstOrDefault method

T? firstOrDefault([
  1. bool test(
    1. T element
    )?
])

get the first item that match expression or null if not any

Implementation

T? firstOrDefault([bool Function(T element)? test]) {
  var filtered = test == null ? this : where(test);
  if (filtered.isNotEmpty) {
    return filtered.first;
  } else {
    return null;
  }
}