From 8f4a255696a6af7dc6983ab2c6d4dd3ff9e68c2a Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Wed, 1 May 2024 17:30:33 +1200 Subject: [PATCH] refactor: use `cmp.Or` --- internal/output/result.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/internal/output/result.go b/internal/output/result.go index eb36181573..8eb5625079 100644 --- a/internal/output/result.go +++ b/internal/output/result.go @@ -1,6 +1,7 @@ package output import ( + "cmp" "encoding/json" "slices" "strings" @@ -23,17 +24,11 @@ func (pss *pkgSourceSet) StableKeys() []pkgWithSource { slices.SortFunc(pkgWithSrcKeys, func(a, b pkgWithSource) int { // compare based on each field in descending priority - for _, fn := range []func() int{ - func() int { return strings.Compare(a.Source.Path, b.Source.Path) }, - func() int { return strings.Compare(a.Package.Name, b.Package.Name) }, - func() int { return strings.Compare(a.Package.Version, b.Package.Version) }, - } { - if r := fn(); r != 0 { - return r - } - } - - return 0 + return cmp.Or( + strings.Compare(a.Source.Path, b.Source.Path), + strings.Compare(a.Package.Name, b.Package.Name), + strings.Compare(a.Package.Version, b.Package.Version), + ) }) return pkgWithSrcKeys