yq/pkg/yqlib/treeops/operator_select.go

38 lines
751 B
Go
Raw Normal View History

2020-10-17 11:10:47 +00:00
package treeops
import (
2020-10-21 01:54:58 +00:00
"container/list"
2020-10-17 11:10:47 +00:00
)
2020-10-21 01:54:58 +00:00
func SelectOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) {
2020-10-17 11:10:47 +00:00
log.Debugf("-- selectOperation")
2020-10-21 01:54:58 +00:00
var results = list.New()
2020-10-17 11:10:47 +00:00
for el := matchingNodes.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode)
2020-10-27 05:45:16 +00:00
rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs)
2020-10-17 11:10:47 +00:00
if err != nil {
return nil, err
}
// grab the first value
first := rhs.Front()
if first != nil {
result := first.Value.(*CandidateNode)
includeResult, errDecoding := isTruthy(result)
if errDecoding != nil {
return nil, errDecoding
}
if includeResult {
2020-10-21 01:54:58 +00:00
results.PushBack(candidate)
2020-10-17 11:10:47 +00:00
}
}
}
return results, nil
}