min method
TValue
min([
- dynamic selector(
- TValue
Finds the element with the smallest value selected by the selector function.
All values returned by the selector must be of type num. If selector is null, the elements itself become the selected elements.
Implementation
TValue min([Function(TValue)? selector]) {
selector ??= (e) => e;
TValue? minObject;
num? minValue;
for (final element in this) {
final value = selector(element);
if (value == null) {
throw BoostException('Selector for element $element returned null!');
} else if (value is! num) {
throw BoostException(
'Selector for element $element did not return num!');
}
if (minValue == null || value < minValue) {
minObject = element;
minValue = value;
}
}
if (minObject == null) {
throw BoostException('Iterable is empty.');
}
return minObject;
}