splitAtFirstWhere method
Splits at the first element where predicate is true. That element goes in the second list.
Audited: 2026-06-12 11:26 EDT
Implementation
@useResult
(List<T>, List<T>) splitAtFirstWhere(ElementPredicate<T> predicate) {
final List<T> list = toList();
// The match position is the split point, so test each element with its index.
for (final (int i, T element) in list.indexed) {
if (predicate(element)) {
return (list.sublist(0, i), list.sublist(i));
}
}
return (list, <T>[]);
}