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