blob: 4819963b7a4a80b53f972c7dfc9165529b071f40 [file] [log] [blame]
-- inlayHint --
//go:build go1.18
// +build go1.18
package inlayHint //@inlayHint("package")
func main() {
ints< map[string]int64> := map[string]int64{
"first": 34,
"second": 12,
}
floats< map[string]float64> := map[string]float64{
"first": 35.98,
"second": 26.99,
}
SumIntsOrFloats[string, int64](<m: >ints)
SumIntsOrFloats[string, float64](<m: >floats)
SumIntsOrFloats<[string, int64]>(<m: >ints)
SumIntsOrFloats<[string, float64]>(<m: >floats)
SumNumbers<[string, int64]>(<m: >ints)
SumNumbers<[string, float64]>(<m: >floats)
}
type Number interface {
int64 | float64
}
func SumIntsOrFloats[K comparable, V int64 | float64](m map[K]V) V {
var s V
for _< K>, v< V> := range m {
s += v
}
return s
}
func SumNumbers[K comparable, V Number](m map[K]V) V {
var s V
for _< K>, v< V> := range m {
s += v
}
return s
}