leastOccurrences method
Finds the least common value in the list.
Returns an Occurrence containing the least common value and its frequency. If the list is empty, returns null. Audited: 2026-06-12 11:26 EDT
Implementation
@useResult
Occurrence<bool>? leastOccurrences() {
final (int trueCount, int falseCount) = _tally();
// Both zero means the iterable was empty.
if (trueCount + falseCount == 0) {
return null;
}
// When counts are equal, false is returned (consistent behavior)
if (falseCount <= trueCount) {
return Occurrence<bool>(false, falseCount);
}
return Occurrence<bool>(true, trueCount);
}