Dart DocumentationpersistentPersistentSet<E>

PersistentSet<E> abstract class

abstract class PersistentSet<E> implements Iterable<E> {

 /// Creates an empty [PersistentSet] using its default implementation.
 factory PersistentSet() => new _PersistentSetImpl<E>();

 /**
  * Creates an immutable copy of [elements] using the default implementation
  * of [PersistentSet].
  */
 factory PersistentSet.from(Iterable<E> elements) {
   PersistentSet<E> result = new _PersistentSetImpl<E>();
   for (E element in elements) {
     result = result.insert(element);
   }
   return result;
 }

 PersistentSet<E> insert(E element);

 PersistentSet<E> delete(E element);

 PersistentSet<E> union(PersistentSet<E> persistentSet);

 /// Alias for [union].
 PersistentSet<E> operator +(PersistentSet<E> persistentSet);

 PersistentSet<E> difference(PersistentSet<E> persistentSet);

 /// Alias for [difference].
 PersistentSet<E> operator -(PersistentSet<E> persistentSet);

 PersistentSet<Pair> cartesianProduct(PersistentSet persistentSet);

 /// Alias for [cartesianProduct].
 PersistentSet<Pair> operator *(PersistentSet persistentSet);

 PersistentSet<E> intersection(PersistentSet<E> persistentSet);

 /// Randomly picks an element of [this].
 E pickRandomElement([Random random]);
}

Subclasses

PersistentSetBase<E>

Implements

Iterable<E>

Constructors

factory PersistentSet() #

Creates an empty PersistentSet using its default implementation.

factory PersistentSet() => new _PersistentSetImpl<E>();

factory PersistentSet.from(Iterable<E> elements) #

Creates an immutable copy of elements using the default implementation of PersistentSet.

factory PersistentSet.from(Iterable<E> elements) {
 PersistentSet<E> result = new _PersistentSetImpl<E>();
 for (E element in elements) {
   result = result.insert(element);
 }
 return result;
}

Properties

final E first #

inherited from Iterable

Returns the first element.

If this is empty throws a StateError. Otherwise this method is equivalent to this.elementAt(0)

E get first;

final bool isEmpty #

inherited from Iterable

Returns true if there is no element in this collection.

bool get isEmpty;

final bool isNotEmpty #

inherited from Iterable

Returns true if there is at least one element in this collection.

bool get isNotEmpty;

final Iterator<E> iterator #

inherited from Iterable

Returns an Iterator that iterates over this Iterable object.

Iterator<E> get iterator;

final E last #

inherited from Iterable

Returns the last element.

If this is empty throws a StateError.

E get last;

final int length #

inherited from Iterable

Returns the number of elements in this.

Counting all elements may be involve running through all elements and can therefore be slow.

int get length;

final E single #

inherited from Iterable

Returns the single element in this.

If this is empty or has more than one element throws a StateError.

E get single;

Operators

abstract PersistentSet<E> operator +(PersistentSet<E> persistentSet) #

Alias for union.

abstract PersistentSet<E> operator -(PersistentSet<E> persistentSet) #

Alias for difference.

abstract PersistentSet<Pair> operator *(PersistentSet persistentSet) #

Alias for cartesianProduct.

Methods

abstract bool any(bool test(E element)) #

inherited from Iterable

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

abstract PersistentSet<Pair> cartesianProduct(PersistentSet persistentSet) #

abstract bool contains(Object element) #

inherited from Iterable

Returns true if the collection contains an element equal to element.

abstract PersistentSet<E> delete(E element) #

abstract PersistentSet<E> difference(PersistentSet<E> persistentSet) #

abstract E elementAt(int index) #

inherited from Iterable

Returns the indexth element.

If this has fewer than index elements throws a RangeError.

Note: if this does not have a deterministic iteration order then the function may simply return any element without any iteration if there are at least index elements in this.

abstract bool every(bool test(E element)) #

inherited from Iterable

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

abstract Iterable expand(Iterable f(E element)) #

inherited from Iterable

Expands each element of this Iterable into zero or more elements.

The resulting Iterable runs through the elements returned by f for each element of this, in order.

The returned Iterable is lazy, and calls f for each element of this every time it's iterated.

abstract E firstWhere(bool test(E element), {E orElse()}) #

inherited from Iterable

Returns the first element that satisfies the given predicate test.

If none matches, the result of invoking the orElse function is returned. By default, when orElse is null, a StateError is thrown.

abstract dynamic fold(initialValue, combine(previousValue, E element)) #

inherited from Iterable

Reduces 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 an iterable:

iterable.fold(0, (prev, element) => prev + element);

abstract void forEach(void f(E element)) #

inherited from Iterable

Applies the function f to each element of this collection.

abstract PersistentSet<E> insert(E element) #

abstract PersistentSet<E> intersection(PersistentSet<E> persistentSet) #

String join([String separator = ""]) #

inherited from Iterable

Converts each element to a String and concatenates the strings.

Converts each element to a String by calling Object.toString on it. Then concatenates the strings, optionally separated by the separator string.

String join([String separator = ""]) {
 StringBuffer buffer = new StringBuffer();
 buffer.writeAll(this, separator);
 return buffer.toString();
}

abstract E lastWhere(bool test(E element), {E orElse()}) #

inherited from Iterable

Returns the last element that satisfies the given predicate test.

If none matches, the result of invoking the orElse function is returned. By default, when orElse is null, a StateError is thrown.

abstract Iterable map(f(E element)) #

inherited from Iterable

Returns a lazy Iterable where each element e of this is replaced by the result of f(e).

This method returns a view of the mapped elements. As long as the returned Iterable is not iterated over, the supplied function f will not be invoked. The transformed elements will not be cached. Iterating multiple times over the the returned Iterable will invoke the supplied function f multiple times on the same element.

abstract E pickRandomElement([Random random]) #

Randomly picks an element of this.

abstract E reduce(E combine(E value, E element)) #

inherited from Iterable

Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.

Example of calculating the sum of an iterable:

iterable.reduce((value, element) => value + element);

abstract E singleWhere(bool test(E element)) #

inherited from Iterable

Returns the single element that satisfies test. If no or more than one element match then a StateError is thrown.

abstract Iterable<E> skip(int n) #

inherited from Iterable

Returns an Iterable that skips the first n elements.

If this has fewer than n elements, then the resulting Iterable is empty.

It is an error if n is negative.

abstract Iterable<E> skipWhile(bool test(E value)) #

inherited from Iterable

Returns an Iterable that skips elements while test is satisfied.

The filtering happens lazily. Every new Iterator of the returned Iterable iterates over all elements of this.

As long as the iterator's elements satisfy test they are discarded. Once an element does not satisfy the test the iterator stops testing and uses every later element unconditionally. That is, the elements of the returned Iterable are the elements of this starting from the first element that does not satisfy test.

abstract Iterable<E> take(int n) #

inherited from Iterable

Returns an Iterable with at most n elements.

The returned Iterable may contain fewer than n elements, if this contains fewer than n elements.

It is an error if n is negative.

abstract Iterable<E> takeWhile(bool test(E value)) #

inherited from Iterable

Returns an Iterable that stops once test is not satisfied anymore.

The filtering happens lazily. Every new Iterator of the returned Iterable starts iterating over the elements of this.

When the iterator encounters an element e that does not satisfy test, it discards e and moves into the finished state. That is, it does not get or provide any more elements.

abstract List<E> toList({bool growable: true}) #

inherited from Iterable

Creates a List containing the elements of this Iterable.

The elements are in iteration order. The list is fixed-length if growable is false.

abstract Set<E> toSet() #

inherited from Iterable

Creates a Set containing the elements of this Iterable.

abstract PersistentSet<E> union(PersistentSet<E> persistentSet) #

abstract Iterable<E> where(bool test(E element)) #

inherited from Iterable

Returns a lazy Iterable with all elements that satisfy the predicate test.

This method returns a view of the mapped elements. As long as the returned Iterable is not iterated over, the supplied function test will not be invoked. Iterating will not cache results, and thus iterating multiple times over the returned Iterable will invoke the supplied function test multiple times on the same element.