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
-
- Iterable<
T> ?
- Iterable<
Methods
-
averageBy(
num selector(T)) → double? -
Available on Iterable<
Example:T> ?, provided by the ListExtensions extension -
forEachIndexed(
void action(T element, int index)) → void -
Available on Iterable<
Like forEach, but the callback also receives the currentT> ?, provided by the ListExtensions extensionindex. -
sumBy(
int selector(T)) → int -
Available on Iterable<
Example:T> ?, provided by the ListExtensions extension -
sumByDouble(
num selector(T)) → double -
Available on Iterable<
Example:T> ?, provided by the ListExtensions extension -
validate(
) → List< T> -
Available on Iterable<
Returns this iterable as a List, or an empty list ifT> ?, provided by the ListExtensions extensionnull.