---
title: "filter(_:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/taskgroup/filter(_:)"
---

# filter(_:)

Creates an asynchronous sequence that contains, in order, the elements of the base sequence that satisfy the given predicate.

## Declaration

```swift
@preconcurrency func filter(_ isIncluded: @escaping @Sendable (Self.Element) async -> Bool) -> AsyncFilterSequence<Self>
```

## Parameters

- `isIncluded`: A closure that takes an element of the asynchronous sequence as its argument and returns a Boolean value that indicates whether to include the element in the filtered sequence.

## Return Value

Return Value An asynchronous sequence that contains, in order, the elements of the base sequence that satisfy the given predicate.

## Discussion

Discussion In this example, an asynchronous sequence called Counter produces Int values from 1 to 10. The filter(_:) method returns true for even values and false for odd values, thereby filtering out the odd values: let stream = Counter(howHigh: 10)     .filter { $0 % 2 == 0 } for await number in stream {     print(number, terminator: " ") } // Prints "2 4 6 8 10 "

## See Also

### Accessing an Asynchronous Sequence of Results

- [makeAsyncIterator()](swift/taskgroup/makeasynciterator().md)
- [allSatisfy(_:)](swift/taskgroup/allsatisfy(_:).md)
- [compactMap(_:)](swift/taskgroup/compactmap(_:)-944od.md)
- [compactMap(_:)](swift/taskgroup/compactmap(_:)-7mgj1.md)
- [contains(_:)](swift/taskgroup/contains(_:).md)
- [contains(where:)](swift/taskgroup/contains(where:).md)
- [drop(while:)](swift/taskgroup/drop(while:).md)
- [dropFirst(_:)](swift/taskgroup/dropfirst(_:).md)
- [first(where:)](swift/taskgroup/first(where:).md)
- [flatMap(_:)](swift/taskgroup/flatmap(_:)-vhi3.md)
- [map(_:)](swift/taskgroup/map(_:)-58nsr.md)
- [map(_:)](swift/taskgroup/map(_:)-4a4kq.md)
- [max()](swift/taskgroup/max().md)
- [max(by:)](swift/taskgroup/max(by:).md)
- [min()](swift/taskgroup/min().md)
