Skip to content

Commit 8fb1141

Browse files
committed
added a new type interface called Number and moved the union there
1 parent 8232750 commit 8fb1141

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

create_generics/utils/utils.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package utils
22

3+
// This is the union type moved to a new type
4+
type Number interface {
5+
int | int64 | float64
6+
}
7+
38
func SumOfNIntegers(numbers map[string]int) int {
49
var sum int = 0
510
for _, num := range numbers {
@@ -19,7 +24,7 @@ func SumOfNFloats(numbers map[string]float64) float64 {
1924
return sum
2025
}
2126

22-
func SumOfNNumbers[K comparable, V int | float64](m map[K]V) V {
27+
func SumOfNNumbers[K comparable, V Number](m map[K]V) V {
2328
var s V
2429

2530
for _, v := range m {

0 commit comments

Comments
 (0)