Created
March 17, 2022 16:04
-
-
Save salrashid123/401e79797dbb9c6462865f815d45fde8 to your computer and use it in GitHub Desktop.
go1.18 generic
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 | |
import ( | |
"fmt" | |
) | |
type Foo struct { | |
a string | |
b string | |
} | |
type Bar struct { | |
a int | |
b int | |
} | |
func main() { | |
f := []Foo{{"aa", "bb"}, {"aaa", "bbb"}} | |
b := []Bar{{1, 2}, {3, 4}} | |
Print(f) | |
Print(b) | |
} | |
func Print[T any](s []T) { | |
for _, v := range s { | |
fmt.Print(v) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment