We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4e9b111 commit 433b6a8Copy full SHA for 433b6a8
1 file changed
container/slice.go
@@ -28,3 +28,12 @@ func InSlice[T comparable](v T, items []T) bool {
28
}
29
return false
30
31
+
32
+// EmptySliceIfNil checks if the given slice is nil. If it is, it returns an empty slice of the same type.
33
+// Otherwise, it returns the original slice.
34
+func EmptySliceIfNil[T any](src []T) (dst []T) {
35
+ if src == nil {
36
+ return make([]T, 0)
37
+ }
38
+ return src
39
+}
0 commit comments