# orEmpty

Source: https://taxilang.org/docs/language/stdlib/orEmpty

**Full name:** `taxi.stdlib.orEmpty`

## Signature

```taxi
declare extension function <T> orEmpty(source:T[]): T[]
```

## Description

Returns the source array unchanged if it is non-null, or an empty array if it is `null`.

Useful for safely chaining collection operations on potentially-null fields.

```taxi
find { user: User } as {
   roles: user.roles.orEmpty().joinToString(', ')
}
```

## Examples

Returns the collection unchanged when non-null. Use `.orEmpty()` to safely chain operations on nullable arrays.

Schema:

```taxi
model Cart {
   items: String[]
}
```

Query:

```taxi
given {
   cart: Cart = { items: ['apple', 'banana'] }
}
find {
   items: String[] = cart.items.orEmpty()
}
```

Result:

```json
{
  "items": [
    "apple",
    "banana"
  ]
}
```
