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

# last(where:)

Publishes the last element of a stream that satisfies a predicate closure, after upstream finishes.

## Declaration

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

## Parameters

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

## Return Value

Return Value A publisher that only publishes the last element satisfying the given predicate.

## Discussion

Discussion Use last(where:) when you need to republish only the last element of a stream that satisfies a closure you specify. In the example below, a range publisher emits the last element that satisfies the closure’s criteria, then finishes normally: let numbers = (-10...10) cancellable = numbers.publisher     .last { $0 < 6 }     .sink { print("\($0)") }

// Prints: "5"

## See Also

### Selecting specific elements

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