Created
February 20, 2022 17:31
-
-
Save pfcoperez/2f552bc1cf2a4dc07cb4c88c23e96c30 to your computer and use it in GitHub Desktop.
Generic in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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