W3cubDocs

/Dart 2

SplayTreeSet<E>.from constructor

SplayTreeSet<E>.from(Iterable elements, [ int compare(E key1, E key2), bool isValidKey(dynamic potentialKey) ])

Creates a SplayTreeSet that contains all elements.

The set works as if created by new SplayTreeSet<E>(compare, isValidKey).

All the elements should be instances of E and valid arguments to compare. The elements iterable itself may have any element type, so this constructor can be used to down-cast a Set, for example as:

Set<SuperType> superSet = ...;
Set<SubType> subSet =
    new SplayTreeSet<SubType>.from(superSet.whereType<SubType>());

Implementation

factory SplayTreeSet.from(Iterable elements,
    [int compare(E key1, E key2), bool isValidKey(potentialKey)]) {
  SplayTreeSet<E> result = new SplayTreeSet<E>(compare, isValidKey);
  for (final element in elements) {
    E e = element;
    result.add(e);
  }
  return result;
}

© 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/SplayTreeSet/SplayTreeSet.from.html