Dart API Referencedart:coreSet<E>

Set<E> abstract class

This class is the public interface of a set. A set is a collection without duplicates.

abstract class Set<E> extends Collection<E> {
  factory Set() => new HashSetImplementation<E>();

  /**
   * Creates a [Set] that contains all elements of [other].
   */
  factory Set.from(Iterable<E> other) {
    return new HashSetImplementation<E>.from(other);
  }

  /**
   * Returns true if [value] is in the set.
   */
  bool contains(E value);

  /**
   * Adds [value] into the set. The method has no effect if
   * [value] was already in the set.
   */
  void add(E value);

  /**
   * Removes [value] from the set. Returns true if [value] was
   * in the set. Returns false otherwise. The method has no effect
   * if [value] value was not in the set.
   */
  bool remove(E value);

  /**
   * Adds all the elements of the given collection to the set.
   */
  void addAll(Collection<E> collection);

  /**
   * Removes all the elements of the given collection from the set.
   */
  void removeAll(Collection<E> collection);

  /**
   * Returns true if [collection] contains all the elements of this
   * collection.
   */
  bool isSubsetOf(Collection<E> collection);

  /**
   * Returns true if this collection contains all the elements of
   * [collection].
   */
  bool containsAll(Collection<E> collection);

  /**
   * Returns a new set which is the intersection between this set and
   * the given collection.
   */
  Set<E> intersection(Collection<E> other);

  /**
   * Removes all elements in the set.
   */
  void clear();

}

Extends

Iterable<E> > Collection<E> > Set<E>

Subclasses

CSSClassSet, HashSet<E>

Constructors

factory Set() #

factory Set() => new HashSetImplementation<E>();

factory Set.from(Iterable<E> other) #

Creates a Set that contains all elements of other.

factory Set.from(Iterable<E> other) {
  return new HashSetImplementation<E>.from(other);
}

Properties

final int length #

inherited from Collection

Returns the number of elements in this collection.

int get length;

Methods

void add(E value) #

Adds value into the set. The method has no effect if value was already in the set.

void add(E value);

void addAll(Collection<E> collection) #

Adds all the elements of the given collection to the set.

void addAll(Collection<E> collection);

void clear() #

Removes all elements in the set.

void clear();

bool contains(E value) #

Returns true if value is in the set.

bool contains(E value);

bool containsAll(Collection<E> collection) #

Returns true if this collection contains all the elements of collection.

bool containsAll(Collection<E> collection);

bool every(bool f(E element)) #

inherited from Collection

Returns true if every elements of this collection satisify the predicate f. Returns false otherwise.

bool every(bool f(E element)) {
  for (E element in this) {
    if (!f(element)) return false;
  }
  return true;
}

Collection<E> filter(bool f(E element)) #

inherited from Collection

Returns a collection with the elements of this collection that satisfy the predicate f.

The returned collection should be of the same type as the collection creating it.

An element satisfies the predicate f if f(element) returns true.

Collection<E> filter(bool f(E element));

void forEach(void f(E element)) #

inherited from Collection

Applies the function f to each element of this collection.

void forEach(void f(E element)) {
  for (E element in this) f(element);
}

Set<E> intersection(Collection<E> other) #

Returns a new set which is the intersection between this set and the given collection.

Set<E> intersection(Collection<E> other);

bool isEmpty() #

inherited from Collection

Returns true if there is no element in this collection.

bool isEmpty() => !iterator().hasNext();

bool isSubsetOf(Collection<E> collection) #

Returns true if collection contains all the elements of this collection.

bool isSubsetOf(Collection<E> collection);

Iterator<E> iterator() #

inherited from Iterable

Returns an Iterator that iterates over this Iterable object.

Iterator<E> iterator();

Collection map(f(E element)) #

inherited from Collection

Returns a new collection with the elements f(e) for each element e of this collection.

Subclasses of Collection should implement the map method to return a collection of the same general type as themselves. E.g., List.map should return a List.

Collection map(f(E element));

reduce(initialValue, combine(previousValue, E element)) #

inherited from Collection

Reduce a collection to a single value by iteratively combining each element of the collection with an existing value using the provided function. Use initialValue as the initial value, and the function combine to create a new value from the previous one and an element.

Example of calculating the sum of a collection:

collection.reduce(0, (prev, element) => prev + element);

Dynamic reduce(var initialValue,
               Dynamic combine(var previousValue, E element)) {
  var value = initialValue;
  for (E element in this) value = combine(value, element);
  return value;
}

bool remove(E value) #

Removes value from the set. Returns true if value was in the set. Returns false otherwise. The method has no effect if value value was not in the set.

bool remove(E value);

void removeAll(Collection<E> collection) #

Removes all the elements of the given collection from the set.

void removeAll(Collection<E> collection);

bool some(bool f(E element)) #

inherited from Collection

Returns true if one element of this collection satisfies the predicate f. Returns false otherwise.

bool some(bool f(E element)) {
  for (E element in this) {
    if (f(element)) return true;
  }
  return false;
}