diff --git a/Sources/OpenCombine/Publishers/Publishers.Throttle.swift b/Sources/OpenCombine/Publishers/Publishers.Throttle.swift index 8d435101..6d529a8f 100644 --- a/Sources/OpenCombine/Publishers/Publishers.Throttle.swift +++ b/Sources/OpenCombine/Publishers/Publishers.Throttle.swift @@ -109,7 +109,7 @@ extension Publishers { /// /// Implementations of ``Publisher`` must implement this method. /// - /// The provided implementation of ``Publisher/subscribe(_:)-4u8kn``calls + /// The provided implementation of ``Publisher/subscribe(_:)-199o9``calls /// this method. /// /// - Parameter subscriber: The subscriber to attach to this ``Publisher``, diff --git a/Sources/OpenCombine/Publishers/Publishers.Zip.swift b/Sources/OpenCombine/Publishers/Publishers.Zip.swift index 7e6ba000..7c078944 100644 --- a/Sources/OpenCombine/Publishers/Publishers.Zip.swift +++ b/Sources/OpenCombine/Publishers/Publishers.Zip.swift @@ -43,9 +43,9 @@ extension Publisher { /// Combines elements from another publisher and delivers a transformed output. /// - /// Use ``Publisher/zip(_:_:)-4xn21`` to return a new publisher that combines the elements from two publishers using a transformation you specify to publish a new value to the downstream. The returned publisher waits until both publishers have emitted an event, then delivers the oldest unconsumed event from each publisher together that the operator uses in the transformation. + /// Use ``Publisher/zip(_:_:)-7ve7u`` to return a new publisher that combines the elements from two publishers using a transformation you specify to publish a new value to the downstream. The returned publisher waits until both publishers have emitted an event, then delivers the oldest unconsumed event from each publisher together that the operator uses in the transformation. /// - /// In this example, ``PassthroughSubject`` instances `numbersPub` and `lettersPub` emit values; ``Publisher/zip(_:_:)-4xn21`` receives the oldest value from each publisher, uses the `Int` from `numbersPub` and publishes a string that repeats the from `lettersPub` that many times. + /// In this example, ``PassthroughSubject`` instances `numbersPub` and `lettersPub` emit values; ``Publisher/zip(_:_:)-7ve7u`` receives the oldest value from each publisher, uses the `Int` from `numbersPub` and publishes a string that repeats the [String](https://developer.apple.com/documentation/swift/string) from `lettersPub` that many times. /// /// let numbersPub = PassthroughSubject() /// let lettersPub = PassthroughSubject() @@ -75,10 +75,10 @@ extension Publisher { /// Combines elements from two other publishers and delivers groups of elements as tuples. /// - /// Use ``Publisher/zip(_:_:)-8d7k7`` to return a new publisher that combines the elements from two additional publishers to publish a tuple to the downstream. The returned publisher waits until all three publishers have emitted an event, then delivers the oldest unconsumed event from each publisher as a tuple to the subscriber. + /// Use ``Publisher/zip(_:_:)-2p498`` to return a new publisher that combines the elements from two additional publishers to publish a tuple to the downstream. The returned publisher waits until all three publishers have emitted an event, then delivers the oldest unconsumed event from each publisher as a tuple to the subscriber. /// /// In this example, `numbersPub`, `lettersPub` and `emojiPub` are each a ``PassthroughSubject``; - /// ``Publisher/zip(_:_:)-8d7k7`` receives the oldest unconsumed value from each publisher and combines them into a tuple that it republishes to the downstream: + /// ``Publisher/zip(_:_:)-2p498`` receives the oldest unconsumed value from each publisher and combines them into a tuple that it republishes to the downstream: /// /// let numbersPub = PassthroughSubject() /// let lettersPub = PassthroughSubject() @@ -111,9 +111,9 @@ extension Publisher { /// Combines elements from two other publishers and delivers a transformed output. /// - /// Use ``Publisher/zip(_:_:_:)-9yqi1`` to return a new publisher that combines the elements from two other publishers using a transformation you specify to publish a new value to the downstream subscriber. The returned publisher waits until all three publishers have emitted an event, then delivers the oldest unconsumed event from each publisher together that the operator uses in the transformation. + /// Use ``Publisher/zip(_:_:_:)-19jxo`` to return a new publisher that combines the elements from two other publishers using a transformation you specify to publish a new value to the downstream subscriber. The returned publisher waits until all three publishers have emitted an event, then delivers the oldest unconsumed event from each publisher together that the operator uses in the transformation. /// - /// In this example, `numbersPub`, `lettersPub` and `emojiPub` are each a ``PassthroughSubject`` that emit values; ``Publisher/zip(_:_:_:)-9yqi1`` receives the oldest value from each publisher and uses the `Int` from `numbersPub` and publishes a string that repeats the from `lettersPub` and `emojiPub` that many times. + /// In this example, `numbersPub`, `lettersPub` and `emojiPub` are each a ``PassthroughSubject`` that emit values; ``Publisher/zip(_:_:_:)-19jxo`` receives the oldest value from each publisher and uses the `Int` from `numbersPub` and publishes a string that repeats the [String](https://developer.apple.com/documentation/swift/string) from `lettersPub` and `emojiPub` that many times. /// /// let numbersPub = PassthroughSubject() /// let lettersPub = PassthroughSubject() @@ -150,9 +150,9 @@ extension Publisher { /// Combines elements from three other publishers and delivers groups of elements as tuples. /// - /// Use ``Publisher/zip(_:_:_:)-16rcy`` to return a new publisher that combines the elements from three other publishers to publish a tuple to the downstream subscriber. The returned publisher waits until all four publishers have emitted an event, then delivers the oldest unconsumed event from each publisher as a tuple to the subscriber. + /// Use ``Publisher/zip(_:_:_:)-67czn`` to return a new publisher that combines the elements from three other publishers to publish a tuple to the downstream subscriber. The returned publisher waits until all four publishers have emitted an event, then delivers the oldest unconsumed event from each publisher as a tuple to the subscriber. /// - /// In this example, several ``PassthroughSubject`` instances emit values; ``Publisher/zip(_:_:_:)-16rcy`` receives the oldest unconsumed value from each publisher and combines them into a tuple that it republishes to the downstream: + /// In this example, several ``PassthroughSubject`` instances emit values; ``Publisher/zip(_:_:_:)-67czn`` receives the oldest unconsumed value from each publisher and combines them into a tuple that it republishes to the downstream: /// /// let numbersPub = PassthroughSubject() /// let lettersPub = PassthroughSubject() @@ -192,7 +192,7 @@ extension Publisher { /// Use ``Publisher/zip(_:_:_:_:)`` to return a new publisher that combines the elements from three other publishers using a transformation you specify to publish a new value to the downstream subscriber. The returned publisher waits until all four publishers have emitted an event, then delivers the oldest unconsumed event from each publisher together that the operator uses in the transformation. /// /// In this example, the ``PassthroughSubject`` publishers, `numbersPub`, - /// `fractionsPub`, `lettersPub`, and `emojiPub` emit values. The ``Publisher/zip(_:_:_:_:)`` operator receives the oldest value from each publisher and uses the `Int` from `numbersPub` and publishes a string that repeats the from `lettersPub` and `emojiPub` that many times and prints out the value in `fractionsPub`. + /// `fractionsPub`, `lettersPub`, and `emojiPub` emit values. The ``Publisher/zip(_:_:_:_:)`` operator receives the oldest value from each publisher and uses the `Int` from `numbersPub` and publishes a string that repeats the [String](https://developer.apple.com/documentation/swift/string) from `lettersPub` and `emojiPub` that many times and prints out the value in `fractionsPub`. /// /// let numbersPub = PassthroughSubject() // first publisher /// let lettersPub = PassthroughSubject() // second @@ -269,7 +269,7 @@ extension Publishers { /// /// Implementations of ``Publisher`` must implement this method. /// - /// The provided implementation of ``Publisher/subscribe(_:)-4u8kn``calls this method. + /// The provided implementation of ``Publisher/subscribe(_:)-199o9``calls this method. /// /// - Parameter subscriber: The subscriber to attach to this ``Publisher``, after which it can receive values. public func receive(subscriber: S) where S: Subscriber, B.Failure == S.Failure, S.Input == (A.Output, B.Output) { @@ -320,7 +320,7 @@ extension Publishers { /// /// Implementations of ``Publisher`` must implement this method. /// - /// The provided implementation of ``Publisher/subscribe(_:)-4u8kn``calls this method. + /// The provided implementation of ``Publisher/subscribe(_:)-199o9``calls this method. /// /// - Parameter subscriber: The subscriber to attach to this ``Publisher``, after which it can receive values. public func receive(subscriber: S) where S: Subscriber, C.Failure == S.Failure, S.Input == (A.Output, B.Output, C.Output) { @@ -377,7 +377,7 @@ extension Publishers { /// /// Implementations of ``Publisher`` must implement this method. /// - /// The provided implementation of ``Publisher/subscribe(_:)-4u8kn``calls this method. + /// The provided implementation of ``Publisher/subscribe(_:)-199o9``calls this method. /// /// - Parameter subscriber: The subscriber to attach to this ``Publisher``, after which it can receive values. public func receive(subscriber: S) where S: Subscriber, D.Failure == S.Failure, S.Input == (A.Output, B.Output, C.Output, D.Output) { diff --git a/Tests/OpenCombineTests/PublisherTests/ZipTests.swift b/Tests/OpenCombineTests/PublisherTests/ZipTests.swift index 091ce3de..5c41dc67 100644 --- a/Tests/OpenCombineTests/PublisherTests/ZipTests.swift +++ b/Tests/OpenCombineTests/PublisherTests/ZipTests.swift @@ -771,4 +771,49 @@ final class ZipTests: XCTestCase { XCTAssertEqual(result?.0, 1) XCTAssertEqual(result?.1, 2) } + + func testZipDocumentationDemo() { + let numbersPub = PassthroughSubject() + let lettersPub = PassthroughSubject() + let emojiPub = PassthroughSubject() + let fractionsPub = PassthroughSubject() + let zip = numbersPub + .zip(lettersPub, emojiPub, fractionsPub) { number, letter, emoji, fraction in + "\(String(repeating: emoji, count: number)) \(String(repeating: letter, count: number)) \(fraction)" + } + + let downstreamSubscriber = TrackingSubscriberBase( + receiveSubscription: { $0.request(.unlimited) }) + zip.subscribe(downstreamSubscriber) + XCTAssertEqual( + downstreamSubscriber.history, + [ + .subscription("Zip"), + ] + ) + numbersPub.send(1) // numbersPub: 1 lettersPub: emojiPub: zip output: + numbersPub.send(2) // numbersPub: 1,2 lettersPub: emojiPub: zip output: + numbersPub.send(3) // numbersPub: 1,2,3 lettersPub: emojiPub: zip output: + fractionsPub.send(0.1) // numbersPub: 1,2,3 lettersPub: "A" emojiPub: zip output: + lettersPub.send("A") // numbersPub: 1,2,3 lettersPub: "A" emojiPub: zip output: + emojiPub.send("😀") // numbersPub: 1,2,3 lettersPub: "A" emojiPub:"😀" zip output: "😀 A" + XCTAssertEqual( + downstreamSubscriber.history, + [ + .subscription("Zip"), + .value("😀 A 0.1"), + ] + ) + lettersPub.send("B") // numbersPub: 2,3 lettersPub: "B" emojiPub: zip output: + fractionsPub.send(0.8) // numbersPub: 2,3 lettersPub: "A" emojiPub: zip output: + emojiPub.send("🥰") // numbersPub: 3 lettersPub: "B" emojiPub: zip output: "🥰🥰 BB" + XCTAssertEqual( + downstreamSubscriber.history, + [ + .subscription("Zip"), + .value("😀 A 0.1"), + .value("🥰🥰 BB 0.8") + ] + ) + } }