W3cubDocs

/Dart 2

retainAll method

void retainAll (Iterable<Object> elements)

Removes all elements of this set that are not elements in elements.

Checks for each element of elements whether there is an element in this set that is equal to it (according to this.contains), and if so, the equal element in this set is retained, and elements that are not equal to any element in elements are removed.

Implementation

void retainAll(Iterable<Object> elements) {
  // Create a copy of the set, remove all of elements from the copy,
  // then remove all remaining elements in copy from this.
  Set<E> toRemove = toSet();
  for (Object o in elements) {
    toRemove.remove(o);
  }
  removeAll(toRemove);
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-collection/SetMixin/retainAll.html