You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
465 B
22 lines
465 B
package collect |
|
|
|
// IsEmptySlice 切片是否为空 |
|
func IsEmptySlice[T any](slice []T) bool { |
|
return slice == nil || len(slice) == 0 |
|
} |
|
|
|
func IsNotEmptySlice[T any](slice []T) bool { |
|
return !IsEmptySlice(slice) |
|
} |
|
|
|
func IsEmptyMap[K comparable, V any](kvs map[K]V) bool { |
|
return kvs == nil || len(kvs) == 0 |
|
} |
|
|
|
func Mapping[T any, M any](slice []T, mapping func(T) M) []M { |
|
m := make([]M, len(slice)) |
|
for i, v := range slice { |
|
m[i] = mapping(v) |
|
} |
|
return m |
|
}
|
|
|