@@ -11,12 +11,12 @@ import (
1111 "reflect"
1212)
1313
14- // Array is a Node representing an array (aka slice in Go) of values, which can be either a Literal or Attribute.
15- type Array struct {
14+ // Set is a Node representing a set of values, which can be either a Literal or Attribute.
15+ type Set struct {
1616 Nodes []Node
1717}
1818
19- func (a Array ) Dfl () string {
19+ func (a Set ) Dfl () string {
2020 str := "["
2121 for i , x := range a .Nodes {
2222 if i > 0 {
@@ -28,15 +28,16 @@ func (a Array) Dfl() string {
2828 return str
2929}
3030
31- func (a Array ) Map () map [string ]interface {} {
31+ func (a Set ) Map () map [string ]interface {} {
3232 return map [string ]interface {}{
3333 "nodes" : a .Nodes ,
3434 }
3535}
3636
3737// Compile returns a compiled version of this node.
38- // If all the values of an array are literals, returns a single Literal with the corresponding array/slice as its value.
39- func (a Array ) Compile () Node {
38+ // If all the values of an Set are literals, returns a single Literal with the corresponding Set/slice as its value.
39+ // Otherwise returns the original node..
40+ func (a Set ) Compile () Node {
4041 values := make ([]interface {}, len (a .Nodes ))
4142 nodes := reflect .ValueOf (a .Nodes )
4243 for i := 0 ; i < nodes .Len (); i ++ {
@@ -48,10 +49,19 @@ func (a Array) Compile() Node {
4849 return a
4950 }
5051 }
51- return Literal {Value : values }
52+ set := make (map [string ]struct {}, len (values ))
53+ for _ , v := range values {
54+ switch v .(type ) {
55+ case string :
56+ set [v .(string )] = struct {}{}
57+ default :
58+ return Literal {Value : values }
59+ }
60+ }
61+ return Literal {Value : set }
5262}
5363
54- func (a Array ) Evaluate (ctx Context , funcs FunctionMap ) (interface {}, error ) {
64+ func (a Set ) Evaluate (ctx Context , funcs FunctionMap ) (interface {}, error ) {
5565 values := make ([]interface {}, len (a .Nodes ))
5666 for i , n := range a .Nodes {
5767 v , err := n .Evaluate (ctx , funcs )
@@ -63,7 +73,7 @@ func (a Array) Evaluate(ctx Context, funcs FunctionMap) (interface{}, error) {
6373 return values , nil
6474}
6575
66- func (a Array ) Attributes () []string {
76+ func (a Set ) Attributes () []string {
6777 set := make (map [string ]struct {})
6878 for _ , n := range a .Nodes {
6979 for _ , x := range n .Attributes () {
0 commit comments