Skip to content

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

@MikaelElkiaer

Description

@MikaelElkiaer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions