# filter

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

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

## Signature

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

## Description

Returns a new collection containing only the members of the original collection that match the provided predicate.

This function is used to select a subset of elements from a collection based on a condition.

```taxi
find { store: Store } as {
   allProducts: store.products // all products
   inStockProducts: store.products.filter((product) -> product.stockLevel > 0)
   affordableProducts: store.products.filter((product) -> product.price < 50.00)
}
```

## Examples

Filters a collection by predicate, returning only matching elements. Uses type-based lambda for clean, semantic access.

Schema:

```taxi
model Friend {
   name: Name inherits String
   age: Age inherits Int
}
```

Query:

```taxi
given {
   friends: Friend[] = [
      { name: 'Jim', age: 20 },
      { name: 'Jack', age: 80 },
      { name: 'Alice', age: 75 },
      { name: 'Bob', age: 30 }
   ]
}
find {
   // Names of seniors (over 70)
   seniorFriends: Name[] = friends.filter((Age) -> Age > 70) as Name[]
   // Names of young adults (under 30)
   youngFriends: Name[] = friends.filter((Age) -> Age < 30) as Name[]
}
```

Result:

```json
{
  "seniorFriends": [
    "Jack",
    "Alice"
  ],
  "youngFriends": [
    "Jim"
  ]
}
```
