# ifEmpty

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

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

## Signature

```taxi
declare extension function <T> ifEmpty(source:T[], defaultValue:T[]): T[]
```

## Description

Returns the source array if it is non-empty, otherwise returns the provided default array.

```taxi
find { order: Order } as {
   tags: order.tags.ifEmpty(['untagged'])
}
```

## Examples

Returns the default array when the source is empty, or the source array when it has elements.

Schema:

```taxi
model Order {
   tags: String[]
}
```

Query:

```taxi
given {
   emptyOrder: Order = { tags: [] },
   fullOrder: Order = { tags: ['express', 'gift'] }
}
find {
   emptyTags: String[] = emptyOrder.tags.ifEmpty(['standard'])
   fullTags: String[] = fullOrder.tags.ifEmpty(['standard'])
}
```

Result:

```json
{
  "emptyTags": [
    "standard"
  ],
  "fullTags": [
    "express",
    "gift"
  ]
}
```
