unique

package
v1.12.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2024 License: MIT Imports: 1 Imported by: 1

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(k K, 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.

type KeyedMap

type KeyedMap[K, V comparable] struct {
	// contains filtered or unexported fields
}

KeyedMap watches a map of values for changes.

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 NewKeyedMap

func NewKeyedMap[K, V comparable](
	cmp func(k K, a, b V) bool,
	changed func(k K, v V, added, removed bool),
	initial map[K]V,
) *KeyedMap[K, V]

NewKeyedMap constructs a new KeyedMap.

func (*KeyedMap[K, V]) AppendValues

func (l *KeyedMap[K, V]) AppendValues(vals map[K]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 (*KeyedMap[K, V]) GetKeys

func (l *KeyedMap[K, V]) GetKeys() []K

GetKeys returns the list of keys stored in the map.

func (*KeyedMap[K, V]) GetValues

func (l *KeyedMap[K, V]) GetValues() []V

GetValues returns the list of values stored in the map.

func (*KeyedMap[K, V]) RemoveKeys

func (l *KeyedMap[K, V]) RemoveKeys(keys ...K)

RemoveKeys removes the given keys from the list.

Ignores values that were not in the list.

func (*KeyedMap[K, V]) SetValues

func (l *KeyedMap[K, V]) SetValues(vals map[K]V)

SetValues sets the list of values contained within the KeyedMap.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL