> ## Documentation Index
> Fetch the complete documentation index at: https://errand.nuvrel.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# length

> Return the number of elements in a collection.

`length(collection)` returns the number of elements in a list, tuple, set, or map.

## Signature

```
length(collection list | set | map | tuple) number
```

## Example

Guard a deployment task so it only runs when at least one target service is specified:

```hcl theme={null}
variable "services" {
  description = "Services to deploy"
  type        = list(string)
  default     = []
}

task "deploy" {
  description = "Deploy the selected services"
  condition   = length(var.services) > 0
  commands = [
    "for svc in ${join(" ", var.services)}; do kubectl rollout restart deployment/$svc; done",
  ]
}
```

When `--var 'services=[]'` is passed or the default is used, the task is skipped. When services are provided, the deployment proceeds.

## Notes

* `length` works on lists, sets, maps, and tuples. It does not work on strings, numbers, or booleans.
* For maps, `length` returns the number of keys.
