Skip to content

Commit 23993a6

Browse files
bdeb1337kawpii
andauthored
feat: Added solution for 24_generics exercise (#153)
Co-authored-by: Kaushalya Pradeep <24698778+kaushalyap@users.noreply.github.com>
1 parent 98c32c3 commit 23993a6

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)