Skip to content

Commit

Permalink
MINOR: add PointerIfNotDefault function
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmatmati committed Feb 2, 2024
1 parent d45dfe4 commit 0bd222c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 0bd222c

Please sign in to comment.