collections/comparators/string.go

16 lines
385 B
Go
Raw Normal View History

2023-07-26 22:13:21 +02:00
package comparators
import (
"golang.org/x/text/collate"
"golang.org/x/text/language"
"pkg.icikowski.pl/collections/functions"
)
2024-05-28 01:28:25 +02:00
// CompareString returns [functions.Comparator] for string values in given language.
2023-07-26 22:13:21 +02:00
func CompareString(lang language.Tag) functions.Comparator[string] {
c := collate.New(lang)
return func(a, b string) bool {
return c.CompareString(a, b) < 0
}
}