DelegatingSet<E> class
Creates a Set that delegates all operations to a base set.
This class can be used hide non-Set
methods of a set object,
or it can be extended to add extra functionality on top of an existing
set object.
class DelegatingSet<E> extends DelegatingIterable<E> implements Set<E> { DelegatingSet(Set<E> base) : super(base); Set<E> get _setBase => _base; bool add(E value) => _setBase.add(value); void addAll(Iterable<E> elements) { _setBase.addAll(elements); } void clear() { _setBase.clear(); } bool containsAll(Iterable<Object> other) => _setBase.containsAll(other); Set<E> difference(Set<E> other) => _setBase.difference(other); Set<E> intersection(Set<Object> other) => _setBase.intersection(other); E lookup(E element) => _setBase.lookup(element); bool remove(Object value) => _setBase.remove(value); void removeAll(Iterable<Object> elements) { _setBase.removeAll(elements); } void removeWhere(bool test(E element)) { _setBase.removeWhere(test); } void retainAll(Iterable<Object> elements) { _setBase.retainAll(elements); } void retainWhere(bool test(E element)) { _setBase.retainWhere(test); } Set<E> union(Set<E> other) => _setBase.union(other); }
Extends
DelegatingIterable<E> > DelegatingSet<E>
Implements
Constructors
new DelegatingSet(Set<E> base) #
Create a wrapper that forwards operations to base.
DelegatingSet(Set<E> base) : super(base);
Properties
final E first #
Returns the first element.
If this
is empty throws a StateError. Otherwise this method is
equivalent to this.elementAt(0)
E get first => _base.first;
final bool isEmpty #
final bool isNotEmpty #
final Iterator<E> iterator #
final int length #
final E single #
Returns the single element in this
.
If this
is empty or has more than one element throws a StateError.
E get single => _base.single;
Methods
bool any(bool test(E element)) #
void clear() #
bool contains(Object element) #
E elementAt(int index) #
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
.
E elementAt(int index) => _base.elementAt(index);
bool every(bool test(E element)) #
Iterable expand(Iterable f(E element)) #
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.
Iterable expand(Iterable f(E element)) => _base.expand(f);
E firstWhere(bool test(E element), {E orElse()}) #
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.
E firstWhere(bool test(E element), {E orElse()}) => _base.firstWhere(test, orElse: orElse);
dynamic fold(initialValue, combine(previousValue, E element)) #
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);
fold(initialValue, combine(previousValue, E element)) => _base.fold(initialValue, combine);
void forEach(void f(E element)) #
String join([String separator = ""]) #
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 = ""]) => _base.join(separator);
E lastWhere(bool test(E element), {E orElse()}) #
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.
E lastWhere(bool test(E element), {E orElse()}) => _base.lastWhere(test, orElse: orElse);
Iterable map(f(E element)) #
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.
Iterable map(f(E element)) => _base.map(f);
E reduce(E combine(E value, E element)) #
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);
E reduce(E combine(E value, E element)) => _base.reduce(combine);
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.
void retainAll(Iterable<Object> elements) { _setBase.retainAll(elements); }
E singleWhere(bool test(E element)) #
Returns the single element that satisfies test. If no or more than one element match then a StateError is thrown.
E singleWhere(bool test(E element)) => _base.singleWhere(test);
Iterable<E> skip(int n) #
Iterable<E> skipWhile(bool test(E value)) #
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.
Iterable<E> skipWhile(bool test(E value)) => _base.skipWhile(test);
Iterable<E> take(int n) #
Iterable<E> takeWhile(bool test(E value)) #
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.
Iterable<E> takeWhile(bool test(E value)) => _base.takeWhile(test);
List<E> toList({bool growable: true}) #
Set<E> toSet() #
String toString() #
Returns a string representation of (some of) the elements of this
.
Elements are represented by their own toString
results.
The representation always contains the first three elements. If there are less than a hundred elements in the iterable, it also contains the last two elements.
If the resulting string isn't above 80 characters, more elements are included from the start of the iterable.
The conversion may omit calling toString
on some elements if they
are known to now occur in the output, and it may stop iterating after
a hundred elements.
String toString() => _iterableToString(this);
Iterable<E> where(bool test(E element)) #
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.
Iterable<E> where(bool test(E element)) => _base.where(test);