Zip3AsyncSequence

public struct Zip3AsyncSequence<P, Q, R> : AsyncSequence where P : AsyncSequence, Q : AsyncSequence, R : AsyncSequence
extension Zip3AsyncSequence: AsyncIteratorProtocol

An asynchronous sequence that applys a zip function to the three async sequences.

Use Zip3AsyncSequence to combine the latest elements from three async sequcnes and emit a tuple.

The async sequence waits until both provided async sequences have emitted an element, then emits both elements as a tuple.

If one sequence never emits a value or raises an error then the zipped sequence will finish.

let streamA = .init { continuation in
    continuation.yield(1)
    continuation.yield(2)
    continuation.finish()
}

let streamB = .init { continuation in
    continuation.yield(5)
    continuation.yield(6)
    continuation.yield(7)
    continuation.finish()
}

let streamC = .init { continuation in
    continuation.yield(8)
    continuation.yield(9)
    continuation.finish()
}

for await value in streamA.zip(streamB, streamC) {
    print(value)
}

// Prints:
// (1, 5, 8)
// (2, 6, 9)
  • The kind of elements streamed.

    Declaration

    Swift

    public typealias Element = (P.Element, Q.Element, R.Element)

AsyncSequence

  • Creates an async iterator that emits elements of this async sequence.

    Declaration

    Swift

    public func makeAsyncIterator() -> Zip3AsyncSequence<P, Q, R>

    Return Value

    An instance that conforms to AsyncIteratorProtocol.

AsyncIteratorProtocol

  • next() Asynchronous

    Produces the next element in the sequence.

    Continues to call next() on it’s base iterator and iterator of it’s combined sequence.

    If any iterator returns nil, indicating the end of the sequence, this iterator returns nil.

    Declaration

    Swift

    public mutating func next() async rethrows -> Element?

    Return Value

    The next element or nil if the end of the sequence is reached.