Skip to content
Snippets Groups Projects
Commit 94e453b5 authored by Francé Wilke's avatar Francé Wilke
Browse files

Add generic functions SliceToSlicePointers and SlicePointersToSlice

parent d1186cbf
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ package slice_utils ...@@ -2,6 +2,7 @@ package slice_utils
import ( import (
"github.com/thoas/go-funk" "github.com/thoas/go-funk"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/utils"
) )
func MinimumFloat64(values []float64) (min float64) { func MinimumFloat64(values []float64) (min float64) {
...@@ -64,3 +65,22 @@ func ArraySlice(s []any, offset, length int) []any { ...@@ -64,3 +65,22 @@ func ArraySlice(s []any, offset, length int) []any {
} }
return s[offset:] 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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment