Skip to content

Instantly share code, notes, and snippets.

@pfcoperez
Created February 20, 2022 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfcoperez/2f552bc1cf2a4dc07cb4c88c23e96c30 to your computer and use it in GitHub Desktop.
Save pfcoperez/2f552bc1cf2a4dc07cb4c88c23e96c30 to your computer and use it in GitHub Desktop.
Generic in Go
package main
// https://go.dev/doc/tutorial/generics
import "fmt"
func receiveSlice[V interface{}](theSlice []V) []V {
ret := make([]V, len(theSlice))
for i, value := range theSlice {
ret[i] = value
}
return ret
}
func main() {
fmt.Println("Hello >> ", receiveSlice([]int{1, 2, 3, 4}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment