1 parent 98c32c3 commit 23993a6Copy full SHA for 23993a6
1 file changed
internal/exercises/solutions/24_generics/generics.go
@@ -0,0 +1,11 @@
1
+package generics
2
+
3
+// identity returns the argument, of any type, as is.
4
+func identity[T any](arg T) T {
5
+ return arg
6
+}
7
8
+// sumIntsOrFloats takes two arguments of the same type, either int or float64, and returns their sum.
9
+func sumIntsOrFloats[T int | float64](a, b T) T {
10
+ return a + b
11
0 commit comments