File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -793,7 +793,7 @@ func (o KubeObjects) String() string {
793793}
794794
795795// Where will return the subset of objects in KubeObjects such that f(object) returns 'true'.
796- func (o KubeObjects ) Where (f func (o * KubeObject ) bool ) KubeObjects {
796+ func (o KubeObjects ) Where (f func (* KubeObject ) bool ) KubeObjects {
797797 var result KubeObjects
798798 for _ , obj := range o {
799799 if f (obj ) {
@@ -803,15 +803,17 @@ func (o KubeObjects) Where(f func(o *KubeObject) bool) KubeObjects {
803803 return result
804804}
805805
806+ // Not returns will return a function that returns the opposite of f(object), i.e. !f(object)
807+ func Not (f func (* KubeObject ) bool ) func (o * KubeObject ) bool {
808+ return func (o * KubeObject ) bool {
809+ return ! f (o )
810+ }
811+ }
812+
806813// WhereNot will return the subset of objects in KubeObjects such that f(object) returns 'false'.
814+ // This is a shortcut for Where(Not(f)).
807815func (o KubeObjects ) WhereNot (f func (o * KubeObject ) bool ) KubeObjects {
808- var result KubeObjects
809- for _ , obj := range o {
810- if ! f (obj ) {
811- result = append (result , obj )
812- }
813- }
814- return result
816+ return o .Where (Not (f ))
815817}
816818
817819// IsGVK returns a function that checks if a KubeObject has a certain GVK.
You can’t perform that action at this time.
0 commit comments