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

# first(where:)

Returns the first element of the sequence that satisfies the given predicate.

## Declaration

```swift
func first(where predicate: (Self.Element) async throws -> Bool) async rethrows -> Self.Element?
```

## Parameters

- `predicate`: A closure that takes an element of the asynchronous sequence as its argument and returns a Boolean value that indicates whether the element is a match.

## Return Value

Return Value The first element of the sequence that satisfies predicate, or nil if there is no element that satisfies predicate.

## Discussion

Discussion In this example, an asynchronous sequence called Counter produces Int values from 1 to 10. The first(where:) method returns the first member of the sequence that’s evenly divisible by both 2 and 3. let divisibleBy2And3 = await Counter(howHigh: 10)     .first { $0 % 2 == 0 && $0 % 3 == 0 } print(divisibleBy2And3 ?? "none") // Prints "6" The predicate executes each time the asynchronous sequence produces an element, until either the predicate finds a match or the sequence ends.

## 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)
- [filter(_:)](swift/taskgroup/filter(_:).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)
