# collectAllInstances

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

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

## Signature

```taxi
declare extension function <T> collectAllInstances(collection: lang.taxi.Type<T>): T
```

## Description

Collects and merges all instances of a type from the current data context, bypassing ambiguity checks.

Without this function, a search for `T[]` will return null when multiple separate collections of `T` exist
(the result is considered ambiguous). `collectAllInstances` disables that check and concatenates all found instances
into a single collection.

```taxi
// Merge homeAddresses and workAddresses into one list
find { person: Person } as {
   allAddresses: collectAllInstances(Address)
}
```

## Examples

Merges all `Address` collections on a `Person` into a single flat list, even though they live in separate fields.

Schema:

```taxi
model Address {
   street: Street inherits String
}
model Person {
   name: Name inherits String
   homeAddresses: Address[]
   workAddresses: Address[]
}
```

Query:

```taxi
given {
   person: Person = {
      name: 'Jimmy',
      homeAddresses: [
         { street: 'Oxford St' },
         { street: 'Regent St' }
      ],
      workAddresses: [
         { street: 'Tot St' }
      ]
   }
}
find {
   name: person.name
   allAddresses: collectAllInstances(Address)
}
```

Result:

```json
{
  "name": "Jimmy",
  "allAddresses": [
    {
      "street": "Oxford St"
    },
    {
      "street": "Regent St"
    },
    {
      "street": "Tot St"
    }
  ]
}
```
