refactor(comments): beautify comments

This commit is contained in:
Piotr Icikowski 2024-05-28 00:20:32 +02:00
parent 057f12e602
commit 73328b0ef7
Signed by: Piotr Icikowski
GPG Key ID: 3931CA47A91F7666
2 changed files with 7 additions and 7 deletions

View File

@ -1,6 +1,6 @@
package generics
// MapPairs returns list of map's key-value pairs
// MapPairs returns list of map's key-value pairs.
func MapPairs[K comparable, V any](src map[K]V) Pairs[K, V] {
dst := make([]Pair[K, V], len(src))
idx := 0
@ -14,7 +14,7 @@ func MapPairs[K comparable, V any](src map[K]V) Pairs[K, V] {
return dst
}
// MapKeys returns list of map's keys
// MapKeys returns list of map's keys.
func MapKeys[K comparable, V any](src map[K]V) []K {
dst := make([]K, len(src))
idx := 0
@ -25,7 +25,7 @@ func MapKeys[K comparable, V any](src map[K]V) []K {
return dst
}
// MapValues returns list of map's values
// MapValues returns list of map's values.
func MapValues[K comparable, V any](src map[K]V) []V {
dst := make([]V, len(src))
idx := 0
@ -36,7 +36,7 @@ func MapValues[K comparable, V any](src map[K]V) []V {
return dst
}
// InvertMap returns map with keys and values swapped
// InvertMap returns map with keys and values swapped.
func InvertMap[K, V comparable](src map[K]V) map[V]K {
if src == nil {
return nil

6
ptr.go
View File

@ -1,11 +1,11 @@
package generics
// Ptr returns pointer for given value
// Ptr returns pointer for given value.
func Ptr[T any](val T) *T {
return &val
}
// Val returns value of given pointer or default value if pointer is nil
// Val returns value of given pointer or default value if pointer is nil.
func Val[T any](ptr *T) T {
var val T
if ptr != nil {
@ -14,7 +14,7 @@ func Val[T any](ptr *T) T {
return val
}
// Fallback returns value of given pointer or fallback value if pointer is nil
// Fallback returns value of given pointer or fallback value if pointer is nil.
func Fallback[T any](ptr *T, fallback T) T {
if ptr != nil {
return *ptr