aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCole Faust <colefaust@google.com>2024-03-14 14:28:52 -0700
committerCole Faust <colefaust@google.com>2024-03-14 14:28:52 -0700
commita962edf7630abb8a67dc7f2883ac4c921bd0e8a9 (patch)
tree316e319b1eecf278870b27b7af76d66c20095513
parent6437d4e737dd1c339ed64374ee8010da8febeb92 (diff)
downloadblueprint-a962edf7630abb8a67dc7f2883ac4c921bd0e8a9.tar.gz
Add proptools.Slice
To make it easier to handle the result of Configurable[[]string].Evaluate() Bug: 329711542 Test: go tests Change-Id: I7364170564b1049a33873424c6da4fc26aff305b
-rw-r--r--proptools/proptools.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/proptools/proptools.go b/proptools/proptools.go
index 98fe953..270512a 100644
--- a/proptools/proptools.go
+++ b/proptools/proptools.go
@@ -105,6 +105,15 @@ func String(s *string) string {
return StringDefault(s, "")
}
+// Slice takes a pointer to a slice and returns the value of the slice if the pointer is non-nil,
+// or a nil slice.
+func Slice[T any](s *[]T) []T {
+ if s != nil {
+ return *s
+ }
+ return nil
+}
+
// IntDefault takes a pointer to an int64 and returns the value pointed to by the pointer cast to int
// if it is non-nil, or def if the pointer is nil.
func IntDefault(i *int64, def int) int {