Skip to content

Commit

Permalink
Use slices.DeleteFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisnovakovic committed Oct 17, 2024
1 parent e995929 commit 42ae0b9
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ var javaExcludePrefixes = []string{

var log = logging.MustGetLogger()

// countFunc returns the number of elements in s that satisfy f.
func countFunc[S []E, E comparable](s S, f func(e E) bool) int {
var n int
for {
i := slices.IndexFunc(s, f)
if i == -1 {
break
}
n++
s = s[i+1:]
}
return n
}

func must(err error) {
if err != nil {
log.Fatalf("%s", err)
Expand Down Expand Up @@ -194,11 +180,11 @@ func main() {
os.Exit(0)
}

if countFunc([]string{
if len(slices.DeleteFunc([]string{
opts.Zip.Preamble,
opts.Zip.PreambleFrom,
opts.Zip.PreambleFile,
}, func(s string) bool { return s != "" }) > 1 {
}, func(s string) bool { return s == "" })) > 1 {
log.Fatal("Only one of --preamble, --preamble_from or --preamble_file may be specified.")
}

Expand Down

0 comments on commit 42ae0b9

Please sign in to comment.