How many type constraints out there

Hi forum,

How many type constraints can I have for type parameters? Ive read some docs and know these two: comparable, any. I think it is very limited. Is there a complete list that I can check.

How can I write a Less than function with type parameters?

Thanks

func Equal[T comparable](a, b T) bool {
	return a == b
}

//return true if a < b
// func Less(a, b) bool {
//}

Tutorial on user-defined type constraints here Tutorial: Getting started with generics - The Go Programming Language

More elaboration here Generics in Go — Bitfield Consulting

3 Likes

Thanks Jeff,

It is very helpful

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.