toList method
Move the list's elements that satisfy the predicate to another List.
The ordering of elements in the returned list is the same as the list.
Contract
A ConcurrentModificationError is thrown if the predicate modifies the list.
Example
final foo = [1, 2, 3, 4, 5];
final bar = foo.move(where: (e) => e.isEven).toList();
print(foo); // [1, 3, 5]
print(bar); // [2, 4]
Implementation
@Possible({ConcurrentModificationError})
@useResult List<E> toList() {
final moved = <E>[];
collect(moved.add);
return moved;
}