Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 215
Switch dyn.Mapping implementation to use map underneath#2737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
69a5f80d2dc5457f3aaa684d984a9f9eb39edf1bfdbef58147afa9d3f4bfacbc7478c8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -32,7 +32,7 @@ var NilValue = Value{ | ||
| // V constructs a new Value with the given value. | ||
| func V(v any) Value { | ||
| return NewValue(v, []Location{}) | ||
| return NewValue(v, nil) | ||
| } | ||
| // NewValue constructs a new Value with the given value and location. | ||
| @@ -103,10 +103,8 @@ func (v Value) AsAny() any { | ||
| case KindMap: | ||
| m := v.v.(Mapping) | ||
| out := make(map[string]any, m.Len()) | ||
| for _, pair := range m.pairs { | ||
| pk := pair.Key | ||
| pv := pair.Value | ||
| out[pk.MustString()] = pv.AsAny() | ||
| for key, value := range m.data { | ||
| out[key] = value.AsAny() | ||
| } | ||
| return out | ||
| case KindSequence: | ||
| @@ -214,3 +212,26 @@ func (v Value) eq(w Value) bool { | ||
| return v.v == w.v | ||
| } | ||
| } | ||
| func (v Value) DropKeyLocations() Value { | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please include a comment to explain why this function exists. | ||
| switch v.k { | ||
| case KindMap: | ||
| m := v.v.(Mapping) | ||
| out := make(map[string]Value, m.Len()) | ||
| for _, pair := range m.Pairs() { | ||
| pk := pair.Key | ||
| pv := pair.Value.DropKeyLocations() | ||
| out[pk.MustString()] = pv | ||
| } | ||
| return NewValue(NewMappingFromGoMap(out), v.l) | ||
| case KindSequence: | ||
| vv := v.v.([]Value) | ||
| a := make([]Value, len(vv)) | ||
| for i, v := range vv { | ||
| a[i] = v.DropKeyLocations() | ||
| } | ||
| return NewValue(a, v.l) | ||
| default: | ||
| return v | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious: the iteration is identical for
Pairs/Keys/Values. Might be a nice use case for https://go.dev/blog/range-functions#range-over-some-function-types.