Skip to content

Commit

Permalink
Added First() and Itereate(f) to AttributeValues
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed Sep 13, 2022
1 parent 5ab49f7 commit e4d7840
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions modules/engine/attributevalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,23 @@ type AttributeAndValues struct {

// AttributeValues can contain one or more values
type AttributeValues interface {
First() AttributeValue
Iterate(func(val AttributeValue) bool)
Slice() []AttributeValue
StringSlice() []string
Len() int
}

type NoValues struct{}

func (nv NoValues) First() AttributeValue {
return nil
}

func (nv NoValues) Iterate(func(val AttributeValue) bool) {
// no op
}

func (nv NoValues) Slice() []AttributeValue {
return nil
}
Expand All @@ -100,6 +110,18 @@ func AttributeValueSliceFromStrings(values []string) AttributeValueSlice {

type AttributeValueSlice []AttributeValue

func (avs AttributeValueSlice) First() AttributeValue {
return avs[0]
}

func (avs AttributeValueSlice) Iterate(it func(val AttributeValue) bool) {
for _, cval := range avs {
if !it(cval) {
break
}
}
}

func (avs AttributeValueSlice) Slice() []AttributeValue {
return avs
}
Expand All @@ -124,6 +146,14 @@ type AttributeValueOne struct {
Value AttributeValue
}

func (avo AttributeValueOne) First() AttributeValue {
return avo.Value
}

func (avo AttributeValueOne) Iterate(it func(val AttributeValue) bool) {
it(avo.Value)
}

func (avo AttributeValueOne) Len() int {
return 1
}
Expand Down

0 comments on commit e4d7840

Please sign in to comment.