partition method
Partitions elements into two lists: those that satisfy predicate and those that do not.
Returns a record (matched, unmatched) where order is preserved.
Example:
[1, 2, 3, 4].partition((x) => x.isEven); // ([2, 4], [1, 3])
Implementation
@useResult
(List<T>, List<T>) partition(ElementPredicate<T> predicate) {
final List<T> matched = <T>[];
final List<T> unmatched = <T>[];
for (final T element in this) {
if (predicate(element)) {
matched.add(element);
} else {
unmatched.add(element);
}
}
return (matched, unmatched);
}