Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
cue: deprecate Value.Elem and Value.Template
Browse files Browse the repository at this point in the history
LookupPath now supports both use cases.

Change-Id: I3ba7ab32f24bda79a63331190a8351508c50658b
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9348
Reviewed-by: CUE cueckoo <[email protected]>
Reviewed-by: Paul Jolly <[email protected]>
  • Loading branch information
mpvl committed Apr 8, 2021
1 parent 957003c commit f0adb4e
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions cue/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1208,22 +1208,15 @@ func (v Value) Len() Value {
}

// Elem returns the value of undefined element types of lists and structs.
//
// Deprecated: use LookupPath in combination with "AnyString" or "AnyIndex".
func (v Value) Elem() (Value, bool) {
if v.v == nil {
return Value{}, false
}
ctx := v.ctx().opCtx
x := &adt.Vertex{
Parent: v.v,
Label: 0,
sel := AnyString
if v.v.IsList() {
sel = AnyIndex
}
v.v.Finalize(ctx)
v.v.MatchAndInsert(ctx, x)
if len(x.Conjuncts) == 0 {
return Value{}, false
}
x.Finalize(ctx)
return makeValue(v.idx, x), true
x := v.LookupPath(MakePath(sel))
return x, x.Exists()
}

// List creates an iterator over the values of a list or reports an error if
Expand Down Expand Up @@ -1663,8 +1656,9 @@ func (v Value) FillPath(p Path, x interface{}) Value {
//
// The returned function returns the value that would be unified with field
// given its name.
//
// Deprecated: use LookupPath in combination with using optional selectors.
func (v Value) Template() func(label string) Value {
// TODO: rename to optional.
if v.v == nil {
return nil
}
Expand All @@ -1674,17 +1668,8 @@ func (v Value) Template() func(label string) Value {
return nil
}

parent := v.v
ctx := v.ctx().opCtx
return func(label string) Value {
f := ctx.StringLabel(label)
arc := &adt.Vertex{Parent: parent, Label: f}
v.v.MatchAndInsert(ctx, arc)
if len(arc.Conjuncts) == 0 {
return Value{}
}
arc.Finalize(ctx)
return makeValue(v.idx, arc)
return v.LookupPath(MakePath(Str(label).Optional()))
}
}

Expand Down

0 comments on commit f0adb4e

Please sign in to comment.