aoc24/util/loadFile.go

36 lines
510 B
Go
Raw Normal View History

2024-12-02 13:42:47 +00:00
package util
import (
"flag"
"os"
"strings"
"git.mstar.dev/mstar/goutils/sliceutils"
)
func LoadFileFromArgs() []byte {
if !flag.Parsed() {
flag.Parse()
}
data, err := os.ReadFile(flag.CommandLine.Arg(0))
if err != nil {
panic(err)
}
return data
}
func AbsI(a int) int {
if a > 0 {
return a
} else {
return -a
}
}
func FileContentToNonEmptyLines(data []byte) []string {
return sliceutils.Filter(
strings.Split(string(data), "\n"),
func(t string) bool { return len(t) > 0 },
)
}