Files
version/list.go
T

41 lines
688 B
Go
Raw Normal View History

2024-07-11 22:21:19 +01:00
package version
// List is a slice of versions that implements sort.Interface.
type List []*Version
2024-07-12 12:11:18 +01:00
// Match tests versions against a constraint and returns a new List of matching versions only.
func (list List) Match(constraints ...*Constraint) List {
2024-07-12 12:11:18 +01:00
filtered := List{}
for _, v := range list {
ok := true
for _, c := range constraints {
if !v.Match(c) {
ok = false
break
}
}
if ok {
2024-07-12 12:11:18 +01:00
filtered = append(filtered, v)
}
}
return filtered
}
2024-07-11 22:21:19 +01:00
func (list List) Len() int {
return len(list)
}
func (list List) Less(i, j int) bool {
return list[i].Less(list[j])
}
func (list List) Swap(i, j int) {
a := list[i]
b := list[j]
list[i] = b
list[j] = a
}