I have written a very small prepend function for go.
func prepend(slice []int, elms ... int) []int {
newSlice := []int{}
for _, elm := range elms {
newSlice = append(newSlice, elm)
}
for _, item := range slice {
newSlice = append(newSlice, item)
}
return newSlice
}
Is there anyway to make the function generic for any type?
So that I can put in a slice of arrays a prepend to that.
Also, is there a better way to write this function?
I have not found anything online about writing one.