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

# contains(where:)

Publishes a Boolean value upon receiving an element that satisfies the predicate closure.

## Declaration

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

## Parameters

- `predicate`: A closure that takes an element as its parameter and returns a Boolean value that indicates whether the element satisfies the closure’s comparison logic.

## Return Value

Return Value A publisher that emits the Boolean value true when the upstream  publisher emits a matching value.

## Discussion

Discussion Use contains(where:) to find the first element in an upstream that satisfies the closure you provide. This operator consumes elements produced from the upstream publisher until the upstream publisher produces a matching element. This operator is useful when the upstream publisher produces elements that don’t conform to Equatable. In the example below, the contains(where:) operator tests elements against the supplied closure and emits true for the first elements that’s greater than 4, and then finishes normally. let numbers = [-1, 0, 10, 5] numbers.publisher     .contains {$0 > 4}     .sink { print("\($0)") }

// Prints: "true"

## See Also

### Applying matching criteria to elements

- [contains(_:)](combine/publisher/contains(_:).md)
- [tryContains(where:)](combine/publisher/trycontains(where:).md)
- [allSatisfy(_:)](combine/publisher/allsatisfy(_:).md)
- [tryAllSatisfy(_:)](combine/publisher/tryallsatisfy(_:).md)
