Reverse a list

Reverses the elements in a list.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

YAML

# Reverse the order of elements in a list
# Expected output: `[3,2,1]`
main:
  steps:
    - call_reverse_list:
        call: reverse_list
        args:
          source: [1, 2, 3]
        result: output
    - return_message:
        return: ${output}

reverse_list:
  params: [source]
  steps:
    - init:
        assign:
          - dst: []
    - reverse:
        for:
          value: entry
          in: ${source}
          steps:
            - prepend_value:
                assign:
                  - dst: ${list.prepend(dst, entry)}
    - return_destination:
        return: ${dst}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.