Documentation ¶
Index ¶
- func CamelizeKeys[K ~string, V interface{}](data map[K]V)
- func CopyBaseType[K comparable, V BaseTypes](src map[K]V) (dst map[K]V)
- func DeepCopy[V interface{}](src map[string]V) (dst map[string]V)
- func Delete(m map[string]interface{}, key string)
- func DeleteKV(c map[string]interface{}, key string) (deleted bool)
- func Dump[T comparable, V interface{}](m map[T]V) (pretty string)
- func Get(m map[string]interface{}, key string) (value interface{})
- func GetKV(c map[string]interface{}, key string) (k string, v interface{})
- func Has(m map[string]interface{}, key string) (present bool)
- func KebabKeys[K ~string, V interface{}](data map[K]V)
- func Keys[K comparable, V interface{}](data map[K]V) (keys []K)
- func MakeTypedKey[K comparable, L comparable, V interface{}, M map[L]V](m map[K]M, key K) (made bool)
- func OrderedKeys[K cmp.Ordered, V interface{}](data map[K]V) (keys []K)
- func ParseDeepKeySlice(input string) (key string, idx int, ok bool)
- func RenameKeys[K ~string, V interface{}](data map[K]V, rename func(original K) (renamed K))
- func ReverseOrderedKeys[K cmp.Ordered, V interface{}](data map[K]V) (keys []K)
- func ReverseSortedKeys[K ~string, V interface{}](data map[K]V) (keys []K)
- func ReverseSortedNumbers[K maths.Number, V interface{}](data map[K]V) (keys []K)
- func ScreamingSnakeKeys[K ~string, V interface{}](data map[K]V)
- func Set(m map[string]interface{}, key string, value interface{}) (err error)
- func SetKV(c map[string]interface{}, key string, value interface{}) (err error)
- func SnakeKeys[K ~string, V interface{}](data map[K]V)
- func SortedKeyLengths[K ~string, V interface{}](data map[K]V) (keys []K)
- func SortedKeys[K ~string, V interface{}](data map[K]V) (keys []K)
- func SortedKeysByLastName[K ~string, V interface{}](data map[K]V) (keys []K)
- func SortedNumbers[K maths.Number, V interface{}](data map[K]V) (keys []K)
- func ToEnviron[K ~string, V interface{}](data map[K]V) (environ []string)
- func ValuesSortedByKeys[K ~string, V interface{}](data map[K]V) (values []V)
- func ValuesSortedByNumbers[K maths.Number, V interface{}](data map[K]V) (values []V)
- type BaseTypes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CamelizeKeys ¶ added in v1.2.0
func CamelizeKeys[K ~string, V interface{}](data map[K]V)
CamelizeKeys is a CamelCase wrapper around RenameKeys
func CopyBaseType ¶ added in v1.2.0
func CopyBaseType[K comparable, V BaseTypes](src map[K]V) (dst map[K]V)
CopyBaseType returns a shallow copy of the given map[comparable]BaseTypes
func DeleteKV ¶ added in v1.2.0
DeleteKV uses Delete if the first character of the key is a period ("."), otherwise DeleteKV uses GetKV to find the correct key and then deletes it from the map
func Dump ¶ added in v1.2.0
func Dump[T comparable, V interface{}](m map[T]V) (pretty string)
Dump is a convenience wrapper around github.com/gookit/goutil/dump to return a human-readable representation of the given map
Only really useful during ad-hoc development cycles
func GetKV ¶ added in v1.2.0
GetKV finds the relative key given, returning both the actual key and the associated interface{} value, using the following procedure:
1. uses Get if the first character of the key is a period (".") 2. checks if the key is already an exact match 3. checks for a CamelCased version of the key 4. checks for a kebab-cased version of the key 5. checks for a snake_cased version of the key
func KebabKeys ¶ added in v1.2.0
func KebabKeys[K ~string, V interface{}](data map[K]V)
KebabKeys is a kebab-case wrapper around RenameKeys
func Keys ¶ added in v1.2.0
func Keys[K comparable, V interface{}](data map[K]V) (keys []K)
Keys returns the list of map keys, in whatever order Go produces from a simple range over the data
func MakeTypedKey ¶ added in v1.2.0
func MakeTypedKey[K comparable, L comparable, V interface{}, M map[L]V](m map[K]M, key K) (made bool)
MakeTypedKey is used to simplify the adding of more map values to a parent map without having to check if the value map exists already or needs to be created first
Example:
// Standard way m := make(map[string]map[string]struct{}) if _, present := m["top"]; !present { m["top"] = make(map[string]struct{}) } m["top"]["thing"] = struct{}{} // Using MakeTypedKey m := make(map[string]map[string]struct{}) _ = maps.MakeTypedKey(m, "top") m["top"]["thing"] = struct{}{}
func OrderedKeys ¶ added in v1.2.0
OrderedKeys returns the list of cmp.Ordered keys in ascending order
func ParseDeepKeySlice ¶ added in v1.2.0
func RenameKeys ¶ added in v1.2.0
func RenameKeys[K ~string, V interface{}](data map[K]V, rename func(original K) (renamed K))
RenameKeys ranges over the given data and calls the rename function for each key, if the renamed string is different from the original string, the renamed key is set on the data and the original key is deleted
func ReverseOrderedKeys ¶ added in v1.2.0
ReverseOrderedKeys returns the list of cmp.Ordered keys in descending order
func ReverseSortedKeys ¶ added in v1.2.0
func ReverseSortedKeys[K ~string, V interface{}](data map[K]V) (keys []K)
ReverseSortedKeys returns the list of keys in reverse natural sorted order
func ReverseSortedNumbers ¶
ReverseSortedNumbers returns a slice of descending sorted keys from the given map
func ScreamingSnakeKeys ¶ added in v1.2.0
func ScreamingSnakeKeys[K ~string, V interface{}](data map[K]V)
ScreamingSnakeKeys converts all keys to kebab-case
For each key/value pair: - if the key is already kebab-cased, does nothing - if the kebab-cased key does not exist, sets it - deletes the original, not-kebab-case key
func Set ¶ added in v1.2.0
Set checks if the key being set is a deep key and if so, sets the value deeply within the map structure. Set is a simple map value assignment for non-deep key cases
func SetKV ¶ added in v1.2.0
SetKV uses Set if the first character of the key is a period ("."), otherwise SetKV sets the map value to a CamelCased version of the key
func SnakeKeys ¶ added in v1.2.0
func SnakeKeys[K ~string, V interface{}](data map[K]V)
SnakeKeys is a snake_case wrapper around RenameKeys
func SortedKeyLengths ¶ added in v1.2.0
func SortedKeyLengths[K ~string, V interface{}](data map[K]V) (keys []K)
SortedKeyLengths returns the list of keys, from longest to shortest and natural sorted for same length keys
func SortedKeys ¶
func SortedKeys[K ~string, V interface{}](data map[K]V) (keys []K)
SortedKeys returns a slice of natural-sorted keys from the given map
func SortedKeysByLastName ¶ added in v1.2.0
func SortedKeysByLastName[K ~string, V interface{}](data map[K]V) (keys []K)
SortedKeysByLastName assumes that the keys in the map are human names and uses strings.LastName produce a list of keys which are sorted by last name and uses a natural sorting for keys where the last names are the same
func SortedNumbers ¶
SortedNumbers returns a slice of ascending sorted keys from the given map
func ToEnviron ¶ added in v1.2.0
ToEnviron transforms the map into a SortedKeys os.Environ slice of KEY=value pairs. ToEnviron uses fmt.Sprintf("%v") to transform the values
Example:
environ := ToEnviron(map[string]interface{}{"one":"two", "many": 10}) // environ == []string{"ONE=two", "MANY=10"}
func ValuesSortedByKeys ¶ added in v1.1.0
func ValuesSortedByKeys[K ~string, V interface{}](data map[K]V) (values []V)
ValuesSortedByKeys returns a slice of values, ordered by SortedKeys
func ValuesSortedByNumbers ¶ added in v1.1.0
ValuesSortedByNumbers returns a slice of values, ordered by SortedNumbers
Types ¶
type BaseTypes ¶ added in v1.2.0
type BaseTypes interface { ~bool | ~string | []byte | []rune | ~float32 | ~float64 | ~complex64 | ~complex128 | ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 }
BaseTypes is a generic interface defining types suitable for a shallow copy using CopyBaseType