Extensions on Generics
Extend List, Iterable, and type parameters.
Extending Collections
The real magic appears when you extend generic types like List or Iterable. One extension can help every element type at once.
Declare a Type Parameter
Put a type parameter after the extension name, then use it in the on clause. Now your helper stays fully type-safe.
extension Firsts<T> on List<T> {
T? get firstOrNull => isEmpty ? null : this[0];
}