AOC2022/helper/helper.go
2022-12-03 03:40:46 +01:00

40 lines
529 B
Go

package helper
import (
"os"
"strings"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func RemoveError[T any](value T, e error) T {
check(e)
return value
}
func ReadTextFile(filePath string) []string {
file, err := os.ReadFile(filePath)
check(err)
return strings.Split(string(file), "\r\n")
}
func FindMax[T int | int64](slice []T) (m T) {
for i, e := range slice {
if i == 0 || e > m {
m = e
}
}
return
}
func Sum[T int | int64](slice []T) (s T) {
for _, e := range slice {
s += e
}
return
}