firstWhereOrNull method

T? firstWhereOrNull(
  1. bool test(
    1. T item
    )
)

Returns the first element for which the return value of test is true.

Null is returned if there is no element for which the return value of test is true.

testの返り値がtrueになる場合の最初の要素を返します。

testの返り値がtrueになる要素がない場合はNullが返されます。

Implementation

T? firstWhereOrNull(bool Function(T item) test) {
  if (isEmpty) {
    return null;
  }
  for (final element in this) {
    if (test(element)) {
      return element;
    }
  }
  return null;
}