github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/hcl2/functions/string/formatlist.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: formatlist - Functions - Configuration Language
     4  description: |-
     5    The formatlist function produces a list of strings by formatting a number of
     6    other values according to a specification string.
     7  ---
     8  
     9  # `formatlist` Function
    10  
    11  `formatlist` produces a list of strings by formatting a number of other
    12  values according to a specification string.
    13  
    14  ```hcl
    15  formatlist(spec, values...)
    16  ```
    17  
    18  The specification string uses
    19  [the same syntax as `format`](/docs/job-specification/hcl2/functions/string/format#specification-syntax).
    20  
    21  The given values can be a mixture of list and non-list arguments. Any given
    22  lists must be the same length, which decides the length of the resulting list.
    23  
    24  The list arguments are iterated together in order by index, while the non-list
    25  arguments are used repeatedly for each iteration. The format string is evaluated
    26  once per element of the list arguments.
    27  
    28  ## Examples
    29  
    30  ```shell-session
    31  > formatlist("Hello, %s!", ["Valentina", "Ander", "Olivia", "Sam"])
    32  [
    33    "Hello, Valentina!",
    34    "Hello, Ander!",
    35    "Hello, Olivia!",
    36    "Hello, Sam!",
    37  ]
    38  > formatlist("%s, %s!", "Salutations", ["Valentina", "Ander", "Olivia", "Sam"])
    39  [
    40    "Salutations, Valentina!",
    41    "Salutations, Ander!",
    42    "Salutations, Olivia!",
    43    "Salutations, Sam!",
    44  ]
    45  ```
    46  
    47  ## Related Functions
    48  
    49  - [`format`](/docs/job-specification/hcl2/functions/string/format) defines the specification syntax used by this
    50    function and produces a single string as its result.