Is it possible to flip or change order of function arguments?
- Dominant language
- No language data
- Stars
- 495
- Forks
- 210
- PR merge metrics
- No merged PRs in 30d
Description
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:
```handlebars
{{ 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.:
```handlebars
{{ "someKey" | index .Values }}
```
which I would rather do as:
```handlebars
{{ .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:
```handlebars
{{ include "createSomeDict" . | index "someKey" }}
```
Which is not actually possible, only by moving around the arguments, such as:
```handlebars
{{ 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.:
```handlebars
{{ include "createSomeDict" . | flip index "someKey" }}
```
For F#, I would have defined a function `flip`:
```fsharp
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.