Skip to content
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

Add support for using nested lists and maps #39

Merged
merged 1 commit into from
Aug 13, 2017
Merged

Conversation

brikis98
Copy link
Member

This PR updates boilerplate so that variables with type list or map can support nested lists and nested maps. It’s rare that we need such complicated data structures, but occasionally it’s useful, and it wasn’t a hard change to support it.

@@ -418,16 +418,21 @@ func slice(start interface{}, end interface{}, increment interface{}) ([]int, er

// Return the keys in the given map. This method always returns the keys in sorted order to provide a stable iteration
// order.
func keys(m map[string]string) []string {
func keys(value interface{}) ([]string, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today's example of Go being a shitty language: without generics, in order to support map[x]y for arbitrary x and y, I had to remove all types from the code and use reflection. That makes the code harder to read and more brittle. We've known how to do generics for several decades; there is no excuse for this.

case reflect.Map:
values := map[interface{}]interface{}{}
for _, key := range valueType.MapKeys() {
renderedKey, err := renderVariable(key.Interface(), variables, options)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example 2 of Go being a shitty language. Here, type casting is required, because the incoming type genuinely could be anything, but even once I know the type is a map, I still have no way to express map[x]y for arbitrary x and y, so I'm used to use a ton more reflection just to loop over the keys and values. Brittle code that's harder to read = no fun.

@brikis98
Copy link
Member Author

Merging now. Feedback welcome!

@brikis98 brikis98 merged commit d00a55a into master Aug 13, 2017
@brikis98 brikis98 deleted the nested-objects branch August 13, 2017 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant