From a962edf7630abb8a67dc7f2883ac4c921bd0e8a9 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Thu, 14 Mar 2024 14:28:52 -0700 Subject: [PATCH] Add proptools.Slice To make it easier to handle the result of Configurable[[]string].Evaluate() Bug: 329711542 Test: go tests Change-Id: I7364170564b1049a33873424c6da4fc26aff305b --- proptools/proptools.go | 9 +++++++++ 1 file changed, 9 insertions(+) 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 {