Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyedList ¶
type KeyedList[K, V comparable] struct { // contains filtered or unexported fields }
KeyedList watches a list of values for changes.
getKey gets the unique key for the value. cmp checks if two values are equal. if equal, the old version of the value is used.
changed is called when a value is added, removed, or changed
K is the key type V is the value type
func NewKeyedList ¶
func NewKeyedList[K, V comparable]( getKey func(v V) K, cmp func(a, b V) bool, changed func(k K, v V, added, removed bool), initial []V, ) *KeyedList[K, V]
NewKeyedList constructs a new KeyedList.
func (*KeyedList[K, V]) AppendValues ¶
func (l *KeyedList[K, V]) AppendValues(vals ...V)
AppendValues appends the given values to the list, deduplicating by key.
Values that are identical to their existing values are ignored. Values that change or are added are stored.
func (*KeyedList[K, V]) GetKeys ¶
func (l *KeyedList[K, V]) GetKeys() []K
GetKeys returns the list of keys stored in the list.
func (*KeyedList[K, V]) GetValues ¶
func (l *KeyedList[K, V]) GetValues() []V
GetValues returns the list of values stored in the list.
func (*KeyedList[K, V]) RemoveKeys ¶
func (l *KeyedList[K, V]) RemoveKeys(keys ...K)
RemoveKeys removes the given keys from the list.
Ignores values that were not in the list.
func (*KeyedList[K, V]) RemoveValues ¶
func (l *KeyedList[K, V]) RemoveValues(vals ...V)
RemoveValues removes the given values from the list by key.
Ignores values that were not in the list.
func (*KeyedList[K, V]) SetValues ¶
func (l *KeyedList[K, V]) SetValues(vals ...V)
SetValues sets the list of values contained within the KeyedList.
Values that do not appear in the list are removed. Values that are identical to their existing values are ignored. Values that change or are added are stored.