list.go 581 B

1234567891011121314151617181920212223242526272829303132
  1. package version
  2. // List is a slice of versions that implements sort.Interface.
  3. type List []*Version
  4. // Match tests versions against a constraint and returns a new List of matching versions only.
  5. func (list List) Match(c *Constraint) List {
  6. filtered := List{}
  7. for _, v := range list {
  8. if v.Match(c) {
  9. filtered = append(filtered, v)
  10. }
  11. }
  12. return filtered
  13. }
  14. func (list List) Len() int {
  15. return len(list)
  16. }
  17. func (list List) Less(i, j int) bool {
  18. return list[i].Less(list[j])
  19. }
  20. func (list List) Swap(i, j int) {
  21. a := list[i]
  22. b := list[j]
  23. list[i] = b
  24. list[j] = a
  25. }