api nil slice map

This commit is contained in:
withchao
2023-07-06 15:09:41 +08:00
parent ff22ea7108
commit f6756008b0
5 changed files with 21 additions and 13 deletions
+12
View File
@@ -529,3 +529,15 @@ func Batch[T any, V any](fn func(T) V, ts []T) []V {
}
return res
}
func InitSlice[T any](val *[]T) {
if val != nil && *val == nil {
*val = []T{}
}
}
func InitMap[K comparable, V any](val *map[K]V) {
if val != nil && *val == nil {
*val = map[K]V{}
}
}