# average

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

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

## Signature

```taxi
declare extension function average(values: Any[]):Decimal
```

## Description

Returns the arithmetic mean of a collection of numeric values.

All values in the collection must be of the same numeric primitive type (Int, Decimal, etc.).
Returns null if the collection is empty or contains non-numeric values.

```taxi
find { order: Order } as {
   averageItemPrice: Decimal = order.items.map((Item) -> Item::price).average()
}
```

## Examples

Computes the average score from a collection of items.

Schema:

```taxi
model Item {
   score: Score inherits Decimal
}
```

Query:

```taxi
given {
   items: Item[] = [
      { score: 80.0 },
      { score: 90.0 },
      { score: 70.0 }
   ]
}
find {
   avg: Decimal = average(items.map((item: Item) -> item.score))
}
```

Result:

```json
{
  "avg": 80
}
```
