Documentation
¶
Overview ¶
Package dict contains Map functions
Index ¶
- func Clear[K comparable, V any](items map[K]V)
- func Copy[K comparable, V any](items map[K]V) map[K]V
- func CounterUpdate[T comparable](oldCounter, newCounter Counter[T])
- func Filter[K comparable, V any](items map[K]V, keep func(K, V) bool) map[K]V
- func FromStruct[V, T any](structRef *T) (map[string]V, error)
- func Get[T any](obj Object, key string) (T, bool)
- func GetList[T any](obj Object, key string) []T
- func GetOrDefault[K comparable, V any](items map[K]V, key K, defaultValue V) V
- func GetRef[T any](obj Object, key string) *T
- func GroupByFunc[K, B comparable, V, A any](items map[K]V, keyFn func(K) A, valueFn func(V) B) map[B][]A
- func GroupByFuncList[K, B comparable, V, A any](items map[K][]V, keyFn func(K) A, valueFn func(V) B) map[B][]A
- func GroupByValue[K, V comparable](items map[K]V) map[V][]K
- func GroupByValueList[K, V comparable](items map[K][]V) map[V][]K
- func HasKey[K comparable, V any](items map[K]V, key K) bool
- func HasKeyFunc[K comparable, V any](items map[K]V, test func(K) bool) bool
- func HasValue[K, V comparable](items map[K]V, value V) bool
- func HasValueFunc[K comparable, V any](items map[K]V, test func(V) bool) bool
- func IsEmpty[K comparable, V any](items map[K]V) bool
- func Keys[K comparable, V any](items map[K]V) []K
- func KeysIter[K comparable, V any](items map[K]V) iter.Seq[K]
- func Len[K comparable, V any](items map[K]V) int
- func LookupFunc[K comparable, V any](items map[K]V) func(K) (V, bool)
- func MustLookupFunc[K comparable, V any](items map[K]V) func(K) V
- func NoKey[K comparable, V any](items map[K]V, key K) bool
- func NoKeyFunc[K comparable, V any](items map[K]V, test func(K) bool) bool
- func NoValue[K, V comparable](items map[K]V, value V) bool
- func NoValueFunc[K comparable, V any](items map[K]V, test func(V) bool) bool
- func NotEmpty[K comparable, V any](items map[K]V) bool
- func SetDefault[K comparable, V any](items map[K]V, key K, defaultValue V)
- func SortValueLists[K comparable, V cmp.Ordered](items map[K][]V)
- func SortValueListsFunc[K comparable, V any](items map[K][]V, sortFn func(V, V) int)
- func SortedKeys[K cmp.Ordered, V any](items map[K]V) []K
- func SortedKeysFunc[K comparable, V any](items map[K]V, sortFn func(K, K) int) []K
- func SortedUnzip[K cmp.Ordered, V any](items map[K]V) ([]K, []V)
- func SortedValues[K comparable, V cmp.Ordered](items map[K]V) []V
- func SortedValuesFunc[K comparable, V any](items map[K]V, sortFn func(V, V) int) []V
- func Swap[K, V comparable](items map[K]V) map[V]K
- func SwapList[K, V comparable](items map[K][]V) map[V]K
- func ToStruct[T any](obj Object) (*T, error)
- func Unzip[K comparable, V any](items map[K]V) ([]K, []V)
- func Update[K comparable, V any](oldMap, newMap map[K]V)
- func UpdateCounter[T comparable](counter Counter[T], items []T)
- func UpdateCounterFunc[T any, K comparable](counter Counter[K], items []T, keyFn func(T) K)
- func Values[K comparable, V any](items map[K]V) []V
- func ValuesIter[K comparable, V any](items map[K]V) iter.Seq[V]
- func Zip[K comparable, V any](keys []K, values []V) map[K]V
- type Bools
- type Counter
- func MergeCounters[T comparable](counters ...Counter[T]) Counter[T]
- func NewCounterFor[T comparable](items []T) Counter[T]
- func NewCounterFunc[T any, K comparable](items []T, keyFn func(T) K) Counter[K]
- func TallyFunc[K, T comparable, V any](items map[K]V, valueFn func(V) T) Counter[T]
- func TallyValues[K, V comparable](items map[K]V, values []V) Counter[V]
- type Entry
- type Flags
- type Floats
- type IntCounter
- type IntFlags
- type Ints
- type Lookup
- type Object
- type StringCounter
- type StringFlags
- type StringLists
- type Strings
- type UintCounter
- type UintFlags
- type Uints
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Copy ¶
func Copy[K comparable, V any](items map[K]V) map[K]V
Copy creates a new map with copied entries
func CounterUpdate ¶
func CounterUpdate[T comparable](oldCounter, newCounter Counter[T])
CounterUpdate updates the old counter with counts from new counter
func Filter ¶
func Filter[K comparable, V any](items map[K]V, keep func(K, V) bool) map[K]V
Filter filters the map, only keeping entries that pass the keep function
func FromStruct ¶
FromStruct creates a map[string]V from given struct pointer. Struct field values must all be of the same type.
func GetOrDefault ¶
func GetOrDefault[K comparable, V any](items map[K]V, key K, defaultValue V) V
GetOrDefault gets the value associated with key if it exists, otherwise returns the default value
func GroupByFunc ¶
func GroupByFunc[K, B comparable, V, A any](items map[K]V, keyFn func(K) A, valueFn func(V) B) map[B][]A
GroupByFunc groups the map by values, using key and value transformers
func GroupByFuncList ¶
func GroupByFuncList[K, B comparable, V, A any](items map[K][]V, keyFn func(K) A, valueFn func(V) B) map[B][]A
GroupByFuncList groups the map[K][]V by values, produces map[B][]A using key and value transformers
func GroupByValue ¶
func GroupByValue[K, V comparable](items map[K]V) map[V][]K
GroupByValue groups the map by values
func GroupByValueList ¶
func GroupByValueList[K, V comparable](items map[K][]V) map[V][]K
GroupByValueList groups the map[K][]V by values, produces map[V][]K
func HasKey ¶
func HasKey[K comparable, V any](items map[K]V, key K) bool
HasKey checks if map has given key
func HasKeyFunc ¶
func HasKeyFunc[K comparable, V any](items map[K]V, test func(K) bool) bool
HasKeyFunc checks if any map key passes the test function
func HasValue ¶
func HasValue[K, V comparable](items map[K]V, value V) bool
HasValue checks if map has given value
func HasValueFunc ¶
func HasValueFunc[K comparable, V any](items map[K]V, test func(V) bool) bool
HasValueFunc checks if any map value passes the test function
func Keys ¶
func Keys[K comparable, V any](items map[K]V) []K
Keys returns map keys, in arbitrary order
func KeysIter ¶
func KeysIter[K comparable, V any](items map[K]V) iter.Seq[K]
KeysIter returns an iterator for map keys
func LookupFunc ¶
func LookupFunc[K comparable, V any](items map[K]V) func(K) (V, bool)
LookupFunc creates a converter function that returns associated value and exists flag for given key
func MustLookupFunc ¶
func MustLookupFunc[K comparable, V any](items map[K]V) func(K) V
MustLookupFunc creates a converter function that returns associated value for given key, and panics if key is not found
func NoKey ¶
func NoKey[K comparable, V any](items map[K]V, key K) bool
NoKey checks if map does not have given key
func NoKeyFunc ¶
func NoKeyFunc[K comparable, V any](items map[K]V, test func(K) bool) bool
NoKeyFunc checks that no map key passes the test function
func NoValue ¶
func NoValue[K, V comparable](items map[K]V, value V) bool
NoValue checks if map does not have given value
func NoValueFunc ¶
func NoValueFunc[K comparable, V any](items map[K]V, test func(V) bool) bool
NoValueFunc checks that no Map value passes the test function
func NotEmpty ¶
func NotEmpty[K comparable, V any](items map[K]V) bool
NotEmpty checks if map is not empty
func SetDefault ¶
func SetDefault[K comparable, V any](items map[K]V, key K, defaultValue V)
SetDefault assigns default value to key, if key is not in Map
func SortValueLists ¶
func SortValueLists[K comparable, V cmp.Ordered](items map[K][]V)
SortValueLists sorts the list of values in place, for each map key
func SortValueListsFunc ¶
func SortValueListsFunc[K comparable, V any](items map[K][]V, sortFn func(V, V) int)
SortValueListsFunc sorts the list of values in place, using the sortFn, for each map key
func SortedKeys ¶
SortedKeys returns the map keys in sorted order
func SortedKeysFunc ¶
func SortedKeysFunc[K comparable, V any](items map[K]V, sortFn func(K, K) int) []K
SortedKeysFunc returns the map keys in sorted order, using the sortFn
func SortedUnzip ¶
SortedUnzip returns the list of Map keys and values, where the keys are sorted and the value order corresponds to the key order
func SortedValues ¶
func SortedValues[K comparable, V cmp.Ordered](items map[K]V) []V
SortedValues returns the map values in sorted order
func SortedValuesFunc ¶
func SortedValuesFunc[K comparable, V any](items map[K]V, sortFn func(V, V) int) []V
SortedValuesFunc returns the map values in sorted order, using the sortFn
func Swap ¶
func Swap[K, V comparable](items map[K]V) map[V]K
Swap swaps the map keys and values, converting map[K]V to map[V]K. This can lose data if values are not unique
func SwapList ¶
func SwapList[K, V comparable](items map[K][]V) map[V]K
SwapList converts the map[K][]V to map[V]K. This can lose data if values are not unique
func Unzip ¶
func Unzip[K comparable, V any](items map[K]V) ([]K, []V)
Unzip returns the list of Map keys and values, where the order of keys is the same as corresponding values
func Update ¶
func Update[K comparable, V any](oldMap, newMap map[K]V)
Update adds the entries of new Map to current Map. If there are overlapping keys, new Map entries overwrite the old Map entries.
func UpdateCounter ¶
func UpdateCounter[T comparable](counter Counter[T], items []T)
UpdateCounter updates the counter with incoming items
func UpdateCounterFunc ¶
func UpdateCounterFunc[T any, K comparable](counter Counter[K], items []T, keyFn func(T) K)
UpdateCounterFunc updates the counter with incoming items, using the keyFn
func Values ¶
func Values[K comparable, V any](items map[K]V) []V
Values returns map values, in arbitrary order
func ValuesIter ¶
func ValuesIter[K comparable, V any](items map[K]V) iter.Seq[V]
ValuesIter returns an iterator for map values
func Zip ¶
func Zip[K comparable, V any](keys []K, values []V) map[K]V
Zip creates a new map by zipping the keys and values
Types ¶
type Counter ¶
type Counter[T comparable] = map[T]int
func MergeCounters ¶
func MergeCounters[T comparable](counters ...Counter[T]) Counter[T]
MergeCounters merges the counts from given counters into one Counter
func NewCounterFor ¶
func NewCounterFor[T comparable](items []T) Counter[T]
NewCounterFor creates a new counter, with each item initialized to count = 0
func NewCounterFunc ¶
func NewCounterFunc[T any, K comparable](items []T, keyFn func(T) K) Counter[K]
NewCounterFunc creates a new counter, using the keys produced from keyFn
func TallyFunc ¶
func TallyFunc[K, T comparable, V any](items map[K]V, valueFn func(V) T) Counter[T]
TallyFunc creates a tally of how many times a transformed value appears in the map, using value transformer
func TallyValues ¶
func TallyValues[K, V comparable](items map[K]V, values []V) Counter[V]
TallyValues creates a tally of how many times each value appears in the map
type Entry ¶
type Entry[K comparable, V any] struct { Key K Value V }
Entry represents a map Key-Value pair
func Entries ¶
func Entries[K comparable, V any](items map[K]V) []Entry[K, V]
Entries returns map entries, in arbitrary order
func SortedEntries ¶
SortedEntries returns the map entries in sorted key order
func SortedEntriesFunc ¶
func SortedEntriesFunc[K comparable, V any](items map[K]V, sortFn func(Entry[K, V], Entry[K, V]) int) []Entry[K, V]
SortedEntriesFunc returns the map entries in sorted order, using the sortFn
type Flags ¶
type Flags[T comparable] = map[T]bool
func NewFlagsFor ¶
func NewFlagsFor[T comparable](items []T, flag bool) Flags[T]
NewFlagsFor creates a new Flags map, with each item initialized to given flag
func NewFlagsFunc ¶
func NewFlagsFunc[T any, K comparable](items []T, flag bool, keyFn func(T) K) Flags[K]
NewFlagsFunc creates a new Flags map, using the keyFn, with each key initialized to given flag
type IntCounter ¶
type Lookup ¶
type Lookup[K comparable, V any] = map[K]V