@@ -13,7 +13,7 @@ public extension Publisher {
13
13
/// Merges two publishers into a single publisher by combining each value
14
14
/// from self with the latest value from the second publisher, if any.
15
15
///
16
- /// - parameter other: Second observable source.
16
+ /// - parameter other: A second publisher source.
17
17
/// - parameter resultSelector: Function to invoke for each value from the self combined
18
18
/// with the latest value from the second source, if any.
19
19
///
@@ -22,19 +22,94 @@ public extension Publisher {
22
22
/// specified result selector function.
23
23
func withLatestFrom< Other: Publisher , Result> ( _ other: Other ,
24
24
resultSelector: @escaping ( Output , Other . Output ) -> Result )
25
- -> Publishers . WithLatestFrom < Self , Other , Result > {
26
- return . init( upstream: self , second: other, resultSelector: resultSelector)
25
+ -> Publishers . WithLatestFrom < Self , Other , Result > {
26
+ return . init( upstream: self , second: other, resultSelector: resultSelector)
27
+ }
28
+
29
+
30
+ /// Merges three publishers into a single publisher by combining each value
31
+ /// from self with the latest value from the second and third publisher, if any.
32
+ ///
33
+ /// - parameter other: A second publisher source.
34
+ /// - parameter other1: A third publisher source.
35
+ /// - parameter resultSelector: Function to invoke for each value from the self combined
36
+ /// with the latest value from the second and third source, if any.
37
+ ///
38
+ /// - returns: A publisher containing the result of combining each value of the self
39
+ /// with the latest value from the second and third publisher, if any, using the
40
+ /// specified result selector function.
41
+ func withLatestFrom< Other: Publisher , Other1: Publisher , Result> ( _ other: Other ,
42
+ _ other1: Other1 ,
43
+ resultSelector: @escaping ( Output , ( Other . Output , Other1 . Output ) ) -> Result )
44
+ -> Publishers . WithLatestFrom < Self , AnyPublisher < ( Other . Output , Other1 . Output ) , Self . Failure > , Result >
45
+ where Other. Failure == Failure , Other1. Failure == Failure {
46
+ let combined = other. combineLatest ( other1)
47
+ . eraseToAnyPublisher ( )
48
+ return . init( upstream: self , second: combined, resultSelector: resultSelector)
49
+ }
50
+
51
+ /// Merges four publishers into a single publisher by combining each value
52
+ /// from self with the latest value from the second, third and fourth publisher, if any.
53
+ ///
54
+ /// - parameter other: A second publisher source.
55
+ /// - parameter other1: A third publisher source.
56
+ /// - parameter other2: A fourth publisher source.
57
+ /// - parameter resultSelector: Function to invoke for each value from the self combined
58
+ /// with the latest value from the second, third and fourth source, if any.
59
+ ///
60
+ /// - returns: A publisher containing the result of combining each value of the self
61
+ /// with the latest value from the second, third and fourth publisher, if any, using the
62
+ /// specified result selector function.
63
+ func withLatestFrom< Other: Publisher , Other1: Publisher , Other2: Publisher , Result> ( _ other: Other ,
64
+ _ other1: Other1 ,
65
+ _ other2: Other2 ,
66
+ resultSelector: @escaping ( Output , ( Other . Output , Other1 . Output , Other2 . Output ) ) -> Result )
67
+ -> Publishers . WithLatestFrom < Self , AnyPublisher < ( Other . Output , Other1 . Output , Other2 . Output ) , Self . Failure > , Result >
68
+ where Other. Failure == Failure , Other1. Failure == Failure , Other2. Failure == Failure {
69
+ let combined = other. combineLatest ( other1, other2)
70
+ . eraseToAnyPublisher ( )
71
+ return . init( upstream: self , second: combined, resultSelector: resultSelector)
27
72
}
28
73
29
74
/// Upon an emission from self, emit the latest value from the
30
75
/// second publisher, if any exists.
31
76
///
32
- /// - parameter other: Second observable source.
77
+ /// - parameter other: A second publisher source.
33
78
///
34
79
/// - returns: A publisher containing the latest value from the second publisher, if any.
35
80
func withLatestFrom< Other: Publisher > ( _ other: Other )
36
- -> Publishers . WithLatestFrom < Self , Other , Other . Output > {
37
- return . init( upstream: self , second: other) { $1 }
81
+ -> Publishers . WithLatestFrom < Self , Other , Other . Output > {
82
+ return . init( upstream: self , second: other) { $1 }
83
+ }
84
+
85
+ /// Upon an emission from self, emit the latest value from the
86
+ /// second and third publisher, if any exists.
87
+ ///
88
+ /// - parameter other: A second publisher source.
89
+ /// - parameter other1: A third publisher source.
90
+ ///
91
+ /// - returns: A publisher containing the latest value from the second and third publisher, if any.
92
+ func withLatestFrom< Other: Publisher , Other1: Publisher > ( _ other: Other ,
93
+ _ other1: Other1 )
94
+ -> Publishers . WithLatestFrom < Self , AnyPublisher < ( Other . Output , Other1 . Output ) , Self . Failure > , ( Other . Output , Other1 . Output ) >
95
+ where Other. Failure == Failure , Other1. Failure == Failure {
96
+ withLatestFrom ( other, other1) { $1 }
97
+ }
98
+
99
+ /// Upon an emission from self, emit the latest value from the
100
+ /// second, third and forth publisher, if any exists.
101
+ ///
102
+ /// - parameter other: A second publisher source.
103
+ /// - parameter other1: A third publisher source.
104
+ /// - parameter other2: A forth publisher source.
105
+ ///
106
+ /// - returns: A publisher containing the latest value from the second, third and forth publisher, if any.
107
+ func withLatestFrom< Other: Publisher , Other1: Publisher , Other2: Publisher > ( _ other: Other ,
108
+ _ other1: Other1 ,
109
+ _ other2: Other2 )
110
+ -> Publishers . WithLatestFrom < Self , AnyPublisher < ( Other . Output , Other1 . Output , Other2 . Output ) , Self . Failure > , ( Other . Output , Other1 . Output , Other2 . Output ) >
111
+ where Other. Failure == Failure , Other1. Failure == Failure , Other2. Failure == Failure {
112
+ withLatestFrom ( other, other1, other2) { $1 }
38
113
}
39
114
}
40
115
0 commit comments