mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-18 11:09:29 +02:00
Replaced util Min/Max functions with builtin
This commit is contained in:
parent
357932f9b0
commit
bcc7bf3167
5 changed files with 4 additions and 34 deletions
|
@ -26,7 +26,6 @@ import (
|
||||||
"go.uploadedlobster.com/scotty/internal/config"
|
"go.uploadedlobster.com/scotty/internal/config"
|
||||||
"go.uploadedlobster.com/scotty/internal/i18n"
|
"go.uploadedlobster.com/scotty/internal/i18n"
|
||||||
"go.uploadedlobster.com/scotty/internal/models"
|
"go.uploadedlobster.com/scotty/internal/models"
|
||||||
"go.uploadedlobster.com/scotty/internal/util"
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -106,7 +105,7 @@ out:
|
||||||
// and continue.
|
// and continue.
|
||||||
if offset >= result.Total {
|
if offset >= result.Total {
|
||||||
p.Total = int64(result.Total)
|
p.Total = int64(result.Total)
|
||||||
offset = util.Max(result.Total-perPage, 0)
|
offset = max(result.Total-perPage, 0)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +174,7 @@ out:
|
||||||
if offset >= result.Total {
|
if offset >= result.Total {
|
||||||
p.Total = int64(result.Total)
|
p.Total = int64(result.Total)
|
||||||
totalCount = result.Total
|
totalCount = result.Total
|
||||||
offset = util.Max(result.Total-perPage, 0)
|
offset = max(result.Total-perPage, 0)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ import (
|
||||||
"go.uploadedlobster.com/scotty/internal/config"
|
"go.uploadedlobster.com/scotty/internal/config"
|
||||||
"go.uploadedlobster.com/scotty/internal/i18n"
|
"go.uploadedlobster.com/scotty/internal/i18n"
|
||||||
"go.uploadedlobster.com/scotty/internal/models"
|
"go.uploadedlobster.com/scotty/internal/models"
|
||||||
"go.uploadedlobster.com/scotty/internal/util"
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
"golang.org/x/oauth2/spotify"
|
"golang.org/x/oauth2/spotify"
|
||||||
)
|
)
|
||||||
|
@ -184,7 +183,7 @@ out:
|
||||||
if offset >= result.Total {
|
if offset >= result.Total {
|
||||||
p.Total = int64(result.Total)
|
p.Total = int64(result.Total)
|
||||||
totalCount = result.Total
|
totalCount = result.Total
|
||||||
offset = util.Max(result.Total-perPage, 0)
|
offset = max(result.Total-perPage, 0)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ func Similarity(s1 string, s2 string) float64 {
|
||||||
s2 = norm.NFKC.String(s2)
|
s2 = norm.NFKC.String(s2)
|
||||||
l1 := len([]rune(s1))
|
l1 := len([]rune(s1))
|
||||||
l2 := len([]rune(s2))
|
l2 := len([]rune(s2))
|
||||||
maxLen := util.Max(l1, l2)
|
maxLen := max(l1, l2)
|
||||||
// Empty strings always compare full equal
|
// Empty strings always compare full equal
|
||||||
if maxLen == 0 {
|
if maxLen == 0 {
|
||||||
return 1.0
|
return 1.0
|
||||||
|
|
|
@ -17,22 +17,6 @@ package util
|
||||||
|
|
||||||
import "golang.org/x/exp/constraints"
|
import "golang.org/x/exp/constraints"
|
||||||
|
|
||||||
func Max[T constraints.Ordered](m, n T) T {
|
|
||||||
if n > m {
|
|
||||||
return n
|
|
||||||
} else {
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Min[T constraints.Ordered](m, n T) T {
|
|
||||||
if n < m {
|
|
||||||
return n
|
|
||||||
} else {
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Sum[T constraints.Integer | constraints.Float](v ...T) T {
|
func Sum[T constraints.Integer | constraints.Float](v ...T) T {
|
||||||
var sum T
|
var sum T
|
||||||
for _, i := range v {
|
for _, i := range v {
|
||||||
|
|
|
@ -23,18 +23,6 @@ import (
|
||||||
"go.uploadedlobster.com/scotty/internal/util"
|
"go.uploadedlobster.com/scotty/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExampleMax() {
|
|
||||||
v := util.Max(2, 5)
|
|
||||||
fmt.Print(v)
|
|
||||||
// Output: 5
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleMin() {
|
|
||||||
v := util.Min(2, 5)
|
|
||||||
fmt.Print(v)
|
|
||||||
// Output: 2
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleSum() {
|
func ExampleSum() {
|
||||||
values := []float64{1.4, 2.2}
|
values := []float64{1.4, 2.2}
|
||||||
sum := util.Sum(values...)
|
sum := util.Sum(values...)
|
||||||
|
|
Loading…
Add table
Reference in a new issue