From 0bd222c57abb46b841fe92d50f2a4596be9d1cd6 Mon Sep 17 00:00:00 2001 From: Ivan Matmati Date: Fri, 2 Feb 2024 14:29:46 +0100 Subject: [PATCH] MINOR: add PointerIfNotDefault function --- pkg/utils/utils.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 386fe50b..21367aae 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -205,3 +205,12 @@ func EqualSliceByIDFunc[T any](a, b []T, id func(x T) string) bool { } return true } + +// PointerIfNotDefault returns a pointer to the argument if it's not a default value for type T +func PointerIfNotDefault[T comparable](arg T) *T { + var def T + if arg != def { + return &arg + } + return nil +}