Structs

Generic structs work the same as any other generic type. Therefore, when instantiated, you must pass the types that the struct will use:


modelInt := Model[int]{
    Data: []int{1, 2, 3},
}
                        

If you declare methods on a generic type, you must repeat the type parameter declaration in the receiver even if the type parameters are not used in the scope of the method — in that case, you can use the identifier _ to make it obvious

An important detail is that — unlike functions — generic types must always provide all type parameters upon instantiation.

structs.go