mirror of
https://github.com/traefik/yaegi.git
synced 2026-06-01 18:37:56 +00:00
Status: * [x] parsing code with generics * [x] instantiate generics from concrete types * [x] automatic type inference * [x] support of generic recursive types * [x] support of generic methods * [x] support of generic receivers in methods * [x] support of multiple type parameters * [x] support of generic constraints * [x] tests (see _test/gen*.go) Fixes #1363.
25 lines
321 B
Go
25 lines
321 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
type Set[Elem comparable] struct {
|
|
m map[Elem]struct{}
|
|
}
|
|
|
|
func Make[Elem comparable]() Set[Elem] {
|
|
return Set[Elem]{m: make(map[Elem]struct{})}
|
|
}
|
|
|
|
func (s Set[Elem]) Add(v Elem) {
|
|
s.m[v] = struct{}{}
|
|
}
|
|
|
|
func main() {
|
|
s := Make[int]()
|
|
s.Add(1)
|
|
fmt.Println(s)
|
|
}
|
|
|
|
// Output:
|
|
// {map[1:{}]}
|