min method

E min({
  1. num value(
    1. dynamic
    )?,
})

Returns the element with the minimum value in the iterable.

An optional value function can be provided to define what is compared. If omitted, the element itself is used for comparison.

** Finding the min of string:**

final strings = ['a', 'cccc', 'bb'];
final result = strings.min(value: (s) => s.length); // 'a'

Implementation

E min({num Function(dynamic)? value}) {
  value ??= identity;
  E minElement = this.first;
  num minValue = value(minElement);

  for (var element in skip(1)) {
    num current = value(element);
    if (current < minValue) minElement = element;
  }

  return minElement;
}