Go functions can be written to work on multiple types using type parameters, just like template class in C++. here is a example func Index[T comparable](s []T, x T) int
This means that s
is a slice of type T that fulfils built-in constraint comparable
.
comparable
is a useful constraint that makes it possible to use ==
and !=
operators on values of the type.
go
keyword, and it'll be executed in a new go-routine.