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