Generic Types

We know how to write functions that can take arguments of any type. But what if we want to create a type that can contain any type?

For example, a slice that contains any type. See the following example:


type Several [E any] []E
                        

We are saying that for any element of type E, a Varios[E] is a slice of values ​​of type E. For example, a Varios[int] is a slice of ints.

generic_types.go