diff --git a/slice_utils/slice_utils.go b/slice_utils/slice_utils.go index f203d0dc8d0dd698f63a5e53a815a990fb005aff..86ce64e0ca0e8465da1140a3fa836ef1884a091d 100644 --- a/slice_utils/slice_utils.go +++ b/slice_utils/slice_utils.go @@ -2,6 +2,7 @@ package slice_utils import ( "github.com/thoas/go-funk" + "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/utils" ) func MinimumFloat64(values []float64) (min float64) { @@ -64,3 +65,22 @@ func ArraySlice(s []any, offset, length int) []any { } return s[offset:] } + +func SliceToSlicePointers[V any](s []V) []*V { + result := make([]*V, len(s)) + for i, v := range s { + vCopy := v // Create a copy to avoid pointer to loop variable issue + result[i] = utils.ValueToPointer(vCopy) + } + return result +} + +func SlicePointersToSlice[V any](s []*V) []V { + result := make([]V, len(s)) + for i, vp := range s { + if vp != nil { + result[i] = utils.PointerToValue(vp) + } + } + return result +}