github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/job-specification/hcl2/functions/string/formatlist.mdx (about)

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