Download pkg/slicesx/empty.go from Leon4gr45/openmeter: direct link, hf CLI and curl.
- Browser
- Download file 315 Bytes
-
https://huggingface.co/spaces/Leon4gr45/openmeter/resolve/main/pkg/slicesx/empty.go
- Command line
-
hf download hf://spaces/Leon4gr45/openmeter/pkg/slicesx/empty.go
-
curl -L -o empty.go https://huggingface.co/spaces/Leon4gr45/openmeter/resolve/main/pkg/slicesx/empty.go
315 Bytes
| package slicesx | |
| // EmptyAsNil returns nil if the slice is empty otherwise the slice is returned. | |
| // This is useful when in tests we are checking struct equality, as we don't need to care | |
| // about the slice being zero length or nil. | |
| func EmptyAsNil[T any](s []T) []T { | |
| if len(s) == 0 { | |
| return nil | |
| } | |
| return s | |
| } | |