ImmortalSet<T> class
An immutable collection of objects in which each object can occur only once
according to the ==
operator.
Operations on this set never modify the original instance but instead return new instances created from mutable sets where the operations are applied to.
Internally a LinkedHashSet is used, regardless of what type of set is passed to the constructor. Even though this implementation might implement Iterable and provide a certain guarantee for the order of the elements contained, it is discouraged to rely on any order of elements in ImmortalSet.
Constructors
-
ImmortalSet([Iterable<
T> iterable = const []]) -
Creates an ImmortalSet that contains all elements of
iterable
. - ImmortalSet.empty()
-
Creates an empty ImmortalSet.
factory
-
ImmortalSet.from(ImmortalSet<
T> other) -
Creates an ImmortalSet as copy of
other
.factory -
ImmortalSet.fromIterable(Iterable<
T> iterable) -
Creates an ImmortalSet that contains all elements of
iterable
.factory -
ImmortalSet.of(ImmortalSet<
T> other) -
Creates an ImmortalSet as copy of
other
.factory -
ImmortalSet.ofIterable(Iterable<
T> iterable) -
Creates an ImmortalSet that contains all elements of
iterable
.factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEmpty → bool
-
Returns
true
if there are no elements in this collection.no setter - isNotEmpty → bool
-
Returns
true
if there is at least one element in this collection.no setter -
iterator
→ Iterator<
T> -
Provides an iterator that iterates over the elements of this set.
no setter
- length → int
-
Returns the number of elements in this set.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
single
→ Optional<
T> -
Returns an
Optional
containing the only element of the set if it has exactly one element, otherwise returnsOptional.empty
.no setter
Methods
-
add(
T value) → ImmortalSet< T> -
Returns a copy of this set where
value
is added to. -
addAll(
ImmortalSet< T> other) → ImmortalSet<T> -
Returns a copy of this set where all elements of
other
are added. -
addIterable(
Iterable< T> iterable) → ImmortalSet<T> -
Returns a copy of this set where all elements of
iterable
are added. -
addOrReplaceWhere(
bool predicate(T value), T value) → ImmortalSet< T> -
Returns a copy of this set replacing each element that fulfills the given
predicate
byvalue
, or addsvalue
to the set if no element satisfyingpredicate
was found. -
addOrUpdateWhere(
bool predicate(T value), T update(T value), T ifAbsent()) → ImmortalSet< T> -
Returns a copy of this set by applying
update
on each element that fulfills the givenpredicate
, or adds the result ofifAbsent
to the set if no element satisfyingpredicate
was found. -
any(
bool predicate(T value)) → bool -
Checks whether any element of this set satisfies the given
predicate
. -
asMapWithKeys<
K> (K keyGenerator(T value)) → ImmortalMap< K, T> -
Returns an ImmortalMap using the given
keyGenerator
. -
cast<
R> () → ImmortalSet< R> -
Returns a copy of this set casting all elements to instances of
R
. -
contains(
Object? element) → bool -
Returns
true
ifelement
is in the set according to the==
operator. -
containsAll(
ImmortalSet< Object?> other) → bool -
Returns whether this set contains all the elements of
other
. -
containsIterable(
Iterable< Object?> iterable) → bool -
Returns whether this set contains all the elements of
iterable
. -
copy(
) → ImmortalSet< T> - Returns a copy of this set.
-
difference(
ImmortalSet< Object?> other) → ImmortalSet<T> -
Returns a new set with the elements of this set that are not in
other
. -
differenceWithSet(
Set< Object?> other) → ImmortalSet<T> -
Returns a new set with the elements of this set that are not in the set
other
. -
equals(
dynamic other) → bool -
Checks whether this set is equal to
other
. -
every(
bool predicate(T value)) → bool -
Checks whether every element of this set satisfies the given
predicate
. -
expand<
R> (ImmortalSet< R> f(T value)) → ImmortalSet<R> - Returns a new set expanding each element of this set into a set of zero or more elements.
-
expandIterable<
R> (Iterable< R> f(T value)) → ImmortalSet<R> - Returns a new set expanding each element of this set into an iterable of zero or more elements.
-
filter(
bool predicate(T value)) → ImmortalSet< T> -
Returns a new set with all elements of this set that satisfy the given
predicate
. -
filterType<
R> () → ImmortalSet< R> -
Returns a new set with all elements of this set that have type
R
. -
flatMap<
R> (ImmortalSet< R> f(T value)) → ImmortalSet<R> - Returns a new set expanding each element of this set into a set of zero or more elements.
-
flatMapIterable<
R> (Iterable< R> f(T value)) → ImmortalSet<R> - Returns a new set expanding each element of this set into an iterable of zero or more elements.
-
flatten<
R> () → ImmortalSet< R> - Flattens a set of ImmortalSets by combining their values to a single set.
-
flattenIterables<
R> () → ImmortalSet< R> - Flattens a set of iterables by combining their values to a single set.
-
fold<
R> (R initialValue, R combine(R previousResult, T value)) → R - Reduces the set to a single value by iteratively combining each element of this set with an existing value.
-
forEach(
void f(T value)) → void -
Applies the function
f
to each element of this set. -
intersection(
ImmortalSet< Object?> other) → ImmortalSet<T> -
Returns a new set which is the intersection between this set and
other
. -
intersectionWithSet(
Set< Object?> other) → ImmortalSet<T> -
Returns a new set which is the intersection between this set and the set
other
. -
join(
[String separator = '']) → String - Converts each element to a String and concatenates the strings.
-
lookup(
Object? element) → Optional< T> -
Returns an
Optional
containing an element equal toelement
if there is one in this set, otherwise returnsOptional.empty
. -
map<
R> (R f(T value)) → ImmortalSet< R> -
Returns a new set with elements that are created by calling
f
on each element of this set. -
merge(
ImmortalSet< T> other) → ImmortalSet<T> -
Returns a new set which contains all the elements of this set and
other
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
partition(
bool predicate(T value)) → Tuple2< ImmortalSet< T> , ImmortalSet<T> > -
Returns a tuple of two new sets by splitting the set into two depending on
the result of the given
predicate
. -
remove(
Object? element) → ImmortalSet< T> -
Returns a copy of this set where
element
is removed from if present, otherwise the set is returned unchanged. -
removeAll(
ImmortalSet< Object?> other) → ImmortalSet<T> -
Returns a copy of this set where each element in
other
is removed from. -
removeIterable(
Iterable< Object?> iterable) → ImmortalSet<T> -
Returns a copy of this set where each element in the
iterable
is removed from. -
removeWhere(
bool predicate(T value)) → ImmortalSet< T> -
Returns a copy of this set where all values that satisfy the given
predicate
are removed from. -
replaceWhere(
bool predicate(T value), T newValue) → ImmortalSet< T> -
Returns a copy of this list replacing each element that fulfills the given
predicate
bynewValue
. -
retainAll(
ImmortalSet< Object?> other) → ImmortalSet<T> -
Returns a copy of this set where are all elements that are not in
other
are removed from. -
retainIterable(
Iterable< Object?> iterable) → ImmortalSet<T> -
Returns a copy of this set where are all elements that are not in
iterable
are removed from. -
retainWhere(
bool predicate(T value)) → ImmortalSet< T> -
Returns a copy of this set where all values that fail to satisfy the given
predicate
are removed from. -
singleWhere(
bool predicate(T value)) → Optional< T> -
Returns an
Optional
containing the only element that satisfies the givenpredicate
if there is exactly one, otherwise returnsOptional.empty
. -
toggle(
T value) → ImmortalSet< T> -
Returns a copy of this set by toggling the presence of
value
. -
toImmortalList(
) → ImmortalList< T> - Returns an ImmortalList containing the elements of this set.
-
toList(
{bool growable = true}) → List< T> - Returns a mutable List containing the elements of this set.
-
toSet(
) → Set< T> - Returns a mutable LinkedHashSet containing the same elements as this set.
-
toString(
) → String -
A string representation of this object.
override
-
union(
ImmortalSet< T> other) → ImmortalSet<T> -
Returns a new set which contains all the elements of this set and
other
. -
unionWithSet(
Set< T> other) → ImmortalSet<T> -
Returns a new set which contains all the elements of this set and the set
other
. -
updateWhere(
bool predicate(T value), T update(T value)) → ImmortalSet< T> -
Returns a copy of this set by applying
update
to all elements that fulfill the givenpredicate
. -
where(
bool predicate(T value)) → ImmortalSet< T> -
Returns a new set with all elements of this set that satisfy the given
predicate
. -
whereType<
R> () → ImmortalSet< R> -
Returns a new set with all elements of this set that have type
R
.
Operators
-
operator &(
ImmortalSet< Object?> other) → ImmortalSet<T> -
Returns a new set which is the intersection between this set and
other
. -
operator +(
ImmortalSet< T> other) → ImmortalSet<T> -
Returns a new set which contains all the elements of this set and
other
. -
operator -(
ImmortalSet< Object?> other) → ImmortalSet<T> -
Returns a new set with the elements of this set that are not in
other
. -
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator |(
ImmortalSet< T> other) → ImmortalSet<T> -
Returns a new set which contains all the elements of this set and
other
.
Static Methods
-
castFrom<
T, R> (ImmortalSet< T> other) → ImmortalSet<R> -
Returns a copy of
other
casting all elements to instances ofR
. -
castFromIterable<
T, R> (Iterable< T> iterable) → ImmortalSet<R> -
Creates an ImmortalSet by casting all elements of
iterable
to instances ofR
.