mirror of
https://github.com/hanzoai/yaegi.git
synced 2026-10-01 00:49:47 +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.
20 lines
279 B
Go
20 lines
279 B
Go
package main
|
|
|
|
func MapKeys[K comparable, V any](m map[K]V) []K {
|
|
r := make([]K, 0, len(m))
|
|
for k := range m {
|
|
r = append(r, k)
|
|
}
|
|
return r
|
|
}
|
|
|
|
func main() {
|
|
var m = map[int]string{1: "2", 2: "4", 4: "8"}
|
|
|
|
// Test type inference
|
|
println(len(MapKeys(m)))
|
|
}
|
|
|
|
// Output:
|
|
// 3
|