-
Notifications
You must be signed in to change notification settings - Fork 16
/
intersect.go
44 lines (39 loc) · 890 Bytes
/
intersect.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
44
package dynaml
import (
"github.com/mandelsoft/spiff/yaml"
)
func init() {
RegisterFunction("intersect", func_intersect)
}
func func_intersect(arguments []interface{}, binding Binding) (interface{}, EvaluationInfo, bool) {
var result []yaml.Node
info := DefaultInfo()
for i, l := range arguments {
switch alist := l.(type) {
case []yaml.Node:
if result == nil {
result = alist
} else {
newList := []yaml.Node{}
for _, e := range result {
found := false
for _, n := range alist {
r, _, _ := compareEquals(e.Value(), n.Value())
if r {
found = true
break
}
}
if found {
newList = append(newList, e)
}
}
result = newList
}
case nil:
default:
return info.Error("intersect: argument %d: type '%s'(%s) cannot be intersected", i, ExpressionType(l))
}
}
return result, info, true
}