# README
maps - go map type utilities
maps is a package for general purpose map-type things, such as getting a
list of naturally SortedKeys
.
Installation
> go get github.com/go-corelibs/maps@latest
Examples
SortedKeys
func main() {
m := map[string]struct{}{
"one": {},
"two": {},
"many": {},
"v1": {},
"v10": {},
"v2": {},
}
keys := maps.SortedKeys(m)
// keys == []string{"many", "one", "two", "v1", "v2", "v10"}
}
Go-CoreLibs
Go-CoreLibs is a repository of shared code between the Go-Curses and Go-Enjin projects.
License
Copyright 2023 The Go-CoreLibs Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use file except in compliance with the License.
You may obtain a copy of the license at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
# Functions
CamelizeKeys is a CamelCase wrapper around RenameKeys.
CopyBaseType returns a shallow copy of the given map[comparable]BaseTypes.
DeepCopy is a wrapper around values.DeepCopy.
No description provided by the author
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.
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.
No description provided by the author
GetKV finds the relative key given, returning both the actual key and the associated interface{} value, using the following procedure:
1.
Has checks for the presence of the (deep or exact) key given.
KebabKeys is a kebab-case wrapper around RenameKeys.
Keys returns the list of map keys, in whatever order Go produces from a simple range over the data.
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{}{}.
OrderedKeys returns the list of cmp.Ordered keys in ascending order.
No description provided by the author
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.
ReverseOrderedKeys returns the list of cmp.Ordered keys in descending order.
ReverseSortedKeys returns the list of keys in reverse natural sorted order.
ReverseSortedNumbers returns a slice of descending sorted keys from the given map.
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.
Set checks if the key being set is a deep key and if so, sets the value deeply within the map structure.
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.
SnakeKeys is a snake_case wrapper around RenameKeys.
SortedKeyLengths returns the list of keys, from longest to shortest and natural sorted for same length keys.
SortedKeys returns a slice of natural-sorted keys from the given map.
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.
SortedNumbers returns a slice of ascending sorted keys from the given map.
ToEnviron transforms the map into a SortedKeys os.Environ slice of KEY=value pairs.
ValuesSortedByKeys returns a slice of values, ordered by SortedKeys.
ValuesSortedByNumbers returns a slice of values, ordered by SortedNumbers.
# Interfaces
BaseTypes is a generic interface defining types suitable for a shallow copy using CopyBaseType.