firstNotNullOf<T> method

T firstNotNullOf<T>(
  1. T? transform(
    1. E element
    )
)

Returns the first non-null value produced by transform function being applied to elements of this collection in iteration order, or throws NoSuchElementException if no non-null value was produced.

Implementation

T firstNotNullOf<T>(T? Function(E element) transform) {
  for (final element in this) {
    final transformed = transform(element);

    if (transformed != null) return transformed;
  }

  throw NoSuchElementException();
}