last()
Publishes the last element of a stream, after the stream finishes.
Declaration
func last() -> Publishers.Last<Self>Return Value
A publisher that only publishes the last element of a stream.
Discussion
Use last() when you need to emit only the last element from an upstream publisher.
In the example below, the range publisher only emits the last element from the sequence publisher, 10, then finishes normally.
let numbers = (-10...10)
cancellable = numbers.publisher
.last()
.sink { print("\($0)") }
// Prints: "10"