1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-08 22:52:29 +08:00

doc: update doc for GetOrDefault

This commit is contained in:
dudaodong
2024-09-10 15:54:54 +08:00
6 changed files with 116 additions and 2 deletions

View File

@@ -657,3 +657,12 @@ func convertMap(src reflect.Value, dst reflect.Value) error {
return nil
}
// GetOrDefault returns the value of the given key or a default value if the key is not present.
// Play: todo
func GetOrDefault[K comparable, V any](m map[K]V, key K, defaultValue V) V {
if v, ok := m[key]; ok {
return v
}
return defaultValue
}