# map

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

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

## Signature

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

## Description

Applies a transformation function to every element in a collection, returning a new array of the results.

If the callback is a type expression, each element is converted to that type:

```taxi
// Convert Person[] to Name[]
Person[].map((Person) -> Name)
```

If the callback is any other expression, it is evaluated against each element:

```taxi
// Return an array of uppercased titles
Film[].map((Title) -> Title.upperCase())
```

## Examples

Extracts a field from each object in a collection, returning a typed array.

Schema:

```taxi
model Product {
   name: Name inherits 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 {
   names: Name[] = products.map((Product) -> Name)
}
```

Result:

```json
{
  "names": [
    "Apple",
    "Banana",
    "Cherry"
  ]
}
```
