反转列表

反转列表中的元素。

深入探索

如需查看包含此代码示例的详细文档,请参阅以下内容:

代码示例

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}

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器