---
page_title: coalescelist function reference
description: |-
  The `coalescelist` function returns the first non-empty argument in a list of arguments. Learn how to use the `coalescelist` function in Packer templates.
---

⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
> [!IMPORTANT]  
> **Documentation Update:** Product documentation previously located in `/website` has moved to the [`hashicorp/web-unified-docs`](https://github.com/hashicorp/web-unified-docs) repository, where all product documentation is now centralized. Please make contributions directly to `web-unified-docs`, since changes to `/website` in this repository will not appear on developer.hashicorp.com.
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

# `coalescelist` Function

`coalescelist` takes any number of list arguments and returns the first one
that isn't empty.

## Examples

```shell-session
> coalescelist(["a", "b"], ["c", "d"])
[
  "a",
  "b",
]
> coalescelist([], ["c", "d"])
[
  "c",
  "d",
]
```

To perform the `coalescelist` operation with a list of lists, use the `...`
symbol to expand the outer list as arguments:

```shell-session
> coalescelist([[], ["c", "d"]]...)
[
  "c",
  "d",
]
```

## Related Functions

- [`coalesce`](/packer/docs/templates/hcl_templates/functions/collection/coalesce) performs a similar operation with string
  arguments rather than list arguments.
