Add generic and generic structs
This commit is contained in:
@@ -14,3 +14,13 @@ func PrintError(value any) {
|
||||
color.Red("Неизвестный тип ошибки")
|
||||
}
|
||||
}
|
||||
|
||||
// Generic
|
||||
func Sum[T int | float32 | float64 | string](a, b T) T {
|
||||
return a + b
|
||||
}
|
||||
|
||||
// Generic structs
|
||||
type List[T any] struct {
|
||||
elements []T
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user