ImmortalMap<K, V> class
An immutable collection of key/value pairs, from which you retrieve a value using its associated key.
Operations on this map never modify the original instance but instead return new instances created from mutable maps where the operations are applied to.
Internally a LinkedHashMap is used, regardless of what type of map is passed to the constructor.
Constructors
-
ImmortalMap([Map<
K, V> map = const {}]) -
Creates an ImmortalMap instance that contains all key/value pairs of
map
. - ImmortalMap.empty()
-
Creates an empty ImmortalMap.
factory
-
ImmortalMap.from(ImmortalMap<
K, V> other) -
Creates an ImmortalMap as copy of
other
.factory -
ImmortalMap.fromEntries(Iterable<
MapEntry< entries)K, V> > -
Creates an ImmortalMap instance that contains all
entries
.factory -
ImmortalMap.fromIterables(Iterable<
K> keys, Iterable<V> values) -
Creates an ImmortalMap by associating the given
keys
tovalues
.factory -
ImmortalMap.fromMap(Map<
K, V> other) -
Creates an ImmortalMap containing all entries of
other
.factory -
ImmortalMap.fromPairs(Iterable<
Tuple2< pairs)K, V> > -
Creates an ImmortalMap instance that contains all
pairs
as entries.factory -
ImmortalMap.of(ImmortalMap<
K, V> other) -
Creates an ImmortalMap as copy of
other
.factory -
ImmortalMap.ofMap(Map<
K, V> other) -
Creates an ImmortalMap instance that contains all key/value pairs of
other
.factory
Properties
-
entries
→ ImmortalList<
MapEntry< K, V> > -
Returns an ImmortalList containing the entries of this map.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEmpty → bool
-
Returns
true
if there is no key/value pair in the map.no setter - isNotEmpty → bool
-
Returns
true
if there is at least one key/value pair in the map.no setter -
keys
→ ImmortalSet<
K> -
Returns an ImmortalSet containing the keys of this map.
no setter
- length → int
-
The number of key/value pairs in the map.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
single
→ Optional<
MapEntry< K, V> > -
Returns an
Optional
containing the only entry of this map if it has exactly one key/value pair, otherwise returnsOptional.empty
.no setter -
singleKey
→ Optional<
K> -
Returns an
Optional
containing the only key in this map if it has exactly one key/value pair, otherwise returnsOptional.empty
.no setter -
singleValue
→ Optional<
V> -
Returns an
Optional
containing the only value in this map if it has exactly one key/value pair, otherwise returnsOptional.empty
.no setter -
values
→ ImmortalList<
V> -
Returns an ImmortalList containing the values of this map.
no setter
Methods
-
add(
K key, V value) → ImmortalMap< K, V> -
Returns a copy of this map where the value of
key
is set tovalue
. -
addAll(
ImmortalMap< K, V> other) → ImmortalMap<K, V> -
Returns a copy of this map where all key/value pairs of
other
are added. -
addEntries(
Iterable< MapEntry< entries) → ImmortalMap<K, V> >K, V> -
Returns a copy of this map where all key/value pairs of
entries
are added. -
addEntry(
MapEntry< K, V> entry) → ImmortalMap<K, V> -
Returns a copy of this map where the key/value pair
entry
is added. -
addEntryIfAbsent(
MapEntry< K, V> entry) → ImmortalMap<K, V> -
Returns a copy of this map where the key/value pair
entry
is added if no entry forentry.key
is already present. -
addIfAbsent(
K key, V ifAbsent()) → ImmortalMap< K, V> -
Returns a copy of this map setting the value of
key
if it isn't there. -
addMap(
Map< K, V> other) → ImmortalMap<K, V> -
Returns a copy of this map where all key/value pairs of
other
are added. -
addPair(
Tuple2< K, V> pair) → ImmortalMap<K, V> -
Returns a copy of this map where the elements of
pair
are added as a new map entry. -
addPairs(
Iterable< Tuple2< pairs) → ImmortalMap<K, V> >K, V> -
Returns a copy of this map where all elements of
pairs
are added as new map entries. -
any(
bool predicate(K key, V value)) → bool -
Checks whether any entry in this map satisfies the given
predicate
. -
anyKey(
bool predicate(K key)) → bool -
Checks whether any key of this map satisfies the given
predicate
. -
anyValue(
bool predicate(V value)) → bool -
Checks whether any value in this map satisfies the given
predicate
. -
cast<
K2, V2> () → ImmortalMap< K2, V2> -
Returns a copy of this map casting all keys to instances of
K2
and all values to instances ofV2
. -
containsKey(
Object? key) → bool -
Returns
true
if this map contains the givenkey
. -
containsValue(
Object? value) → bool -
Returns
true
if this map contains the givenvalue
. -
copy(
) → ImmortalMap< K, V> - Returns a copy of this map.
-
equals(
dynamic other) → bool -
Checks whether this map is equal to
other
. -
every(
bool predicate(K key, V value)) → bool -
Checks whether every entry in this map satisfies the given
predicate
. -
everyKey(
bool predicate(K key)) → bool -
Checks whether every key of this map satisfies the given
predicate
. -
everyValue(
bool predicate(V value)) → bool -
Checks whether every value in this map satisfies the given
predicate
. -
filter(
bool predicate(K key, V value)) → ImmortalMap< K, V> -
Returns a copy of this map containing all entries that satisfy the given
predicate
. -
filterKeys(
bool predicate(K key)) → ImmortalMap< K, V> -
Returns a copy of this map containing all entries with keys that satisfy
the given
predicate
. -
filterValues(
bool predicate(V value)) → ImmortalMap< K, V> -
Returns a copy of this map containing all entries with values that satisfy
the given
predicate
. -
flatten<
K2, V2> () → ImmortalMap< K2, V2> - Flattens a map of ImmortalMaps by building a new map from the nested map entries.
-
flattenMaps<
K2, V2> () → ImmortalMap< K2, V2> - Flattens a map of mutable maps by building a new map from the nested map entries.
-
forEach(
void f(K key, V value)) → void -
Applies
f
to each key/value pair of the map. -
get(
Object? key) → Optional< V> -
Returns an
Optional
containing the value for the givenkey
orOptional.empty
ifkey
is not in the map. -
getKeysForValue(
Object? value) → ImmortalSet< K> -
Returns an ImmortalSet of all keys with a value equal to the given
value
according to the==
operator. -
keysForValue(
Object? value) → ImmortalSet< K> -
Returns an ImmortalSet of all keys with a value equal to the given
value
according to the==
operator. -
keysWhere(
bool predicate(K key, V value)) → ImmortalSet< K> -
Returns an ImmortalSet containing the keys of all entries in this map
that fulfill the given
predicate
. -
lookup(
Object? key) → Optional< V> -
Returns an
Optional
containing the value for the givenkey
orOptional.empty
ifkey
is not in the map. -
lookupKeysForValue(
Object? lookupValue) → ImmortalSet< K> -
Returns an ImmortalSet of all keys with a value equal to the given
lookupValue
according to the==
operator. -
map<
K2, V2> (MapEntry< K2, V2> f(K key, V value)) → ImmortalMap<K2, V2> -
Returns a new map where all entries of this map are transformed by the
given
f
function. -
mapEntries<
R> (R f(K key, V value)) → ImmortalList< R> -
Returns an ImmortalList with elements that are created by calling
f
on each entry in the map. -
mapKeys<
K2> (K2 f(K key, V value)) → ImmortalMap< K2, V> -
Returns a new map where all keys of this map are transformed by the given
f
function in respect to their values. -
mapValues<
V2> (V2 f(K key, V value)) → ImmortalMap< K, V2> -
Returns a new map where all values of this map are transformed by
the given
f
function in respect of their keys. -
merge(
ImmortalMap< K, V> other) → ImmortalMap<K, V> -
Returns a copy of this map where all key/value pairs of
other
are added and merged with existing values if possible. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pairs(
) → ImmortalList< Tuple2< K, V> > - Returns an ImmortalList containing the entries of this map as tuples of key and value.
-
put(
K key, V value) → ImmortalMap< K, V> -
Returns a copy of this map where the value of
key
is set tovalue
. -
putEntryIfAbsent(
MapEntry< K, V> entry) → ImmortalMap<K, V> -
Returns a copy of this map where the key/value pair
entry
is added if no entry forentry.key
is already present. -
putIfAbsent(
K key, V ifAbsent()) → ImmortalMap< K, V> -
Returns a copy of this map setting the value of
key
if it isn't there. -
putWhere(
bool predicate(K key, V value), V newValue) → ImmortalMap< K, V> -
Returns a copy of this map replacing the values of all key/value pairs
fulfilling the given
predicate
withnewValue
. -
remove(
Object? key) → ImmortalMap< K, V> -
Returns a copy of this map where
key
and its associated value are removed if present. -
removeAll(
ImmortalSet< Object?> keysToRemove) → ImmortalMap<K, V> -
Returns a copy of this map where all keys and their associated values
contained in
keysToRemove
are removed from. -
removeIterable(
Iterable< Object?> keysToRemove) → ImmortalMap<K, V> -
Returns a copy of this map where all keys and their associated values
contained in the iterable
keysToRemove
are removed from. -
removeValue(
Object? valueToRemove) → ImmortalMap< K, V> -
Returns a copy of this map where all entries are removed that contain a
value equal to
valueToRemove
according to the==
operator. -
removeValues(
Iterable< Object?> valuesToRemove) → ImmortalMap<K, V> -
Returns a copy of this map where all entries with a value contained in
valuesToRemove
are removed from. -
removeWhere(
bool predicate(K key, V value)) → ImmortalMap< K, V> -
Returns a copy of this map where all entries that satisfy the given
predicate
are removed. -
removeWhereKey(
bool predicate(K key)) → ImmortalMap< K, V> -
Returns a copy of this map removing all entries with keys fulfilling the
given
predicate
. -
removeWhereValue(
bool predicate(V value)) → ImmortalMap< K, V> -
Returns a copy of this map removing all entries with values fulfilling
the given
predicate
. -
replace(
K key, V newValue) → ImmortalMap< K, V> -
Returns a copy of this map where the value of
key
is set tonewValue
if already present. -
replaceEntry(
K key, MapEntry< K, V> entry) → ImmortalMap<K, V> -
Returns a copy of this map where the key/value pair with
key
is replaced byentry
if already present. -
replaceKey(
K key, K newKey) → ImmortalMap< K, V> -
Returns a copy of this map where the key of the entry with
key
is replaced bynewKey
if already present. -
replaceWhere(
bool predicate(K key, V value), V value) → ImmortalMap< K, V> -
Returns a copy of this map replacing the values of all key/value pairs
fulfilling the given
predicate
withvalue
. -
set(
K key, V value) → ImmortalMap< K, V> -
Returns a copy of this map where the value of
key
is set tovalue
. -
setEntry(
MapEntry< K, V> entry) → ImmortalMap<K, V> -
Returns a copy of this map where the key/value pair
entry
is added. -
setEntryIfAbsent(
MapEntry< K, V> entry) → ImmortalMap<K, V> -
Returns a copy of this map where the key/value pair
entry
is added if no entry forentry.key
is already present. -
setIfAbsent(
K key, V ifAbsent()) → ImmortalMap< K, V> -
Returns a copy of this map setting the value of
key
if it isn't there. -
setWhere(
bool predicate(K key, V value), V value) → ImmortalMap< K, V> -
Returns a copy of this map replacing the values of all key/value pairs
fulfilling the given
predicate
withvalue
. -
singleKeyWhere(
bool predicate(K key, V value)) → Optional< K> -
Returns an
Optional
containing the key of only entry in this map that fulfills the givenpredicate
if there is exactly one entry fulfilling this condition, otherwise returnsOptional.empty
. -
singleValueWhere(
bool predicate(K key, V value)) → Optional< V> -
Returns an
Optional
containing the value of only entry in this map that fulfills the givenpredicate
if there is exactly one entry fulfilling this condition, otherwise returnsOptional.empty
. -
singleWhere(
bool predicate(K key, V value)) → Optional< MapEntry< K, V> > -
Returns an
Optional
containing the only entry in this map that fulfills the givenpredicate
if there is exactly one entry fulfilling this condition, otherwise returnsOptional.empty
. -
toMap(
) → Map< K, V> - Returns a mutable LinkedHashMap containing all key/value pairs of this map.
-
toString(
) → String -
A string representation of this object.
override
-
update(
K key, V update(V value), {V ifAbsent()?}) → ImmortalMap< K, V> -
Returns a copy of this map updating the value for the provided
key
. -
updateAll(
V update(K key, V value)) → ImmortalMap< K, V> - Returns a copy of this map updating all values.
-
updateEntry(
K key, MapEntry< K, V> update(V value), {MapEntry<K, V> ifAbsent()?}) → ImmortalMap<K, V> -
Returns a copy of this map updating the entry for the provided
key
. -
updateKey(
K key, K update(V value)) → ImmortalMap< K, V> -
Returns a copy of this map where the key of the entry with
key
is replaced by applyingupdate
to its value if already present. -
updateWhere(
bool predicate(K key, V value), V update(K key, V value)) → ImmortalMap< K, V> -
Returns a copy of this map invoking
update
on all key/value pairs fulfilling the givenpredicate
. -
valuesWhere(
bool predicate(K key, V value)) → ImmortalList< V> -
Returns an ImmortalList containing the values of all entries in this
map that fulfill the given
predicate
. -
where(
bool predicate(K key, V value)) → ImmortalMap< K, V> -
Returns a copy of this map containing all entries that satisfy the given
predicate
. -
whereKey(
bool predicate(K key)) → ImmortalMap< K, V> -
Returns a copy of this map containing all entries with keys that satisfy
the given
predicate
. -
whereValue(
bool predicate(V value)) → ImmortalMap< K, V> -
Returns a copy of this map containing all entries with values that satisfy
the given
predicate
.
Operators
-
operator +(
ImmortalMap< K, V> other) → ImmortalMap<K, V> -
Returns a copy of this map where all key/value pairs of
other
are added. -
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
Object? key) → Optional< V> -
Returns an
Optional
containing the value for the givenkey
orOptional.empty
ifkey
is not in the map.
Static Methods
-
castFrom<
K, V, K2, V2> (ImmortalMap< K, V> other) → ImmortalMap<K2, V2> -
Returns a copy of
other
casting all keys to instances ofK2
and all values to instances ofV2
. -
castFromMap<
K, V, K2, V2> (Map< K, V> other) → ImmortalMap<K2, V2> -
Creates an ImmortalMap from
other
by casting all keys to instances ofK2
and all values to instances ofV2
. -
fromIterable<
K, V> (Iterable iterable, {K keyGenerator(dynamic value)?, V valueGenerator(dynamic value)?}) → ImmortalMap< K, V> -
Creates an ImmortalMap by computing the keys and values from
iterable
.