Mutation method updated to return new copy

with value node (pointer) and value (non pointer) returned.
This commit is contained in:
Dave Shanley
2022-09-13 09:32:08 -04:00
parent a2b7119af7
commit aa4422fa74
4 changed files with 167 additions and 177 deletions

View File

@@ -40,8 +40,10 @@ func (n NodeReference[T]) GenerateMapKey() string {
return fmt.Sprintf("%d:%d", n.ValueNode.Line, n.ValueNode.Column)
}
func (n NodeReference[T]) Mutate(value T) {
func (n NodeReference[T]) Mutate(value T) NodeReference[T] {
n.ValueNode.Value = fmt.Sprintf("%v", value)
n.Value = value
return n
}
func (n ValueReference[T]) IsEmpty() bool {
@@ -60,8 +62,10 @@ func (n KeyReference[T]) GenerateMapKey() string {
return fmt.Sprintf("%d:%d", n.KeyNode.Line, n.KeyNode.Column)
}
func (n ValueReference[T]) Mutate(value T) {
func (n ValueReference[T]) Mutate(value T) ValueReference[T] {
n.ValueNode.Value = fmt.Sprintf("%v", value)
n.Value = value
return n
}
func IsCircular(node *yaml.Node, idx *index.SpecIndex) bool {