firstWhereOrNull<T> function

T? firstWhereOrNull<T>(
  1. Iterable<T> iterable,
  2. bool test(
    1. T
    )
)

Not JSON-specific — a hand-rolled Iterable.firstWhere-or-null so the generated code doesn't need the collection package as a pub dependency.

Implementation

T? firstWhereOrNull<T>(Iterable<T> iterable, bool Function(T) test) {
  for (final item in iterable) {
    if (test(item)) return item;
  }
  return null;
}