-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
config: new "reverse" interpolation function #18887
config: new "reverse" interpolation function #18887
Conversation
First PR on Terraform. This is useful for
Assuming you want it in ascending order, you need to reverse the list. for_each may solve this, but for existing terraform configurations, this is invaluable. |
Hi @sargun! Thanks for working on this. The implementation here looks good to me. The interpolation functions are frozen for the moment while we complete some refactoring in preparation for the 0.12 release, so we'll need to hold on merging this for a little while, but I've labelled this so we'll find it again during our 0.12 release preparation. The way functions are defined will be changing once we complete this refactoring, so this PR will need some changes to adapt to the new style but we'd be happy to do that step at merge time since it'll just be the same mechanical updates we'll be doing for a number of other pending function pull requests. Thanks again! We'll be back here to merge this as we get closer to the 0.12 release. |
@apparentlymart Sounds good. Thanks for taking a look at it. Is there a rough timeline as to 0.12 yet? |
inputList := args[0].([]ast.Variable) | ||
|
||
reversedList := make([]ast.Variable, len(inputList)) | ||
for idx := range inputList { |
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.
One could say that you could iterate over len(inputList) /2
and do swaps:
example pseudocode
r := make([]ast.Variable, len(inputList))
copy(r, inputList)
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
r[i], r[j] = r[j], r[i]
}
return r, nil
It reverses a list.
This has the same functionality as the "reverse" function that was implemented in the "config" package, but adapted to the new language type system.
f3b5274
to
5922f5a
Compare
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
It reverses a list.