Add proptools.Slice
To make it easier to handle the result of Configurable[[]string].Evaluate() Bug: 329711542 Test: go tests Change-Id: I7364170564b1049a33873424c6da4fc26aff305b
This commit is contained in:
parent
6437d4e737
commit
a962edf763
1 changed files with 9 additions and 0 deletions
|
@ -105,6 +105,15 @@ func String(s *string) string {
|
||||||
return StringDefault(s, "")
|
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
|
// 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.
|
// if it is non-nil, or def if the pointer is nil.
|
||||||
func IntDefault(i *int64, def int) int {
|
func IntDefault(i *int64, def int) int {
|
||||||
|
|
Loading…
Reference in a new issue