WIP Publishers.Merge

This commit is contained in:
Sergej Jaskiewicz
2019-10-04 15:56:28 +03:00
parent f861335dc3
commit af0ae86407
6 changed files with 1907 additions and 480 deletions
-480
View File
@@ -261,396 +261,6 @@ extension Publisher {
public func prefix<P>(untilOutputFrom publisher: P) -> Publishers.PrefixUntilOutput<Self, P> where P : Publisher
}
extension Publishers {
/// A publisher created by applying the merge function to two upstream publishers.
public struct Merge<A, B> : Publisher where A : Publisher, B : Publisher, A.Failure == B.Failure, A.Output == B.Output {
/// The kind of values published by this publisher.
public typealias Output = A.Output
/// The kind of errors this publisher might publish.
///
/// Use `Never` if this `Publisher` does not publish errors.
public typealias Failure = A.Failure
public let a: A
public let b: B
public init(_ a: A, _ b: B)
/// This function is called to attach the specified `Subscriber` to this `Publisher` by `subscribe(_:)`
///
/// - SeeAlso: `subscribe(_:)`
/// - Parameters:
/// - subscriber: The subscriber to attach to this `Publisher`.
/// once attached it can begin to receive values.
public func receive<S>(subscriber: S) where S : Subscriber, B.Failure == S.Failure, B.Output == S.Input
public func merge<P>(with other: P) -> Publishers.Merge3<A, B, P> where P : Publisher, B.Failure == P.Failure, B.Output == P.Output
public func merge<Z, Y>(with z: Z, _ y: Y) -> Publishers.Merge4<A, B, Z, Y> where Z : Publisher, Y : Publisher, B.Failure == Z.Failure, B.Output == Z.Output, Z.Failure == Y.Failure, Z.Output == Y.Output
public func merge<Z, Y, X>(with z: Z, _ y: Y, _ x: X) -> Publishers.Merge5<A, B, Z, Y, X> where Z : Publisher, Y : Publisher, X : Publisher, B.Failure == Z.Failure, B.Output == Z.Output, Z.Failure == Y.Failure, Z.Output == Y.Output, Y.Failure == X.Failure, Y.Output == X.Output
public func merge<Z, Y, X, W>(with z: Z, _ y: Y, _ x: X, _ w: W) -> Publishers.Merge6<A, B, Z, Y, X, W> where Z : Publisher, Y : Publisher, X : Publisher, W : Publisher, B.Failure == Z.Failure, B.Output == Z.Output, Z.Failure == Y.Failure, Z.Output == Y.Output, Y.Failure == X.Failure, Y.Output == X.Output, X.Failure == W.Failure, X.Output == W.Output
public func merge<Z, Y, X, W, V>(with z: Z, _ y: Y, _ x: X, _ w: W, _ v: V) -> Publishers.Merge7<A, B, Z, Y, X, W, V> where Z : Publisher, Y : Publisher, X : Publisher, W : Publisher, V : Publisher, B.Failure == Z.Failure, B.Output == Z.Output, Z.Failure == Y.Failure, Z.Output == Y.Output, Y.Failure == X.Failure, Y.Output == X.Output, X.Failure == W.Failure, X.Output == W.Output, W.Failure == V.Failure, W.Output == V.Output
public func merge<Z, Y, X, W, V, U>(with z: Z, _ y: Y, _ x: X, _ w: W, _ v: V, _ u: U) -> Publishers.Merge8<A, B, Z, Y, X, W, V, U> where Z : Publisher, Y : Publisher, X : Publisher, W : Publisher, V : Publisher, U : Publisher, B.Failure == Z.Failure, B.Output == Z.Output, Z.Failure == Y.Failure, Z.Output == Y.Output, Y.Failure == X.Failure, Y.Output == X.Output, X.Failure == W.Failure, X.Output == W.Output, W.Failure == V.Failure, W.Output == V.Output, V.Failure == U.Failure, V.Output == U.Output
}
/// A publisher created by applying the merge function to three upstream publishers.
public struct Merge3<A, B, C> : Publisher where A : Publisher, B : Publisher, C : Publisher, A.Failure == B.Failure, A.Output == B.Output, B.Failure == C.Failure, B.Output == C.Output {
/// The kind of values published by this publisher.
public typealias Output = A.Output
/// The kind of errors this publisher might publish.
///
/// Use `Never` if this `Publisher` does not publish errors.
public typealias Failure = A.Failure
public let a: A
public let b: B
public let c: C
public init(_ a: A, _ b: B, _ c: C)
/// This function is called to attach the specified `Subscriber` to this `Publisher` by `subscribe(_:)`
///
/// - SeeAlso: `subscribe(_:)`
/// - Parameters:
/// - subscriber: The subscriber to attach to this `Publisher`.
/// once attached it can begin to receive values.
public func receive<S>(subscriber: S) where S : Subscriber, C.Failure == S.Failure, C.Output == S.Input
public func merge<P>(with other: P) -> Publishers.Merge4<A, B, C, P> where P : Publisher, C.Failure == P.Failure, C.Output == P.Output
public func merge<Z, Y>(with z: Z, _ y: Y) -> Publishers.Merge5<A, B, C, Z, Y> where Z : Publisher, Y : Publisher, C.Failure == Z.Failure, C.Output == Z.Output, Z.Failure == Y.Failure, Z.Output == Y.Output
public func merge<Z, Y, X>(with z: Z, _ y: Y, _ x: X) -> Publishers.Merge6<A, B, C, Z, Y, X> where Z : Publisher, Y : Publisher, X : Publisher, C.Failure == Z.Failure, C.Output == Z.Output, Z.Failure == Y.Failure, Z.Output == Y.Output, Y.Failure == X.Failure, Y.Output == X.Output
public func merge<Z, Y, X, W>(with z: Z, _ y: Y, _ x: X, _ w: W) -> Publishers.Merge7<A, B, C, Z, Y, X, W> where Z : Publisher, Y : Publisher, X : Publisher, W : Publisher, C.Failure == Z.Failure, C.Output == Z.Output, Z.Failure == Y.Failure, Z.Output == Y.Output, Y.Failure == X.Failure, Y.Output == X.Output, X.Failure == W.Failure, X.Output == W.Output
public func merge<Z, Y, X, W, V>(with z: Z, _ y: Y, _ x: X, _ w: W, _ v: V) -> Publishers.Merge8<A, B, C, Z, Y, X, W, V> where Z : Publisher, Y : Publisher, X : Publisher, W : Publisher, V : Publisher, C.Failure == Z.Failure, C.Output == Z.Output, Z.Failure == Y.Failure, Z.Output == Y.Output, Y.Failure == X.Failure, Y.Output == X.Output, X.Failure == W.Failure, X.Output == W.Output, W.Failure == V.Failure, W.Output == V.Output
}
/// A publisher created by applying the merge function to four upstream publishers.
public struct Merge4<A, B, C, D> : Publisher where A : Publisher, B : Publisher, C : Publisher, D : Publisher, A.Failure == B.Failure, A.Output == B.Output, B.Failure == C.Failure, B.Output == C.Output, C.Failure == D.Failure, C.Output == D.Output {
/// The kind of values published by this publisher.
public typealias Output = A.Output
/// The kind of errors this publisher might publish.
///
/// Use `Never` if this `Publisher` does not publish errors.
public typealias Failure = A.Failure
public let a: A
public let b: B
public let c: C
public let d: D
public init(_ a: A, _ b: B, _ c: C, _ d: D)
/// This function is called to attach the specified `Subscriber` to this `Publisher` by `subscribe(_:)`
///
/// - SeeAlso: `subscribe(_:)`
/// - Parameters:
/// - subscriber: The subscriber to attach to this `Publisher`.
/// once attached it can begin to receive values.
public func receive<S>(subscriber: S) where S : Subscriber, D.Failure == S.Failure, D.Output == S.Input
public func merge<P>(with other: P) -> Publishers.Merge5<A, B, C, D, P> where P : Publisher, D.Failure == P.Failure, D.Output == P.Output
public func merge<Z, Y>(with z: Z, _ y: Y) -> Publishers.Merge6<A, B, C, D, Z, Y> where Z : Publisher, Y : Publisher, D.Failure == Z.Failure, D.Output == Z.Output, Z.Failure == Y.Failure, Z.Output == Y.Output
public func merge<Z, Y, X>(with z: Z, _ y: Y, _ x: X) -> Publishers.Merge7<A, B, C, D, Z, Y, X> where Z : Publisher, Y : Publisher, X : Publisher, D.Failure == Z.Failure, D.Output == Z.Output, Z.Failure == Y.Failure, Z.Output == Y.Output, Y.Failure == X.Failure, Y.Output == X.Output
public func merge<Z, Y, X, W>(with z: Z, _ y: Y, _ x: X, _ w: W) -> Publishers.Merge8<A, B, C, D, Z, Y, X, W> where Z : Publisher, Y : Publisher, X : Publisher, W : Publisher, D.Failure == Z.Failure, D.Output == Z.Output, Z.Failure == Y.Failure, Z.Output == Y.Output, Y.Failure == X.Failure, Y.Output == X.Output, X.Failure == W.Failure, X.Output == W.Output
}
/// A publisher created by applying the merge function to five upstream publishers.
public struct Merge5<A, B, C, D, E> : Publisher where A : Publisher, B : Publisher, C : Publisher, D : Publisher, E : Publisher, A.Failure == B.Failure, A.Output == B.Output, B.Failure == C.Failure, B.Output == C.Output, C.Failure == D.Failure, C.Output == D.Output, D.Failure == E.Failure, D.Output == E.Output {
/// The kind of values published by this publisher.
public typealias Output = A.Output
/// The kind of errors this publisher might publish.
///
/// Use `Never` if this `Publisher` does not publish errors.
public typealias Failure = A.Failure
public let a: A
public let b: B
public let c: C
public let d: D
public let e: E
public init(_ a: A, _ b: B, _ c: C, _ d: D, _ e: E)
/// This function is called to attach the specified `Subscriber` to this `Publisher` by `subscribe(_:)`
///
/// - SeeAlso: `subscribe(_:)`
/// - Parameters:
/// - subscriber: The subscriber to attach to this `Publisher`.
/// once attached it can begin to receive values.
public func receive<S>(subscriber: S) where S : Subscriber, E.Failure == S.Failure, E.Output == S.Input
public func merge<P>(with other: P) -> Publishers.Merge6<A, B, C, D, E, P> where P : Publisher, E.Failure == P.Failure, E.Output == P.Output
public func merge<Z, Y>(with z: Z, _ y: Y) -> Publishers.Merge7<A, B, C, D, E, Z, Y> where Z : Publisher, Y : Publisher, E.Failure == Z.Failure, E.Output == Z.Output, Z.Failure == Y.Failure, Z.Output == Y.Output
public func merge<Z, Y, X>(with z: Z, _ y: Y, _ x: X) -> Publishers.Merge8<A, B, C, D, E, Z, Y, X> where Z : Publisher, Y : Publisher, X : Publisher, E.Failure == Z.Failure, E.Output == Z.Output, Z.Failure == Y.Failure, Z.Output == Y.Output, Y.Failure == X.Failure, Y.Output == X.Output
}
/// A publisher created by applying the merge function to six upstream publishers.
public struct Merge6<A, B, C, D, E, F> : Publisher where A : Publisher, B : Publisher, C : Publisher, D : Publisher, E : Publisher, F : Publisher, A.Failure == B.Failure, A.Output == B.Output, B.Failure == C.Failure, B.Output == C.Output, C.Failure == D.Failure, C.Output == D.Output, D.Failure == E.Failure, D.Output == E.Output, E.Failure == F.Failure, E.Output == F.Output {
/// The kind of values published by this publisher.
public typealias Output = A.Output
/// The kind of errors this publisher might publish.
///
/// Use `Never` if this `Publisher` does not publish errors.
public typealias Failure = A.Failure
public let a: A
public let b: B
public let c: C
public let d: D
public let e: E
public let f: F
public init(_ a: A, _ b: B, _ c: C, _ d: D, _ e: E, _ f: F)
/// This function is called to attach the specified `Subscriber` to this `Publisher` by `subscribe(_:)`
///
/// - SeeAlso: `subscribe(_:)`
/// - Parameters:
/// - subscriber: The subscriber to attach to this `Publisher`.
/// once attached it can begin to receive values.
public func receive<S>(subscriber: S) where S : Subscriber, F.Failure == S.Failure, F.Output == S.Input
public func merge<P>(with other: P) -> Publishers.Merge7<A, B, C, D, E, F, P> where P : Publisher, F.Failure == P.Failure, F.Output == P.Output
public func merge<Z, Y>(with z: Z, _ y: Y) -> Publishers.Merge8<A, B, C, D, E, F, Z, Y> where Z : Publisher, Y : Publisher, F.Failure == Z.Failure, F.Output == Z.Output, Z.Failure == Y.Failure, Z.Output == Y.Output
}
/// A publisher created by applying the merge function to seven upstream publishers.
public struct Merge7<A, B, C, D, E, F, G> : Publisher where A : Publisher, B : Publisher, C : Publisher, D : Publisher, E : Publisher, F : Publisher, G : Publisher, A.Failure == B.Failure, A.Output == B.Output, B.Failure == C.Failure, B.Output == C.Output, C.Failure == D.Failure, C.Output == D.Output, D.Failure == E.Failure, D.Output == E.Output, E.Failure == F.Failure, E.Output == F.Output, F.Failure == G.Failure, F.Output == G.Output {
/// The kind of values published by this publisher.
public typealias Output = A.Output
/// The kind of errors this publisher might publish.
///
/// Use `Never` if this `Publisher` does not publish errors.
public typealias Failure = A.Failure
public let a: A
public let b: B
public let c: C
public let d: D
public let e: E
public let f: F
public let g: G
public init(_ a: A, _ b: B, _ c: C, _ d: D, _ e: E, _ f: F, _ g: G)
/// This function is called to attach the specified `Subscriber` to this `Publisher` by `subscribe(_:)`
///
/// - SeeAlso: `subscribe(_:)`
/// - Parameters:
/// - subscriber: The subscriber to attach to this `Publisher`.
/// once attached it can begin to receive values.
public func receive<S>(subscriber: S) where S : Subscriber, G.Failure == S.Failure, G.Output == S.Input
public func merge<P>(with other: P) -> Publishers.Merge8<A, B, C, D, E, F, G, P> where P : Publisher, G.Failure == P.Failure, G.Output == P.Output
}
/// A publisher created by applying the merge function to eight upstream publishers.
public struct Merge8<A, B, C, D, E, F, G, H> : Publisher where A : Publisher, B : Publisher, C : Publisher, D : Publisher, E : Publisher, F : Publisher, G : Publisher, H : Publisher, A.Failure == B.Failure, A.Output == B.Output, B.Failure == C.Failure, B.Output == C.Output, C.Failure == D.Failure, C.Output == D.Output, D.Failure == E.Failure, D.Output == E.Output, E.Failure == F.Failure, E.Output == F.Output, F.Failure == G.Failure, F.Output == G.Output, G.Failure == H.Failure, G.Output == H.Output {
/// The kind of values published by this publisher.
public typealias Output = A.Output
/// The kind of errors this publisher might publish.
///
/// Use `Never` if this `Publisher` does not publish errors.
public typealias Failure = A.Failure
public let a: A
public let b: B
public let c: C
public let d: D
public let e: E
public let f: F
public let g: G
public let h: H
public init(_ a: A, _ b: B, _ c: C, _ d: D, _ e: E, _ f: F, _ g: G, _ h: H)
/// This function is called to attach the specified `Subscriber` to this `Publisher` by `subscribe(_:)`
///
/// - SeeAlso: `subscribe(_:)`
/// - Parameters:
/// - subscriber: The subscriber to attach to this `Publisher`.
/// once attached it can begin to receive values.
public func receive<S>(subscriber: S) where S : Subscriber, H.Failure == S.Failure, H.Output == S.Input
}
public struct MergeMany<Upstream> : Publisher where Upstream : Publisher {
/// The kind of values published by this publisher.
public typealias Output = Upstream.Output
/// The kind of errors this publisher might publish.
///
/// Use `Never` if this `Publisher` does not publish errors.
public typealias Failure = Upstream.Failure
public let publishers: [Upstream]
public init(_ upstream: Upstream...)
public init<S>(_ upstream: S) where Upstream == S.Element, S : Sequence
/// This function is called to attach the specified `Subscriber` to this `Publisher` by `subscribe(_:)`
///
/// - SeeAlso: `subscribe(_:)`
/// - Parameters:
/// - subscriber: The subscriber to attach to this `Publisher`.
/// once attached it can begin to receive values.
public func receive<S>(subscriber: S) where S : Subscriber, Upstream.Failure == S.Failure, Upstream.Output == S.Input
public func merge(with other: Upstream) -> Publishers.MergeMany<Upstream>
}
}
extension Publisher {
/// Combines elements from this publisher with those from another publisher, delivering an interleaved sequence of elements.
///
/// The merged publisher continues to emit elements until all upstream publishers finish. If an upstream publisher produces an error, the merged publisher fails with that error.
/// - Parameter other: Another publisher.
/// - Returns: A publisher that emits an event when either upstream publisher emits an event.
public func merge<P>(with other: P) -> Publishers.Merge<Self, P> where P : Publisher, Self.Failure == P.Failure, Self.Output == P.Output
/// Combines elements from this publisher with those from two other publishers, delivering an interleaved sequence of elements.
///
/// The merged publisher continues to emit elements until all upstream publishers finish. If an upstream publisher produces an error, the merged publisher fails with that error.
///
/// - Parameters:
/// - b: A second publisher.
/// - c: A third publisher.
/// - Returns: A publisher that emits an event when any upstream publisher emits
/// an event.
public func merge<B, C>(with b: B, _ c: C) -> Publishers.Merge3<Self, B, C> where B : Publisher, C : Publisher, Self.Failure == B.Failure, Self.Output == B.Output, B.Failure == C.Failure, B.Output == C.Output
/// Combines elements from this publisher with those from three other publishers, delivering
/// an interleaved sequence of elements.
///
/// The merged publisher continues to emit elements until all upstream publishers finish. If an upstream publisher produces an error, the merged publisher fails with that error.
///
/// - Parameters:
/// - b: A second publisher.
/// - c: A third publisher.
/// - d: A fourth publisher.
/// - Returns: A publisher that emits an event when any upstream publisher emits an event.
public func merge<B, C, D>(with b: B, _ c: C, _ d: D) -> Publishers.Merge4<Self, B, C, D> where B : Publisher, C : Publisher, D : Publisher, Self.Failure == B.Failure, Self.Output == B.Output, B.Failure == C.Failure, B.Output == C.Output, C.Failure == D.Failure, C.Output == D.Output
/// Combines elements from this publisher with those from four other publishers, delivering an interleaved sequence of elements.
///
/// The merged publisher continues to emit elements until all upstream publishers finish. If an upstream publisher produces an error, the merged publisher fails with that error.
///
/// - Parameters:
/// - b: A second publisher.
/// - c: A third publisher.
/// - d: A fourth publisher.
/// - e: A fifth publisher.
/// - Returns: A publisher that emits an event when any upstream publisher emits an event.
public func merge<B, C, D, E>(with b: B, _ c: C, _ d: D, _ e: E) -> Publishers.Merge5<Self, B, C, D, E> where B : Publisher, C : Publisher, D : Publisher, E : Publisher, Self.Failure == B.Failure, Self.Output == B.Output, B.Failure == C.Failure, B.Output == C.Output, C.Failure == D.Failure, C.Output == D.Output, D.Failure == E.Failure, D.Output == E.Output
/// Combines elements from this publisher with those from five other publishers, delivering an interleaved sequence of elements.
///
/// The merged publisher continues to emit elements until all upstream publishers finish. If an upstream publisher produces an error, the merged publisher fails with that error.
///
/// - Parameters:
/// - b: A second publisher.
/// - c: A third publisher.
/// - d: A fourth publisher.
/// - e: A fifth publisher.
/// - f: A sixth publisher.
/// - Returns: A publisher that emits an event when any upstream publisher emits an event.
public func merge<B, C, D, E, F>(with b: B, _ c: C, _ d: D, _ e: E, _ f: F) -> Publishers.Merge6<Self, B, C, D, E, F> where B : Publisher, C : Publisher, D : Publisher, E : Publisher, F : Publisher, Self.Failure == B.Failure, Self.Output == B.Output, B.Failure == C.Failure, B.Output == C.Output, C.Failure == D.Failure, C.Output == D.Output, D.Failure == E.Failure, D.Output == E.Output, E.Failure == F.Failure, E.Output == F.Output
/// Combines elements from this publisher with those from six other publishers, delivering an interleaved sequence of elements.
///
/// The merged publisher continues to emit elements until all upstream publishers finish. If an upstream publisher produces an error, the merged publisher fails with that error.
///
/// - Parameters:
/// - b: A second publisher.
/// - c: A third publisher.
/// - d: A fourth publisher.
/// - e: A fifth publisher.
/// - f: A sixth publisher.
/// - g: A seventh publisher.
/// - Returns: A publisher that emits an event when any upstream publisher emits an event.
public func merge<B, C, D, E, F, G>(with b: B, _ c: C, _ d: D, _ e: E, _ f: F, _ g: G) -> Publishers.Merge7<Self, B, C, D, E, F, G> where B : Publisher, C : Publisher, D : Publisher, E : Publisher, F : Publisher, G : Publisher, Self.Failure == B.Failure, Self.Output == B.Output, B.Failure == C.Failure, B.Output == C.Output, C.Failure == D.Failure, C.Output == D.Output, D.Failure == E.Failure, D.Output == E.Output, E.Failure == F.Failure, E.Output == F.Output, F.Failure == G.Failure, F.Output == G.Output
/// Combines elements from this publisher with those from seven other publishers, delivering an interleaved sequence of elements.
///
/// The merged publisher continues to emit elements until all upstream publishers finish. If an upstream publisher produces an error, the merged publisher fails with that error.
///
/// - Parameters:
/// - b: A second publisher.
/// - c: A third publisher.
/// - d: A fourth publisher.
/// - e: A fifth publisher.
/// - f: A sixth publisher.
/// - g: A seventh publisher.
/// - h: An eighth publisher.
/// - Returns: A publisher that emits an event when any upstream publisher emits an event.
public func merge<B, C, D, E, F, G, H>(with b: B, _ c: C, _ d: D, _ e: E, _ f: F, _ g: G, _ h: H) -> Publishers.Merge8<Self, B, C, D, E, F, G, H> where B : Publisher, C : Publisher, D : Publisher, E : Publisher, F : Publisher, G : Publisher, H : Publisher, Self.Failure == B.Failure, Self.Output == B.Output, B.Failure == C.Failure, B.Output == C.Output, C.Failure == D.Failure, C.Output == D.Output, D.Failure == E.Failure, D.Output == E.Output, E.Failure == F.Failure, E.Output == F.Output, F.Failure == G.Failure, F.Output == G.Output, G.Failure == H.Failure, G.Output == H.Output
/// Combines elements from this publisher with those from another publisher of the same type, delivering an interleaved sequence of elements.
///
/// - Parameter other: Another publisher of this publisher's type.
/// - Returns: A publisher that emits an event when either upstream publisher emits
/// an event.
public func merge(with other: Self) -> Publishers.MergeMany<Self>
}
extension Publishers {
/// A publisher that flattens nested publishers.
@@ -1310,96 +920,6 @@ extension Publishers.CombineLatest4 : Equatable where A : Equatable, B : Equatab
public static func == (lhs: Publishers.CombineLatest4<A, B, C, D>, rhs: Publishers.CombineLatest4<A, B, C, D>) -> Bool
}
extension Publishers.Merge : Equatable where A : Equatable, B : Equatable {
/// Returns a Boolean value that indicates whether two publishers are equivalent.
///
/// - Parameters:
/// - lhs: A merging publisher to compare for equality.
/// - rhs: Another merging publisher to compare for equality..
/// - Returns: `true` if the two merging - rhs: Another merging publisher to compare for equality.
public static func == (lhs: Publishers.Merge<A, B>, rhs: Publishers.Merge<A, B>) -> Bool
}
extension Publishers.Merge3 : Equatable where A : Equatable, B : Equatable, C : Equatable {
/// Returns a Boolean value that indicates whether two publishers are equivalent.
///
/// - Parameters:
/// - lhs: A merging publisher to compare for equality.
/// - rhs: Another merging publisher to compare for equality.
/// - Returns: `true` if the two merging publishers have equal source publishers, `false` otherwise.
public static func == (lhs: Publishers.Merge3<A, B, C>, rhs: Publishers.Merge3<A, B, C>) -> Bool
}
extension Publishers.Merge4 : Equatable where A : Equatable, B : Equatable, C : Equatable, D : Equatable {
/// Returns a Boolean value that indicates whether two publishers are equivalent.
///
/// - Parameters:
/// - lhs: A merging publisher to compare for equality.
/// - rhs: Another merging publisher to compare for equality.
/// - Returns: `true` if the two merging publishers have equal source publishers, `false` otherwise.
public static func == (lhs: Publishers.Merge4<A, B, C, D>, rhs: Publishers.Merge4<A, B, C, D>) -> Bool
}
extension Publishers.Merge5 : Equatable where A : Equatable, B : Equatable, C : Equatable, D : Equatable, E : Equatable {
/// Returns a Boolean value that indicates whether two publishers are equivalent.
///
/// - Parameters:
/// - lhs: A merging publisher to compare for equality.
/// - rhs: Another merging publisher to compare for equality.
/// - Returns: `true` if the two merging publishers have equal source publishers, `false` otherwise.
public static func == (lhs: Publishers.Merge5<A, B, C, D, E>, rhs: Publishers.Merge5<A, B, C, D, E>) -> Bool
}
extension Publishers.Merge6 : Equatable where A : Equatable, B : Equatable, C : Equatable, D : Equatable, E : Equatable, F : Equatable {
/// Returns a Boolean value that indicates whether two publishers are equivalent.
///
/// - Parameters:
/// - lhs: A merging publisher to compare for equality.
/// - rhs: Another merging publisher to compare for equality.
/// - Returns: `true` if the two merging publishers have equal source publishers, `false` otherwise.
public static func == (lhs: Publishers.Merge6<A, B, C, D, E, F>, rhs: Publishers.Merge6<A, B, C, D, E, F>) -> Bool
}
extension Publishers.Merge7 : Equatable where A : Equatable, B : Equatable, C : Equatable, D : Equatable, E : Equatable, F : Equatable, G : Equatable {
/// Returns a Boolean value that indicates whether two publishers are equivalent.
///
/// - Parameters:
/// - lhs: A merging publisher to compare for equality.
/// - rhs: Another merging publisher to compare for equality.
/// - Returns: `true` if the two merging publishers have equal source publishers, `false` otherwise.
public static func == (lhs: Publishers.Merge7<A, B, C, D, E, F, G>, rhs: Publishers.Merge7<A, B, C, D, E, F, G>) -> Bool
}
extension Publishers.Merge8 : Equatable where A : Equatable, B : Equatable, C : Equatable, D : Equatable, E : Equatable, F : Equatable, G : Equatable, H : Equatable {
/// Returns a Boolean value that indicates whether two publishers are equivalent.
///
/// - Parameters:
/// - lhs: A merging publisher to compare for equality.
/// - rhs: Another merging publisher to compare for equality.
/// - Returns: `true` if the two merging publishers have equal source publishers, `false` otherwise.
public static func == (lhs: Publishers.Merge8<A, B, C, D, E, F, G, H>, rhs: Publishers.Merge8<A, B, C, D, E, F, G, H>) -> Bool
}
extension Publishers.MergeMany : Equatable where Upstream : Equatable {
/// Returns a Boolean value indicating whether two values are equal.
///
/// Equality is the inverse of inequality. For any values `a` and `b`,
/// `a == b` implies that `a != b` is `false`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
public static func == (lhs: Publishers.MergeMany<Upstream>, rhs: Publishers.MergeMany<Upstream>) -> Bool
}
extension Publishers.Retry : Equatable where Upstream : Equatable {
/// Returns a Boolean value indicating whether two values are equal.
@@ -0,0 +1,952 @@
//
//
// Auto-generated from GYB template. DO NOT EDIT!
//
//
//
//
// Publishers.Merge.swift.gyb
//
//
// Created by Sergej Jaskiewicz on 04/10/2019.
//
// swiftlint:disable generic_type_name
// swiftlint:disable vertical_parameter_alignment
// MARK: - Merge methods on Publisher
extension Publisher {
/// Combines elements from this publisher with those from another publisher,
/// delivering an interleaved sequence of elements.
///
/// The merged publisher continues to emit elements until all upstream publishers
/// finish. If an upstream publisher produces an error, the merged publisher fails
/// with that error.
///
/// - Parameters:
/// - other: Another publisher.
/// - Returns: A publisher that emits an event when any upstream publisher emits
/// an event.
public func merge<
P: Publisher
>(with other: P) -> Publishers.Merge<Self, P>
where Failure == P.Failure, Output == P.Output
{
return .init(self, other)
}
/// Combines elements from this publisher with those from three other publishers,
/// delivering an interleaved sequence of elements.
///
/// The merged publisher continues to emit elements until all upstream publishers
/// finish. If an upstream publisher produces an error, the merged publisher fails
/// with that error.
///
/// - Parameters:
/// - b: A second publisher.
/// - c: A third publisher.
/// - Returns: A publisher that emits an event when any upstream publisher emits
/// an event.
public func merge<
B: Publisher,
C: Publisher
>(with b: B,
_ c: C) -> Publishers.Merge3<Self, B, C>
where Failure == B.Failure, Output == B.Output,
B.Failure == C.Failure, B.Output == C.Output
{
return .init(self, b, c)
}
/// Combines elements from this publisher with those from four other publishers,
/// delivering an interleaved sequence of elements.
///
/// The merged publisher continues to emit elements until all upstream publishers
/// finish. If an upstream publisher produces an error, the merged publisher fails
/// with that error.
///
/// - Parameters:
/// - b: A second publisher.
/// - c: A third publisher.
/// - d: A fourth publisher.
/// - Returns: A publisher that emits an event when any upstream publisher emits
/// an event.
public func merge<
B: Publisher,
C: Publisher,
D: Publisher
>(with b: B,
_ c: C,
_ d: D) -> Publishers.Merge4<Self, B, C, D>
where Failure == B.Failure, Output == B.Output,
B.Failure == C.Failure, B.Output == C.Output,
C.Failure == D.Failure, C.Output == D.Output
{
return .init(self, b, c, d)
}
/// Combines elements from this publisher with those from five other publishers,
/// delivering an interleaved sequence of elements.
///
/// The merged publisher continues to emit elements until all upstream publishers
/// finish. If an upstream publisher produces an error, the merged publisher fails
/// with that error.
///
/// - Parameters:
/// - b: A second publisher.
/// - c: A third publisher.
/// - d: A fourth publisher.
/// - e: A fifth publisher.
/// - Returns: A publisher that emits an event when any upstream publisher emits
/// an event.
public func merge<
B: Publisher,
C: Publisher,
D: Publisher,
E: Publisher
>(with b: B,
_ c: C,
_ d: D,
_ e: E) -> Publishers.Merge5<Self, B, C, D, E>
where Failure == B.Failure, Output == B.Output,
B.Failure == C.Failure, B.Output == C.Output,
C.Failure == D.Failure, C.Output == D.Output,
D.Failure == E.Failure, D.Output == E.Output
{
return .init(self, b, c, d, e)
}
/// Combines elements from this publisher with those from six other publishers,
/// delivering an interleaved sequence of elements.
///
/// The merged publisher continues to emit elements until all upstream publishers
/// finish. If an upstream publisher produces an error, the merged publisher fails
/// with that error.
///
/// - Parameters:
/// - b: A second publisher.
/// - c: A third publisher.
/// - d: A fourth publisher.
/// - e: A fifth publisher.
/// - f: A sixth publisher.
/// - Returns: A publisher that emits an event when any upstream publisher emits
/// an event.
public func merge<
B: Publisher,
C: Publisher,
D: Publisher,
E: Publisher,
F: Publisher
>(with b: B,
_ c: C,
_ d: D,
_ e: E,
_ f: F) -> Publishers.Merge6<Self, B, C, D, E, F>
where Failure == B.Failure, Output == B.Output,
B.Failure == C.Failure, B.Output == C.Output,
C.Failure == D.Failure, C.Output == D.Output,
D.Failure == E.Failure, D.Output == E.Output,
E.Failure == F.Failure, E.Output == F.Output
{
return .init(self, b, c, d, e, f)
}
/// Combines elements from this publisher with those from seven other publishers,
/// delivering an interleaved sequence of elements.
///
/// The merged publisher continues to emit elements until all upstream publishers
/// finish. If an upstream publisher produces an error, the merged publisher fails
/// with that error.
///
/// - Parameters:
/// - b: A second publisher.
/// - c: A third publisher.
/// - d: A fourth publisher.
/// - e: A fifth publisher.
/// - f: A sixth publisher.
/// - g: A seventh publisher.
/// - Returns: A publisher that emits an event when any upstream publisher emits
/// an event.
public func merge<
B: Publisher,
C: Publisher,
D: Publisher,
E: Publisher,
F: Publisher,
G: Publisher
>(with b: B,
_ c: C,
_ d: D,
_ e: E,
_ f: F,
_ g: G) -> Publishers.Merge7<Self, B, C, D, E, F, G>
where Failure == B.Failure, Output == B.Output,
B.Failure == C.Failure, B.Output == C.Output,
C.Failure == D.Failure, C.Output == D.Output,
D.Failure == E.Failure, D.Output == E.Output,
E.Failure == F.Failure, E.Output == F.Output,
F.Failure == G.Failure, F.Output == G.Output
{
return .init(self, b, c, d, e, f, g)
}
/// Combines elements from this publisher with those from eight other publishers,
/// delivering an interleaved sequence of elements.
///
/// The merged publisher continues to emit elements until all upstream publishers
/// finish. If an upstream publisher produces an error, the merged publisher fails
/// with that error.
///
/// - Parameters:
/// - b: A second publisher.
/// - c: A third publisher.
/// - d: A fourth publisher.
/// - e: A fifth publisher.
/// - f: A sixth publisher.
/// - g: A seventh publisher.
/// - h: An eighth publisher.
/// - Returns: A publisher that emits an event when any upstream publisher emits
/// an event.
public func merge<
B: Publisher,
C: Publisher,
D: Publisher,
E: Publisher,
F: Publisher,
G: Publisher,
H: Publisher
>(with b: B,
_ c: C,
_ d: D,
_ e: E,
_ f: F,
_ g: G,
_ h: H) -> Publishers.Merge8<Self, B, C, D, E, F, G, H>
where Failure == B.Failure, Output == B.Output,
B.Failure == C.Failure, B.Output == C.Output,
C.Failure == D.Failure, C.Output == D.Output,
D.Failure == E.Failure, D.Output == E.Output,
E.Failure == F.Failure, E.Output == F.Output,
F.Failure == G.Failure, F.Output == G.Output,
G.Failure == H.Failure, G.Output == H.Output
{
return .init(self, b, c, d, e, f, g, h)
}
}
extension Publisher {
/// Combines elements from this publisher with those from another publisher of
/// the same type, delivering an interleaved sequence of elements.
///
/// - Parameter other: Another publisher of this publisher's type.
/// - Returns: A publisher that emits an event when either upstream publisher emits
/// an event.
public func merge(with other: Self) -> Publishers.MergeMany<Self> {
return .init([self, other])
}
}
// MARK: - Merge publishers
extension Publishers {
/// A publisher created by applying the merge function to two upstream
/// publishers.
public struct Merge<A: Publisher,
B: Publisher>: Publisher
where A.Failure == B.Failure, A.Output == B.Output
{
public typealias Output = A.Output
public typealias Failure = A.Failure
public let a: A
public let b: B
public init(
_ a: A,
_ b: B
) {
self.a = a
self.b = b
}
public func receive<Downstream: Subscriber>(subscriber: Downstream)
where A.Failure == Downstream.Failure,
A.Output == Downstream.Input
{
typealias Merged = _Merged<Output, Failure, Downstream>
let merged = Merged(downstream: subscriber, count: 2)
a.subscribe(Merged.Side(index: 0, merger: merged))
b.subscribe(Merged.Side(index: 1, merger: merged))
subscriber.receive(subscription: merged)
}
public func merge<
P: Publisher
>(with other: P) -> Publishers.Merge3<A, B, P>
{
return .init(a, b, other)
}
public func merge<
Z: Publisher,
Y: Publisher
>(with z: Z,
_ y: Y) -> Publishers.Merge4<A, B, Z, Y>
{
return .init(a, b, z, y)
}
public func merge<
Z: Publisher,
Y: Publisher,
X: Publisher
>(with z: Z,
_ y: Y,
_ x: X) -> Publishers.Merge5<A, B, Z, Y, X>
{
return .init(a, b, z, y, x)
}
public func merge<
Z: Publisher,
Y: Publisher,
X: Publisher,
W: Publisher
>(with z: Z,
_ y: Y,
_ x: X,
_ w: W) -> Publishers.Merge6<A, B, Z, Y, X, W>
{
return .init(a, b, z, y, x, w)
}
public func merge<
Z: Publisher,
Y: Publisher,
X: Publisher,
W: Publisher,
V: Publisher
>(with z: Z,
_ y: Y,
_ x: X,
_ w: W,
_ v: V) -> Publishers.Merge7<A, B, Z, Y, X, W, V>
{
return .init(a, b, z, y, x, w, v)
}
public func merge<
Z: Publisher,
Y: Publisher,
X: Publisher,
W: Publisher,
V: Publisher,
U: Publisher
>(with z: Z,
_ y: Y,
_ x: X,
_ w: W,
_ v: V,
_ u: U) -> Publishers.Merge8<A, B, Z, Y, X, W, V, U>
{
return .init(a, b, z, y, x, w, v, u)
}
}
/// A publisher created by applying the merge function to three upstream
/// publishers.
public struct Merge3<A: Publisher,
B: Publisher,
C: Publisher>: Publisher
where A.Failure == B.Failure, A.Output == B.Output,
B.Failure == C.Failure, B.Output == C.Output
{
public typealias Output = A.Output
public typealias Failure = A.Failure
public let a: A
public let b: B
public let c: C
public init(
_ a: A,
_ b: B,
_ c: C
) {
self.a = a
self.b = b
self.c = c
}
public func receive<Downstream: Subscriber>(subscriber: Downstream)
where A.Failure == Downstream.Failure,
A.Output == Downstream.Input
{
typealias Merged = _Merged<Output, Failure, Downstream>
let merged = Merged(downstream: subscriber, count: 3)
a.subscribe(Merged.Side(index: 0, merger: merged))
b.subscribe(Merged.Side(index: 1, merger: merged))
c.subscribe(Merged.Side(index: 2, merger: merged))
subscriber.receive(subscription: merged)
}
public func merge<
P: Publisher
>(with other: P) -> Publishers.Merge4<A, B, C, P>
{
return .init(a, b, c, other)
}
public func merge<
Z: Publisher,
Y: Publisher
>(with z: Z,
_ y: Y) -> Publishers.Merge5<A, B, C, Z, Y>
{
return .init(a, b, c, z, y)
}
public func merge<
Z: Publisher,
Y: Publisher,
X: Publisher
>(with z: Z,
_ y: Y,
_ x: X) -> Publishers.Merge6<A, B, C, Z, Y, X>
{
return .init(a, b, c, z, y, x)
}
public func merge<
Z: Publisher,
Y: Publisher,
X: Publisher,
W: Publisher
>(with z: Z,
_ y: Y,
_ x: X,
_ w: W) -> Publishers.Merge7<A, B, C, Z, Y, X, W>
{
return .init(a, b, c, z, y, x, w)
}
public func merge<
Z: Publisher,
Y: Publisher,
X: Publisher,
W: Publisher,
V: Publisher
>(with z: Z,
_ y: Y,
_ x: X,
_ w: W,
_ v: V) -> Publishers.Merge8<A, B, C, Z, Y, X, W, V>
{
return .init(a, b, c, z, y, x, w, v)
}
}
/// A publisher created by applying the merge function to four upstream
/// publishers.
public struct Merge4<A: Publisher,
B: Publisher,
C: Publisher,
D: Publisher>: Publisher
where A.Failure == B.Failure, A.Output == B.Output,
B.Failure == C.Failure, B.Output == C.Output,
C.Failure == D.Failure, C.Output == D.Output
{
public typealias Output = A.Output
public typealias Failure = A.Failure
public let a: A
public let b: B
public let c: C
public let d: D
public init(
_ a: A,
_ b: B,
_ c: C,
_ d: D
) {
self.a = a
self.b = b
self.c = c
self.d = d
}
public func receive<Downstream: Subscriber>(subscriber: Downstream)
where A.Failure == Downstream.Failure,
A.Output == Downstream.Input
{
typealias Merged = _Merged<Output, Failure, Downstream>
let merged = Merged(downstream: subscriber, count: 4)
a.subscribe(Merged.Side(index: 0, merger: merged))
b.subscribe(Merged.Side(index: 1, merger: merged))
c.subscribe(Merged.Side(index: 2, merger: merged))
d.subscribe(Merged.Side(index: 3, merger: merged))
subscriber.receive(subscription: merged)
}
public func merge<
P: Publisher
>(with other: P) -> Publishers.Merge5<A, B, C, D, P>
{
return .init(a, b, c, d, other)
}
public func merge<
Z: Publisher,
Y: Publisher
>(with z: Z,
_ y: Y) -> Publishers.Merge6<A, B, C, D, Z, Y>
{
return .init(a, b, c, d, z, y)
}
public func merge<
Z: Publisher,
Y: Publisher,
X: Publisher
>(with z: Z,
_ y: Y,
_ x: X) -> Publishers.Merge7<A, B, C, D, Z, Y, X>
{
return .init(a, b, c, d, z, y, x)
}
public func merge<
Z: Publisher,
Y: Publisher,
X: Publisher,
W: Publisher
>(with z: Z,
_ y: Y,
_ x: X,
_ w: W) -> Publishers.Merge8<A, B, C, D, Z, Y, X, W>
{
return .init(a, b, c, d, z, y, x, w)
}
}
/// A publisher created by applying the merge function to five upstream
/// publishers.
public struct Merge5<A: Publisher,
B: Publisher,
C: Publisher,
D: Publisher,
E: Publisher>: Publisher
where A.Failure == B.Failure, A.Output == B.Output,
B.Failure == C.Failure, B.Output == C.Output,
C.Failure == D.Failure, C.Output == D.Output,
D.Failure == E.Failure, D.Output == E.Output
{
public typealias Output = A.Output
public typealias Failure = A.Failure
public let a: A
public let b: B
public let c: C
public let d: D
public let e: E
public init(
_ a: A,
_ b: B,
_ c: C,
_ d: D,
_ e: E
) {
self.a = a
self.b = b
self.c = c
self.d = d
self.e = e
}
public func receive<Downstream: Subscriber>(subscriber: Downstream)
where A.Failure == Downstream.Failure,
A.Output == Downstream.Input
{
typealias Merged = _Merged<Output, Failure, Downstream>
let merged = Merged(downstream: subscriber, count: 5)
a.subscribe(Merged.Side(index: 0, merger: merged))
b.subscribe(Merged.Side(index: 1, merger: merged))
c.subscribe(Merged.Side(index: 2, merger: merged))
d.subscribe(Merged.Side(index: 3, merger: merged))
e.subscribe(Merged.Side(index: 4, merger: merged))
subscriber.receive(subscription: merged)
}
public func merge<
P: Publisher
>(with other: P) -> Publishers.Merge6<A, B, C, D, E, P>
{
return .init(a, b, c, d, e, other)
}
public func merge<
Z: Publisher,
Y: Publisher
>(with z: Z,
_ y: Y) -> Publishers.Merge7<A, B, C, D, E, Z, Y>
{
return .init(a, b, c, d, e, z, y)
}
public func merge<
Z: Publisher,
Y: Publisher,
X: Publisher
>(with z: Z,
_ y: Y,
_ x: X) -> Publishers.Merge8<A, B, C, D, E, Z, Y, X>
{
return .init(a, b, c, d, e, z, y, x)
}
}
/// A publisher created by applying the merge function to six upstream
/// publishers.
public struct Merge6<A: Publisher,
B: Publisher,
C: Publisher,
D: Publisher,
E: Publisher,
F: Publisher>: Publisher
where A.Failure == B.Failure, A.Output == B.Output,
B.Failure == C.Failure, B.Output == C.Output,
C.Failure == D.Failure, C.Output == D.Output,
D.Failure == E.Failure, D.Output == E.Output,
E.Failure == F.Failure, E.Output == F.Output
{
public typealias Output = A.Output
public typealias Failure = A.Failure
public let a: A
public let b: B
public let c: C
public let d: D
public let e: E
public let f: F
public init(
_ a: A,
_ b: B,
_ c: C,
_ d: D,
_ e: E,
_ f: F
) {
self.a = a
self.b = b
self.c = c
self.d = d
self.e = e
self.f = f
}
public func receive<Downstream: Subscriber>(subscriber: Downstream)
where A.Failure == Downstream.Failure,
A.Output == Downstream.Input
{
typealias Merged = _Merged<Output, Failure, Downstream>
let merged = Merged(downstream: subscriber, count: 6)
a.subscribe(Merged.Side(index: 0, merger: merged))
b.subscribe(Merged.Side(index: 1, merger: merged))
c.subscribe(Merged.Side(index: 2, merger: merged))
d.subscribe(Merged.Side(index: 3, merger: merged))
e.subscribe(Merged.Side(index: 4, merger: merged))
f.subscribe(Merged.Side(index: 5, merger: merged))
subscriber.receive(subscription: merged)
}
public func merge<
P: Publisher
>(with other: P) -> Publishers.Merge7<A, B, C, D, E, F, P>
{
return .init(a, b, c, d, e, f, other)
}
public func merge<
Z: Publisher,
Y: Publisher
>(with z: Z,
_ y: Y) -> Publishers.Merge8<A, B, C, D, E, F, Z, Y>
{
return .init(a, b, c, d, e, f, z, y)
}
}
/// A publisher created by applying the merge function to seven upstream
/// publishers.
public struct Merge7<A: Publisher,
B: Publisher,
C: Publisher,
D: Publisher,
E: Publisher,
F: Publisher,
G: Publisher>: Publisher
where A.Failure == B.Failure, A.Output == B.Output,
B.Failure == C.Failure, B.Output == C.Output,
C.Failure == D.Failure, C.Output == D.Output,
D.Failure == E.Failure, D.Output == E.Output,
E.Failure == F.Failure, E.Output == F.Output,
F.Failure == G.Failure, F.Output == G.Output
{
public typealias Output = A.Output
public typealias Failure = A.Failure
public let a: A
public let b: B
public let c: C
public let d: D
public let e: E
public let f: F
public let g: G
public init(
_ a: A,
_ b: B,
_ c: C,
_ d: D,
_ e: E,
_ f: F,
_ g: G
) {
self.a = a
self.b = b
self.c = c
self.d = d
self.e = e
self.f = f
self.g = g
}
public func receive<Downstream: Subscriber>(subscriber: Downstream)
where A.Failure == Downstream.Failure,
A.Output == Downstream.Input
{
typealias Merged = _Merged<Output, Failure, Downstream>
let merged = Merged(downstream: subscriber, count: 7)
a.subscribe(Merged.Side(index: 0, merger: merged))
b.subscribe(Merged.Side(index: 1, merger: merged))
c.subscribe(Merged.Side(index: 2, merger: merged))
d.subscribe(Merged.Side(index: 3, merger: merged))
e.subscribe(Merged.Side(index: 4, merger: merged))
f.subscribe(Merged.Side(index: 5, merger: merged))
g.subscribe(Merged.Side(index: 6, merger: merged))
subscriber.receive(subscription: merged)
}
public func merge<
P: Publisher
>(with other: P) -> Publishers.Merge8<A, B, C, D, E, F, G, P>
{
return .init(a, b, c, d, e, f, g, other)
}
}
/// A publisher created by applying the merge function to eight upstream
/// publishers.
public struct Merge8<A: Publisher,
B: Publisher,
C: Publisher,
D: Publisher,
E: Publisher,
F: Publisher,
G: Publisher,
H: Publisher>: Publisher
where A.Failure == B.Failure, A.Output == B.Output,
B.Failure == C.Failure, B.Output == C.Output,
C.Failure == D.Failure, C.Output == D.Output,
D.Failure == E.Failure, D.Output == E.Output,
E.Failure == F.Failure, E.Output == F.Output,
F.Failure == G.Failure, F.Output == G.Output,
G.Failure == H.Failure, G.Output == H.Output
{
public typealias Output = A.Output
public typealias Failure = A.Failure
public let a: A
public let b: B
public let c: C
public let d: D
public let e: E
public let f: F
public let g: G
public let h: H
public init(
_ a: A,
_ b: B,
_ c: C,
_ d: D,
_ e: E,
_ f: F,
_ g: G,
_ h: H
) {
self.a = a
self.b = b
self.c = c
self.d = d
self.e = e
self.f = f
self.g = g
self.h = h
}
public func receive<Downstream: Subscriber>(subscriber: Downstream)
where A.Failure == Downstream.Failure,
A.Output == Downstream.Input
{
typealias Merged = _Merged<Output, Failure, Downstream>
let merged = Merged(downstream: subscriber, count: 8)
a.subscribe(Merged.Side(index: 0, merger: merged))
b.subscribe(Merged.Side(index: 1, merger: merged))
c.subscribe(Merged.Side(index: 2, merger: merged))
d.subscribe(Merged.Side(index: 3, merger: merged))
e.subscribe(Merged.Side(index: 4, merger: merged))
f.subscribe(Merged.Side(index: 5, merger: merged))
g.subscribe(Merged.Side(index: 6, merger: merged))
h.subscribe(Merged.Side(index: 7, merger: merged))
subscriber.receive(subscription: merged)
}
}
}
extension Publishers {
public struct MergeMany<Upstream: Publisher>: Publisher {
public typealias Output = Upstream.Output
public typealias Failure = Upstream.Failure
public let publishers: [Upstream]
public init(_ upstream: Upstream...) {
self.publishers = upstream
}
public init<UpstreamPublishers: Swift.Sequence>(_ upstream: UpstreamPublishers)
where Upstream == UpstreamPublishers.Element
{
publishers = Array(upstream)
}
public func receive<Downstream: Subscriber>(subscriber: Downstream)
where Upstream.Failure == Downstream.Failure,
Upstream.Output == Downstream.Input
{
typealias Merged = _Merged<Output, Failure, Downstream>
let merged = Merged(downstream: subscriber, count: publishers.count)
for (i, upstream) in publishers.enumerated() {
upstream.subscribe(Merged.Side(index: i, merger: merged))
}
subscriber.receive(subscription: merged)
}
public func merge(with other: Upstream) -> Publishers.MergeMany<Upstream> {
var newPublishers = publishers
newPublishers.append(other)
return .init(newPublishers)
}
}
}
// MARK: - Equatable conformances
extension Publishers.Merge: Equatable
where
A: Equatable,
B: Equatable {}
extension Publishers.Merge3: Equatable
where
A: Equatable,
B: Equatable,
C: Equatable {}
extension Publishers.Merge4: Equatable
where
A: Equatable,
B: Equatable,
C: Equatable,
D: Equatable {}
extension Publishers.Merge5: Equatable
where
A: Equatable,
B: Equatable,
C: Equatable,
D: Equatable,
E: Equatable {}
extension Publishers.Merge6: Equatable
where
A: Equatable,
B: Equatable,
C: Equatable,
D: Equatable,
E: Equatable,
F: Equatable {}
extension Publishers.Merge7: Equatable
where
A: Equatable,
B: Equatable,
C: Equatable,
D: Equatable,
E: Equatable,
F: Equatable,
G: Equatable {}
extension Publishers.Merge8: Equatable
where
A: Equatable,
B: Equatable,
C: Equatable,
D: Equatable,
E: Equatable,
F: Equatable,
G: Equatable,
H: Equatable {}
extension Publishers.MergeMany: Equatable
where
Upstream: Equatable {}
@@ -0,0 +1,285 @@
${template_header}
//
// Publishers.Merge.swift.gyb
//
//
// Created by Sergej Jaskiewicz on 04/10/2019.
//
%{
from gyb_opencombine_support import (
suffix_variadic,
list_with_suffix_variadic,
indent
)
import string
instantiations = [(2, 'two', 'A second'),
(3, 'three', 'A third'),
(4, 'four', 'A fourth'),
(5, 'five', 'A fifth'),
(6, 'six', 'A sixth'),
(7, 'seven', 'A seventh'),
(8, 'eight', 'An eighth')]
def make_publisher_name(arity):
return suffix_variadic('Merge', arity, arity - 1)
def make_upstream_types(arity, start=0):
return [str(c) for c in string.ascii_uppercase[start:arity]]
def make_upstream_types_reversed(arity):
return [str(c) for c in reversed(string.ascii_uppercase)][:arity]
def make_upstream_generic_constraints(upstream_types, first_is_self=False):
format_string = '{0}Failure == {1}.Failure, {0}Output == {1}.Output'
def format(i):
return format_string.format(upstream_types[i] + '.',
upstream_types[i + 1])
result = [format(i) for i in range(len(upstream_types) - 1)]
if first_is_self:
result.insert(0, format_string.format('', upstream_types[0]))
return result
def declare_merge_method(arg_count, arity, indent_spaces_count):
assert(arg_count <= arity - 1)
is_specialization = arg_count < arity - 1
declaration_format = """\
public func merge<
{}
>(with {}) -> Publishers.{}<{}>\
"""
where_clause_format = '\n where {}'
if arg_count == 1:
upstream_types = ['P']
elif is_specialization:
upstream_types = make_upstream_types_reversed(arg_count)
else:
upstream_types = make_upstream_types(arg_count + 1, 1)
method_generic_params = \
[upstream_type + ': Publisher' for upstream_type in upstream_types]
cs_method_generic_params = \
(',\n ').join(method_generic_params)
method_args = ['other: P'] \
if arg_count == 1 else ['{}: {}'.format(upstream_type.lower(), upstream_type) \
for upstream_type in upstream_types]
cs_method_args = ',\n _ '.join(method_args)
publisher_name = make_publisher_name(arity)
self_generic_params = make_upstream_types(arity - arg_count) \
if is_specialization else ['Self']
publisher_generic_params = self_generic_params + upstream_types
cs_publisher_generic_params = ', '.join(publisher_generic_params)
generic_constraints = make_upstream_generic_constraints(upstream_types, True)
cs_generic_constraints = \
',\n '.join(generic_constraints)
declaration = declaration_format.format(cs_method_generic_params,
cs_method_args,
publisher_name,
cs_publisher_generic_params)
if not is_specialization:
declaration += where_clause_format.format(cs_generic_constraints)
return indent(declaration, indent_spaces_count)
}%
// swiftlint:disable generic_type_name
// swiftlint:disable vertical_parameter_alignment
// MARK: - Merge methods on Publisher
extension Publisher {
% for arity, _, _ in instantiations:
%
% doc_cardinal = 'another publisher' \
% if arity == 2 else (instantiations[arity - 2][1] + ' other publishers')
% argument_names = ['other'] \
% if arity == 2 else [upstream_type.lower() \
% for upstream_type in make_upstream_types(arity, 1)]
/// Combines elements from this publisher with those from ${doc_cardinal},
/// delivering an interleaved sequence of elements.
///
/// The merged publisher continues to emit elements until all upstream publishers
/// finish. If an upstream publisher produces an error, the merged publisher fails
/// with that error.
///
/// - Parameters:
% for i in range(arity - 1):
% param_doc = 'Another' if arity == 2 else instantiations[i][2]
/// - ${argument_names[i]}: ${param_doc} publisher.
% end
/// - Returns: A publisher that emits an event when any upstream publisher emits
/// an event.
${declare_merge_method(arity - 1, arity, 4)}
{
return .init(self, ${', '.join(argument_names)})
}
% end
}
extension Publisher {
/// Combines elements from this publisher with those from another publisher of
/// the same type, delivering an interleaved sequence of elements.
///
/// - Parameter other: Another publisher of this publisher's type.
/// - Returns: A publisher that emits an event when either upstream publisher emits
/// an event.
public func merge(with other: Self) -> Publishers.MergeMany<Self> {
return .init([self, other])
}
}
// MARK: - Merge publishers
extension Publishers {
% for arity, cardinal, _ in instantiations:
%
% publisher_name = make_publisher_name(arity)
%
% upstream_types = make_upstream_types(arity)
%
% upstream_generic_params = \
% [upstream_type + ': Publisher' for upstream_type in upstream_types]
%
% cs_upstream_generic_params = \
% (',\n' + (19 + len(publisher_name)) * ' ').join(upstream_generic_params)
%
% upstream_generic_constraints = \
% make_upstream_generic_constraints(upstream_types)
%
% cs_upstream_generic_constraints = \
% ',\n '.join(upstream_generic_constraints)
%
% init_args = ['_ {}: {}'.format(upstream_type.lower(), upstream_type) \
% for upstream_type in upstream_types]
% cs_init_args = ',\n '.join(init_args)
%
% self_fields = [upstream_type.lower() for upstream_type in upstream_types]
/// A publisher created by applying the merge function to ${cardinal} upstream
/// publishers.
public struct ${publisher_name}<${cs_upstream_generic_params}>: Publisher
where ${cs_upstream_generic_constraints}
{
public typealias Output = ${upstream_types[0]}.Output
public typealias Failure = ${upstream_types[0]}.Failure
% for upstream_type in upstream_types:
public let ${upstream_type.lower()}: ${upstream_type}
% end
public init(
${cs_init_args}
) {
% for self_field in self_fields:
self.${self_field} = ${self_field}
% end
}
public func receive<Downstream: Subscriber>(subscriber: Downstream)
where ${upstream_types[0]}.Failure == Downstream.Failure,
${upstream_types[0]}.Output == Downstream.Input
{
typealias Merged = _Merged<Output, Failure, Downstream>
let merged = Merged(downstream: subscriber, count: ${arity})
% for i in range(len(self_fields)):
${self_fields[i]}.subscribe(Merged.Side(index: ${i}, merger: merged))
% end
subscriber.receive(subscription: merged)
}
% for i in range(len(instantiations) + 1 - arity):
% argument_names = ['other'] \
% if i == 0 else [upstream_type.lower() \
% for upstream_type in make_upstream_types_reversed(i + 1)]
%
${declare_merge_method(i + 1, arity + i + 1, 8)}
{
return .init(${', '.join(self_fields + argument_names)})
}
% end
}
% end
}
extension Publishers {
public struct MergeMany<Upstream: Publisher>: Publisher {
public typealias Output = Upstream.Output
public typealias Failure = Upstream.Failure
public let publishers: [Upstream]
public init(_ upstream: Upstream...) {
self.publishers = upstream
}
public init<UpstreamPublishers: Swift.Sequence>(_ upstream: UpstreamPublishers)
where Upstream == UpstreamPublishers.Element
{
publishers = Array(upstream)
}
public func receive<Downstream: Subscriber>(subscriber: Downstream)
where Upstream.Failure == Downstream.Failure,
Upstream.Output == Downstream.Input
{
typealias Merged = _Merged<Output, Failure, Downstream>
let merged = Merged(downstream: subscriber, count: publishers.count)
for (i, upstream) in publishers.enumerated() {
upstream.subscribe(Merged.Side(index: i, merger: merged))
}
subscriber.receive(subscription: merged)
}
public func merge(with other: Upstream) -> Publishers.MergeMany<Upstream> {
var newPublishers = publishers
newPublishers.append(other)
return .init(newPublishers)
}
}
}
// MARK: - Equatable conformances
% for arity, cardinal, _ in instantiations:
%
% publisher_name = make_publisher_name(arity)
%
% upstream_types = make_upstream_types(arity)
%
% constraints = [upstream_type + ': Equatable' for upstream_type in upstream_types]
% cs_constraints = ',\n'.join(constraints)
% cs_constraints = indent(cs_constraints, 8)
%
extension Publishers.${publisher_name}: Equatable
where
${cs_constraints} {}
% end
extension Publishers.MergeMany: Equatable
where
Upstream: Equatable {}
@@ -0,0 +1,214 @@
//
// Publishers._Merged.swift
//
//
// Created by Sergej Jaskiewicz on 03.12.2019.
//
import COpenCombineHelpers
extension Publishers {
// swiftlint:disable:next type_name
internal final class _Merged<Input, Failure, Downstream: Subscriber>
: Subscription,
CustomStringConvertible,
CustomReflectable,
CustomPlaygroundDisplayConvertible
where Downstream.Input == Input, Downstream.Failure == Failure
{
private let downstream: Downstream
private var demand = Subscribers.Demand.none // 0x78
private var terminated = false // 0x80
private let count: Int // 0x88
private var upstreamFinished = 0 // 0x90
private var finished = false // 0x98
// TODO: The size of these arrays always stays the same.
// Maybe we can leverage ManagedBuffer/ManagedBufferPointer here
// to avoid additional allocations.
private var subscriptions: [Subscription?] // 0xA0
private var buffers: [Input?] // 0xA8
private let lock = UnfairLock.allocate() // 0xB0
private let downstreamLock = UnfairLock.allocate() // 0xB8
private var recursive = false // 0xC0
private var pending = Subscribers.Demand.none // 0xC8
internal init(downstream: Downstream, count: Int) {
self.downstream = downstream
self.count = count
self.subscriptions = Array(repeating: nil, count: count)
self.buffers = Array(repeating: nil, count: count)
}
deinit {
lock.deallocate()
downstreamLock.deallocate()
}
private func receive(subscription: Subscription, _ index: Int) {
lock.lock()
guard subscriptions[index] == nil else {
lock.unlock()
subscription.cancel()
return
}
subscriptions[index] = subscription
let demand = self.demand
lock.unlock()
subscription.request(demand == .unlimited ? .unlimited : .max(1))
}
private func receive(_ input: Input, _ index: Int) -> Subscribers.Demand {
func lockedSendValueDownstream() -> Subscribers.Demand {
recursive = true
lock.unlock()
downstreamLock.lock()
let newDemand = downstream.receive(input)
downstreamLock.unlock()
lock.lock()
recursive = false
return newDemand
}
lock.lock()
if demand == .unlimited {
let newDemand = lockedSendValueDownstream()
lock.unlock()
return newDemand
}
if demand == .none {
buffers[index] = input
lock.unlock()
return .none
}
demand -= 1
let newDemand = lockedSendValueDownstream()
demand += newDemand + pending
pending = .none
lock.unlock()
return .max(1)
}
private func receive(completion: Subscribers.Completion<Failure>, _ index: Int) {
func lockedSendCompletionDownstream() {
recursive = true
lock.unlock()
downstreamLock.lock()
downstream.receive(completion: completion)
downstreamLock.unlock()
lock.lock()
recursive = false
}
lock.lock()
switch completion {
case .finished:
upstreamFinished += 1
subscriptions[index] = nil
// TODO: Test both conditions.
// When receiving subscription twice, the second time
// upstreamFinished != count
guard upstreamFinished == count,
subscriptions.allSatisfy({ $0 == nil }) else {
lock.unlock()
return
}
finished = true
lockedSendCompletionDownstream()
lock.unlock()
case .failure:
if terminated {
lock.unlock()
return
}
terminated = true
let subscriptions = self.subscriptions
self.subscriptions = Array(repeating: nil, count: subscriptions.count)
lock.unlock()
for (i, subscription) in subscriptions.enumerated() where i != index {
subscription?.cancel()
}
lock.lock()
lockedSendCompletionDownstream()
lock.unlock()
}
}
internal func request(_ demand: Subscribers.Demand) {
lock.lock()
// TODO: Test all conditions
if terminated || finished || demand == .none || self.demand == .unlimited {
lock.unlock()
return
}
if recursive {
pending += demand
lock.unlock()
return
}
if demand == .unlimited {
// loc_6a5b1
self.demand = .unlimited
}
// TODO: Unimplemented
lock.unlock()
}
internal func cancel() {
// TODO: Unimplemented
}
internal var description: String { return "Merge" }
internal var customMirror: Mirror {
return Mirror(self, children: EmptyCollection())
}
internal var playgroundDescription: Any { return description }
}
}
extension Publishers._Merged {
internal struct Side
: Subscriber,
CustomStringConvertible,
CustomReflectable,
CustomPlaygroundDisplayConvertible
{
private let index: Int
private let merger: Publishers._Merged<Input, Failure, Downstream>
internal let combineIdentifier = CombineIdentifier()
internal init(index: Int,
merger: Publishers._Merged<Input, Failure, Downstream>) {
self.index = index
self.merger = merger
}
internal func receive(subscription: Subscription) {
merger.receive(subscription: subscription, index)
}
internal func receive(_ input: Input) -> Subscribers.Demand {
return merger.receive(input, index)
}
internal func receive(completion: Subscribers.Completion<Failure>) {
merger.receive(completion: completion, index)
}
internal var description: String { return "Merge" }
internal var customMirror: Mirror {
let children = CollectionOfOne<Mirror.Child>(
("parentSubscription", merger.combineIdentifier)
)
return Mirror(self, children: children)
}
internal var playgroundDescription: Any { return description }
}
}
@@ -0,0 +1,452 @@
//
// MergeTests.swift
//
//
// Created by Sergej Jaskiewicz on 06.01.2020.
//
import XCTest
#if OPENCOMBINE_COMPATIBILITY_TEST
import Combine
#else
import OpenCombine
#endif
@available(macOS 10.15, iOS 13.0, *)
final class MergeTests: XCTestCase {
private func createTestPublishers(
arity: Int
) -> ([CustomSubscription], [CustomPublisher]) {
precondition(arity >= 0)
let subscriptions = (0 ..< arity).map { _ in
CustomSubscription()
}
let publishers = (0 ..< arity).map {
CustomPublisher(subscription: subscriptions[$0])
}
return (subscriptions, publishers)
}
func testMergeLimitedInitialDemand() {
func test<Merger: Publisher>(
forArity arity: Int,
_ makeMerger: ([CustomPublisher]) -> Merger
) where Merger.Output == Int, Merger.Failure == TestingError {
let (subscriptions, publishers) = createTestPublishers(arity: arity)
let merger = makeMerger(publishers)
var downstreamSubscription: Subscription?
let tracking = TrackingSubscriber(
receiveSubscription: { downstreamSubscription = $0 },
receiveValue: { _ in .max(3) }
)
merger.subscribe(tracking)
for (i, subscription) in subscriptions.enumerated() {
XCTAssertEqual(subscription.history,
[.requested(.max(1))],
"failure for subscription \(i)")
}
XCTAssertEqual(tracking.history, [.subscription("Merge")])
// No downstream demand, these values are buffered
for (i, publisher) in publishers.reversed().enumerated() {
XCTAssertEqual(publisher.send(-i), .none) // ignored
XCTAssertEqual(publisher.send(i), .none)
}
XCTAssertEqual(tracking.history, [.subscription("Merge")])
// Establishing downstream demand
downstreamSubscription?.request(.max(arity))
downstreamSubscription?.request(.max(arity))
for (i, subscription) in subscriptions.enumerated() {
XCTAssertEqual(subscription.history,
[.requested(.max(1)),
.requested(.max(1))],
"failure for subscription \(i)")
}
let expectedValues: [TrackingSubscriber.Event] = (0 ..< arity)
.reversed()
.map {
.value($0)
}
XCTAssertEqual(tracking.history,
[.subscription("Merge")] + expectedValues)
// Requesting more elements
downstreamSubscription?.request(.max(arity))
// Satisfying the unfullfilled demand
for (i, publisher) in publishers.reversed().enumerated() {
XCTAssertEqual(publisher.send(i), .max(1))
}
XCTAssertEqual(
tracking.history,
[.subscription("Merge")] + expectedValues + expectedValues.reversed()
)
tracking.cancel()
}
test(forArity: 2) { publishers in
Publishers.Merge(publishers[0],
publishers[1])
}
test(forArity: 3) { publishers in
Publishers.Merge3(publishers[0],
publishers[1],
publishers[2])
}
test(forArity: 4) { publishers in
Publishers.Merge4(publishers[0],
publishers[1],
publishers[2],
publishers[3])
}
test(forArity: 4) { publishers in
Publishers.Merge4(publishers[0],
publishers[1],
publishers[2],
publishers[3])
}
test(forArity: 5) { publishers in
Publishers.Merge5(publishers[0],
publishers[1],
publishers[2],
publishers[3],
publishers[4])
}
test(forArity: 6) { publishers in
Publishers.Merge6(publishers[0],
publishers[1],
publishers[2],
publishers[3],
publishers[4],
publishers[5])
}
test(forArity: 7) { publishers in
Publishers.Merge7(publishers[0],
publishers[1],
publishers[2],
publishers[3],
publishers[4],
publishers[5],
publishers[6])
}
test(forArity: 8) { publishers in
Publishers.Merge8(publishers[0],
publishers[1],
publishers[2],
publishers[3],
publishers[4],
publishers[5],
publishers[6],
publishers[7])
}
test(forArity: 0) { _ in
Publishers.MergeMany<CustomPublisher>()
}
test(forArity: 2) { publishers in
Publishers.MergeMany(publishers[0], publishers[1])
}
test(forArity: 20) { publishers in
Publishers.MergeMany(publishers)
}
}
func testMergeUnimitedInitialDemand() {
func test<Merger: Publisher>(
forArity arity: Int,
_ makeMerger: ([CustomPublisher]) -> Merger
) where Merger.Output == Int, Merger.Failure == TestingError {
let (subscriptions, publishers) = createTestPublishers(arity: arity)
let merger = makeMerger(publishers)
var downstreamSubscription: Subscription?
let tracking = TrackingSubscriber(
receiveSubscription: {
$0.request(.unlimited)
downstreamSubscription = $0
},
receiveValue: { _ in .max(3) }
)
merger.subscribe(tracking)
for (i, subscription) in subscriptions.enumerated() {
XCTAssertEqual(subscription.history,
[.requested(.max(1)),
.requested(.unlimited)],
"failure for subscription \(i)")
}
if arity == 0 {
XCTAssertEqual(tracking.history, [.subscription("Merge"),
.completion(.finished)])
} else {
XCTAssertEqual(tracking.history, [.subscription("Merge")])
}
downstreamSubscription?.request(.max(42))
downstreamSubscription?.request(.unlimited)
for (i, subscription) in subscriptions.enumerated() {
XCTAssertEqual(subscription.history,
[.requested(.max(1)),
.requested(.unlimited)],
"failure for subscription \(i)")
}
for (i, publisher) in publishers.reversed().enumerated() {
XCTAssertEqual(publisher.send(i), .max(3))
}
let expectedValues: [TrackingSubscriber.Event] = (0 ..< arity).map {
.value($0)
}
if arity == 0 {
XCTAssertEqual(tracking.history, [.subscription("Merge"),
.completion(.finished)])
} else {
XCTAssertEqual(tracking.history,
[.subscription("Merge")] + expectedValues)
}
for (i, publisher) in publishers.enumerated() {
XCTAssertEqual(publisher.send(i), .max(3))
}
if arity == 0 {
XCTAssertEqual(tracking.history, [.subscription("Merge"),
.completion(.finished)])
} else {
XCTAssertEqual(tracking.history,
[.subscription("Merge")] + expectedValues + expectedValues)
}
tracking.cancel()
}
test(forArity: 2) { publishers in
Publishers.Merge(publishers[0],
publishers[1])
}
test(forArity: 3) { publishers in
Publishers.Merge3(publishers[0],
publishers[1],
publishers[2])
}
test(forArity: 4) { publishers in
Publishers.Merge4(publishers[0],
publishers[1],
publishers[2],
publishers[3])
}
test(forArity: 4) { publishers in
Publishers.Merge4(publishers[0],
publishers[1],
publishers[2],
publishers[3])
}
test(forArity: 5) { publishers in
Publishers.Merge5(publishers[0],
publishers[1],
publishers[2],
publishers[3],
publishers[4])
}
test(forArity: 6) { publishers in
Publishers.Merge6(publishers[0],
publishers[1],
publishers[2],
publishers[3],
publishers[4],
publishers[5])
}
test(forArity: 7) { publishers in
Publishers.Merge7(publishers[0],
publishers[1],
publishers[2],
publishers[3],
publishers[4],
publishers[5],
publishers[6])
}
test(forArity: 8) { publishers in
Publishers.Merge8(publishers[0],
publishers[1],
publishers[2],
publishers[3],
publishers[4],
publishers[5],
publishers[6],
publishers[7])
}
test(forArity: 0) { _ in
Publishers.MergeMany<CustomPublisher>()
}
test(forArity: 2) { publishers in
Publishers.MergeMany(publishers[0], publishers[1])
}
test(forArity: 20) { publishers in
Publishers.MergeMany(publishers)
}
}
func testMergeReflection() throws {
func testMergeSubscriptionReflection<Sut: Publisher>(_ sut: Sut) throws {
try testSubscriptionReflection(
description: "Merge",
customMirror: childrenIsEmpty,
playgroundDescription: "Merge",
sut: sut
)
}
func testMergeSideReflection<Merger: Publisher>(
_ makeMerger: (CustomPublisher) -> Merger
) throws where Merger.Output == Int, Merger.Failure == TestingError {
try testReflection(parentInput: Int.self,
parentFailure: TestingError.self,
description: "Merge",
customMirror: expectedChildren(
("parentSubscription", .anything)
),
playgroundDescription: "Merge",
makeMerger)
let publisher = CustomPublisher(subscription: CustomSubscription())
let merger = makeMerger(publisher)
let tracking = TrackingSubscriber()
merger.subscribe(tracking)
let side = try XCTUnwrap(publisher.erasedSubscriber)
let expectedParentID =
try XCTUnwrap(tracking.subscriptions.first?.combineIdentifier)
let actualParentID = Mirror(reflecting: side)
.descendant("parentSubscription") as? CombineIdentifier
XCTAssertEqual(expectedParentID, actualParentID)
}
let publisher = CustomPublisher(subscription: CustomSubscription())
try testMergeSubscriptionReflection(
publisher.merge(with: publisher) as Publishers.Merge
)
try testMergeSideReflection {
$0.merge(with: publisher) as Publishers.Merge
}
try testMergeSubscriptionReflection(
publisher.merge(with: publisher,
publisher) as Publishers.Merge3
)
try testMergeSideReflection {
$0.merge(with: publisher,
publisher) as Publishers.Merge3
}
try testMergeSubscriptionReflection(
publisher.merge(with: publisher,
publisher,
publisher) as Publishers.Merge4
)
try testMergeSideReflection {
$0.merge(with: publisher,
publisher,
publisher) as Publishers.Merge4
}
try testMergeSubscriptionReflection(
publisher.merge(with: publisher,
publisher,
publisher,
publisher) as Publishers.Merge5
)
try testMergeSideReflection {
$0.merge(with: publisher,
publisher,
publisher,
publisher) as Publishers.Merge5
}
try testMergeSubscriptionReflection(
publisher.merge(with: publisher,
publisher,
publisher,
publisher,
publisher) as Publishers.Merge6
)
try testMergeSideReflection {
$0.merge(with: publisher,
publisher,
publisher,
publisher,
publisher) as Publishers.Merge6
}
try testMergeSubscriptionReflection(
publisher.merge(with: publisher,
publisher,
publisher,
publisher,
publisher,
publisher) as Publishers.Merge7
)
try testMergeSideReflection {
$0.merge(with: publisher,
publisher,
publisher,
publisher,
publisher,
publisher) as Publishers.Merge7
}
try testMergeSubscriptionReflection(
publisher.merge(with: publisher,
publisher,
publisher,
publisher,
publisher,
publisher,
publisher) as Publishers.Merge8
)
try testMergeSideReflection {
$0.merge(with: publisher,
publisher,
publisher,
publisher,
publisher,
publisher,
publisher) as Publishers.Merge8
}
try testMergeSubscriptionReflection(
publisher.merge(with: publisher) as Publishers.MergeMany
)
try testMergeSideReflection {
$0.merge(with: $0) as Publishers.MergeMany
}
}
}
+4
View File
@@ -3,3 +3,7 @@ def suffix_variadic(name, index, arity):
def list_with_suffix_variadic(name, arity):
return [suffix_variadic(name, i, arity) for i in range(arity)]
def indent(input, space_count):
padding = space_count * ' '
return ''.join(padding + line for line in input.splitlines(True))