RemoveDuplicatesAsyncSequence
public struct RemoveDuplicatesAsyncSequence<Base> : AsyncSequence where Base : AsyncSequence, Base.Element : Equatable
extension RemoveDuplicatesAsyncSequence: AsyncIteratorProtocol
An asynchronous sequence that streams only elements from the base asynchronous sequence that don’t match the previous element.
let stream = .init { continuation in
continuation.yield(1)
continuation.yield(1)
continuation.yield(2)
continuation.yield(3)
continuation.finish()
}
for await value in stream.removeDuplicates() {
print(value)
}
// Prints:
// 1
// 2
// 3
-
The kind of elements streamed.
Declaration
Swift
public typealias Element = Base.Element
-
Creates an async that only emits elements that don’t match the previous element, as evaluated by a provided closure.
Declaration
Swift
public init( base: Base, predicate: @escaping Predicate )
Parameters
base
The async sequence in which this sequence receives it’s elements.
predicate
A closure to evaluate whether two elements are equivalent.
-
Creates an async iterator that emits elements of this async sequence.
Declaration
Swift
public func makeAsyncIterator() -> RemoveDuplicatesAsyncSequence<Base>
Return Value
An instance that conforms to
AsyncIteratorProtocol
.
-
next()
AsynchronousProduces the next element in the sequence.
Continues to call
next()
on it’s base iterator and discard the results if the predicate returns true.The first element of the sequence is always returned.
If the base iterator returns
nil
, indicating the end of the sequence, this iterator returnsnil
.Declaration
Swift
public mutating func next() async rethrows -> Element?
Return Value
The next element or
nil
if the end of the sequence is reached.