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

# first(where:)

Publishes the first element of a stream to satisfy a predicate closure, then finishes normally.

## Declaration

```swift
func first(where predicate: @escaping (Self.Output) -> Bool) -> Publishers.FirstWhere<Self>
```

## Parameters

- `predicate`: A closure that takes an element as a parameter and returns a Boolean value that indicates whether to publish the element.

## Return Value

Return Value A publisher that only publishes the first element of a stream that satisfies the predicate.

## Discussion

Discussion Use first(where:) to republish only the first element of a stream that satisfies a closure you specify. The publisher ignores all elements after the first element that satisfies the closure and finishes normally. If this publisher doesn’t receive any elements, it finishes without publishing. In the example below, the provided closure causes the Publishers.FirstWhere publisher to republish the first received element that’s greater than 0, then finishes normally. let numbers = (-10...10) cancellable = numbers.publisher     .first { $0 > 0 }     .sink { print("\($0)") }

// Prints: "1"

## See Also

### Selecting specific elements

- [first()](combine/publisher/first().md)
- [tryFirst(where:)](combine/publisher/tryfirst(where:).md)
- [last()](combine/publisher/last().md)
- [last(where:)](combine/publisher/last(where:).md)
- [tryLast(where:)](combine/publisher/trylast(where:).md)
- [output(at:)](combine/publisher/output(at:).md)
- [output(in:)](combine/publisher/output(in:).md)
