Add generic and generic structs
This commit is contained in:
@@ -10,6 +10,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// fmt.Println(output.Sum(100, 42))
|
||||||
|
// fmt.Println(output.Sum(10.7, 3.14))
|
||||||
|
// fmt.Println(output.Sum("Hello ", "world!"))
|
||||||
fmt.Println("__Менеджер паролей__")
|
fmt.Println("__Менеджер паролей__")
|
||||||
vault := account.NewVault(files.NewJsonDb("data.json"))
|
vault := account.NewVault(files.NewJsonDb("data.json"))
|
||||||
Menu:
|
Menu:
|
||||||
|
|||||||
@@ -14,3 +14,13 @@ func PrintError(value any) {
|
|||||||
color.Red("Неизвестный тип ошибки")
|
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