Skip to content

Instantly share code, notes, and snippets.

@salrashid123
Created March 17, 2022 16:04
Show Gist options
  • Save salrashid123/401e79797dbb9c6462865f815d45fde8 to your computer and use it in GitHub Desktop.
Save salrashid123/401e79797dbb9c6462865f815d45fde8 to your computer and use it in GitHub Desktop.
go1.18 generic
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