isSorted method
Returns true if this collection is sorted in ascending order reactively.
compare: Optional custom comparator overriding Comparable.compareTo.
Ensures:
- Returns
trueif collection length is less than 2. - Uses
comparecomparator if provided, falling back to Comparable.compareTo.
Implementation
Bloom<bool> isSorted([int Function(E a, E b)? compare]) => computed((via) {
final source = via(bloom);
if (source.length < 2) return true;
final comp = compare ?? (a, b) => a.compareTo(b);
var iterator = source.iterator;
iterator.moveNext();
var previous = iterator.current;
while (iterator.moveNext()) {
if (comp(previous, iterator.current) > 0) return false;
previous = iterator.current;
}
return true;
});