ListExtensions<T> extension

Extensions on nullable Iterable for safe access, indexed iteration, and aggregate calculations.

All methods are null-safe — if the iterable is null, you get sensible defaults (empty list, zero sum, etc.) instead of a crash.

List<int>? scores;
scores.validate();                  // []
[1, 3, 7].sumBy((n) => n);         // 11
[10, 20, 30].averageBy((n) => n);  // 20.0
on

Methods

averageBy(num selector(T)) → double?

Available on Iterable<T>?, provided by the ListExtensions extension

Example:
forEachIndexed(void action(T element, int index)) → void

Available on Iterable<T>?, provided by the ListExtensions extension

Like forEach, but the callback also receives the current index.
sumBy(int selector(T)) → int

Available on Iterable<T>?, provided by the ListExtensions extension

Example:
sumByDouble(num selector(T)) → double

Available on Iterable<T>?, provided by the ListExtensions extension

Example:
validate() → List<T>

Available on Iterable<T>?, provided by the ListExtensions extension

Returns this iterable as a List, or an empty list if null.