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

Is it possible to flip or change order of function arguments? #340

Open
MikaelElkiaer opened this issue Apr 10, 2024 · 1 comment
Open

Comments

@MikaelElkiaer
Copy link

I am having a hard time structuring my pipes consistently, due to the fixed order of arguments for template functions.
I would like to change the order of arguments.
Is this at all possible when applying template functions? (Please don't say named templates, that would be a verbose monster)

A couple of examples.

I like reading a pipeline like:

{{ 5 | lt 4 | ternary "yay" "nay" }}

which in my mind I can easily translate into "5, is less than 4, if true 'yay' otherwise 'nay'".

However, for some functions the order is wrong in my opinion, e.g.:

{{ "someKey" | index .Values }}

which I would rather do as:

{{ .Values | index "someKey" }}

This becomes more obvious when the first pipe (piped as last argument) becomes something more dynamic.
In general, I would like the argument which is typically more dynamic to be passed as the last argument.

I would like to do:

{{ include "createSomeDict" . | index "someKey" }}

Which is not actually possible, only by moving around the arguments, such as:

{{ index "someKey" (include "createSomeDict" .) }}
{{!-- or, slightly more perverted --}}
{{ index "someKey" (. | include "createSomeDict") }}

However, it might be possible to do with a flip function, e.g.:

{{ include "createSomeDict" . | flip index "someKey" }}

For F#, I would have defined a function flip:

let flip f x y = f y x

which is basically the same function as the passed argument f, but with flipped order of arguments x and y when flip applies f.
This is not quite what would be possible for Helm, since functions are not first-class citizens and therefore not possible to partially apply a function.

@MikaelElkiaer
Copy link
Author

helm/helm#12135 could be relevant.

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

No branches or pull requests

1 participant