LightStats<T extends num>.fromData constructor
LightStats<T extends num>.fromData (
- Iterable<
T> source
Implementation
factory LightStats.fromData(Iterable<T> source) {
num sum = 0;
var count = 0;
T? min, max;
for (var value in source) {
min = (min == null) ? value : math.min(min, value);
max = (max == null) ? value : math.max(max, value);
count++;
sum += value;
}
if (count == 0) {
throw ArgumentError.value(source, 'source', 'Cannot be empty.');
}
final mean = sum / count;
return LightStats(count, mean, min!, max!);
}