# sum

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

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

## Signature

```taxi
declare extension function <T,A> sum(collection: T[], callback: (T) -> A):A
```

## Description

Returns the sum of values in the collection, computed by applying the selector function to each element.

```taxi
find { order: Order } as {
   total: Price = order.items.sum((Item) -> Price)
}
```

## Examples

Sums a numeric field across all elements of a collection.

Schema:

```taxi
model Product {
   name: String
   price: Price inherits Decimal
}
```

Query:

```taxi
given {
   products: Product[] = [
      { name: 'Apple', price: 1.50 },
      { name: 'Banana', price: 0.75 },
      { name: 'Cherry', price: 3.00 }
   ]
}
find {
   totalPrice: Price = products.sum((Product) -> Price)
}
```

Result:

```json
{
  "totalPrice": 5.25
}
```
