-
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: Add length to built-in functions #1495
Conversation
I agree that empty strings are often not desired, but I think your length function should count them regardless. I think a common use case will be something like:
In which case, setting foo_list to ",something," would never create an object with Maybe it would be better to have another function that cleans empty strings from a list? I could have used that the other day. |
Could you provide any real example with real resources/options (replacing "some" and "foo"), so it's easier to imagine the use case? |
For that split example, it seems like split should be the one to ignore empty strings |
A contrived example might be if you had a module for managing your DNS:
I might call this module like so:
Let's say Now your I'd argue that's even more confusing than having 7 dnsimple_record resources, with one having an empty value. This is not to mention all the cases where you actually might want empty strings. |
Most of my use cases are related to get the length of a list not a string. |
437b508
to
96de968
Compare
@EvanKrall Thank you for the example. It's worth mentioning that The question I was asking originally was "Is there any use case for empty strings?". Your example is merely pointing to inconsistency between You probably wouldn't want to see empty strings in your example anyway - what's the point of creating DNS records pointing to an empty string? (putting aside the fact that API won't allow you to do that) |
In fact the problem is not just a whitespace, I believe that any character which is used as a delimiter in I can implement that with no issues, but we need to make a decision about |
I like this! For "blank" things, I think we should just have a separate function For strings: I think in the future we need to improve typing to support first class lists (always planned), and use that to determine the behavior. I think for now the behavior in this PR is fine. |
OK, thanks for the input, I will update the PR accordingly then. |
PR updated accordingly, please let me know if there's anything else you'd change or if it's good to go. |
This is looking great - thanks! Merging now. Think you could follow up with a little docs PR? |
config: Add length to built-in functions
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. |
Related issue: #1389
I would really welcome some feedback regarding expected use-cases of this function - i.e. see the test cases and input/output.
I've taken certain assumptions about edge cases like empty members and strings generally.
${length(split(",one,"))}
to return3
, but I can't think of any real use case for empty strings here, so${length(split(",one,"))}
=1
${length("string")}
to return6
instead of1
.I could try and search fordone.InterpSplitDelim
and if it's not there, just treat the input as string.Once you'll be happy with the behaviour, I can add some docs too (and describe the behaviour there as well).
I'm not entirely sure @mitchellh will want to see this implemented before a real support for arrays.