-
Notifications
You must be signed in to change notification settings - Fork 47
/
and.go
43 lines (35 loc) · 856 Bytes
/
and.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
Use of this source code is governed by a MIT license that can be found in the LICENSE file.
*/
package selector
import "strings"
// And is a combination selector.
type And []Selector
// Matches returns if both A and B match the labels.
func (a And) Matches(labels Labels) bool {
for _, s := range a {
if !s.Matches(labels) {
return false
}
}
return true
}
// Validate validates all the selectors in the clause.
func (a And) Validate() (err error) {
for _, s := range a {
err = s.Validate()
if err != nil {
return
}
}
return
}
// And returns a string representation for the selector.
func (a And) String() string {
var childValues []string
for _, c := range a {
childValues = append(childValues, c.String())
}
return strings.Join(childValues, ", ")
}