docs: add godoc comments to all exported functions and methods
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"slices"
|
||||
)
|
||||
|
||||
// OrderedKeys returns the keys of the map sorted in ascending order.
|
||||
func OrderedKeys[Map map[K]V, K cmp.Ordered, V any](m Map) []K {
|
||||
keysIter := maps.Keys(m)
|
||||
keys := slices.Collect(keysIter)
|
||||
@@ -13,6 +14,7 @@ func OrderedKeys[Map map[K]V, K cmp.Ordered, V any](m Map) []K {
|
||||
return keys
|
||||
}
|
||||
|
||||
// AssertAndConvertMapValues asserts and converts all values in a map[string]any to type T.
|
||||
func AssertAndConvertMapValues[T any, M map[K]any, K cmp.Ordered](m M) map[K]T {
|
||||
ret := map[K]T{}
|
||||
for k, v := range m {
|
||||
@@ -21,6 +23,7 @@ func AssertAndConvertMapValues[T any, M map[K]any, K cmp.Ordered](m M) map[K]T {
|
||||
return ret
|
||||
}
|
||||
|
||||
// ReverseMap returns a new map with keys and values swapped.
|
||||
func ReverseMap[M map[K]V, K cmp.Ordered, V cmp.Ordered](m M) map[V]K {
|
||||
ret := map[V]K{}
|
||||
for k, v := range m {
|
||||
@@ -29,6 +32,7 @@ func ReverseMap[M map[K]V, K cmp.Ordered, V cmp.Ordered](m M) map[V]K {
|
||||
return ret
|
||||
}
|
||||
|
||||
// PopFront removes and returns the first element of the slice.
|
||||
func PopFront[T any](s []T) (T, []T, bool) {
|
||||
if len(s) == 0 {
|
||||
var zero T
|
||||
@@ -37,6 +41,7 @@ func PopFront[T any](s []T) (T, []T, bool) {
|
||||
return s[0], s[1:], true
|
||||
}
|
||||
|
||||
// CombineNamAndData returns a slice containing name and data.
|
||||
func CombineNamAndData(name string, data any) []any {
|
||||
return []any{name, data}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user