Dart DocumentationpersistentPersistentMapBase<K, V>

PersistentMapBase<K, V> abstract class

A base class for implementations of PersistentMap.

abstract class PersistentMapBase<K, V> implements PersistentMap<K, V> {
 Map<K, V> toMap() {
   Map<K, V> result = new Map<K, V>();
   this.forEach((K k, V v) { result[k] = v; });
   return result;
 }

 String toString() {
   StringBuffer buffer = new StringBuffer('{');
   bool comma = false;
   this.forEach((K k, V v) {
     if (comma) buffer.add(', ');
     buffer.add('$k: $v');
     comma = true;
   });
   buffer.add('}');
   return buffer.toString();
 }
}

Implements

PersistentMap<K, V>

Properties

final bool isEmpty #

inherited from PersistentMap

True when this is empty.

bool get isEmpty;

final int length #

inherited from PersistentMap

The number of (key, value) pairs in this.

{}.length == 0
{'a': 1}.length == 1
{'a': 1, 'b': 2}.length == 2
int get length;

Methods

abstract PersistentMap<K, V> adjust(K key, V update(V value)) #

inherited from PersistentMap

Returns a new map identical to this except that the value it possibly binds to key has been adjusted by update.

{'a': 1, 'b': 2}.adjust('b', (x) => x + 1) == {'a', 1, 'b', 3}
{'a': 1}.adjust('b', (x) => x + 1) == {'a', 1}

abstract PersistentMap<K, V> delete(K key) #

inherited from PersistentMap

Returns a new map identical to this except that it doesn't bind key anymore.

{'a': 1, 'b': 2}.delete('b') == {'a': 1}
{'a': 1}.delete('b') == {'a': 1}

abstract void forEach(f(K key, V value)) #

inherited from PersistentMap

Evaluates f(key, value) for each (key, value) pair in this.

abstract PersistentMap<K, V> insert(K key, V value, [V combine(V oldvalue, V newvalue)]) #

inherited from PersistentMap

Returns a new map identical to this except that it binds key to value.

If key was bound to some oldvalue in this, it is nevertheless bound to value in the new map. If key was bound to some oldvalue in this and if combine is provided then key it is bound to combine(oldvalue, value) in the new map.

{'a': 1}.insert('b', 2) == {'a': 1, 'b', 2}
{'a': 1, 'b': 2}.insert('b', 3) == {'a': 3, 'b', 3}
{'a': 1, 'b': 2}.insert('b', 3, (x,y) => x - y) == {'a': 3, 'b', -1}

abstract PersistentMap<K, V> intersection(PersistentMap<K, V> other, [V combine(V left, V right)]) #

inherited from PersistentMap

Returns a new map whose (key, value) pairs are the intersection of those of this and other.

The intersection is right-biased: values from other are retained. If combine is provided, the retained value for a key present in both this and other is then combine(leftvalue, rightvalue) where leftvalue is the value bound to key in this and rightvalue is the one bound to key in other.

{'a': 1}.intersection({'b': 2}) == {}
{'a': 1}.intersection({'a': 3, 'b': 2}) == {'a': 3}
{'a': 1}.intersection({'a': 3, 'b': 2}, (x,y) => x + y) == {'a': 4}

Note that intersection is commutative if and only if combine is provided and if it is commutative.

abstract Option<V> lookup(K key) #

inherited from PersistentMap

Looks up the value possibly bound to key in this. Returns Option.some(value) if it exists, Option.none() otherwise.

{'a': 1}.lookup('b') == Option.none()
{'a': 1, 'b': 2}.lookup('b') == Option.some(2)

abstract PersistentMap mapValues(f(V value)) #

inherited from PersistentMap

Returns a new map identical to this where each value has been updated by f.

{'a': 1, 'b': 2}.map((x) => x + 1) == {'a', 2, 'b', 3}
{}.map((x) => x + 1) == {}

Map<K, V> toMap() #

Returns a mutable copy of this.

docs inherited from PersistentMap<K, V>
Map<K, V> toMap() {
 Map<K, V> result = new Map<K, V>();
 this.forEach((K k, V v) { result[k] = v; });
 return result;
}

String toString() #

Returns a string representation of this object.

docs inherited from Object
String toString() {
 StringBuffer buffer = new StringBuffer('{');
 bool comma = false;
 this.forEach((K k, V v) {
   if (comma) buffer.add(', ');
   buffer.add('$k: $v');
   comma = true;
 });
 buffer.add('}');
 return buffer.toString();
}

abstract PersistentMap<K, V> union(PersistentMap<K, V> other, [V combine(V left, V right)]) #

inherited from PersistentMap

Returns a new map whose (key, value) pairs are the union of those of this and other.

The union is right-biased: if a key is present in both this and other, the value from other is retained. If combine is provided, the retained value for a key present in both this and other is then combine(leftvalue, rightvalue) where leftvalue is the value bound to key in this and rightvalue is the one bound to key in other.

{'a': 1}.union({'b': 2}) == {'a': 1, 'b': 2}
{'a': 1}.union({'a': 3, 'b': 2}) == {'a': 3, 'b': 2}
{'a': 1}.union({'a': 3, 'b': 2}, (x,y) => x + y) == {'a': 4, 'b': 2}

Note that union is commutative if and only if combine is provided and if it is commutative.