@@ -52,26 +52,48 @@ public extension Publisher {
52
52
func forward< Root: AnyObject , S: Subject > (
53
53
to keyPath: KeyPath < Root , S > ,
54
54
on object: Root ,
55
- ownership: ObjectOwnership
55
+ ownership: ObjectOwnership ,
56
+ includeFinished: Bool
56
57
) -> AnyCancellable
57
58
where S. Output == Output , S. Failure == Failure
58
59
{
59
60
switch ownership {
60
61
case . strong:
61
62
return sink {
62
- object [ keyPath: keyPath] . send ( completion: $0)
63
+ switch $0 {
64
+ case . failure:
65
+ object [ keyPath: keyPath] . send ( completion: $0)
66
+ case . finished:
67
+ if includeFinished {
68
+ object [ keyPath: keyPath] . send ( completion: $0)
69
+ }
70
+ }
63
71
} receiveValue: {
64
72
object [ keyPath: keyPath] . send ( $0)
65
73
}
66
74
case . weak:
67
75
return sink { [ weak object] in
68
- object ? [ keyPath: keyPath] . send ( completion: $0)
76
+ switch $0 {
77
+ case . failure:
78
+ object ? [ keyPath: keyPath] . send ( completion: $0)
79
+ case . finished:
80
+ if includeFinished {
81
+ object ? [ keyPath: keyPath] . send ( completion: $0)
82
+ }
83
+ }
69
84
} receiveValue: { [ weak object] in
70
85
object ? [ keyPath: keyPath] . send ( $0)
71
86
}
72
87
case . unowned:
73
88
return sink { [ unowned object] in
74
- object [ keyPath: keyPath] . send ( completion: $0)
89
+ switch $0 {
90
+ case . failure:
91
+ object [ keyPath: keyPath] . send ( completion: $0)
92
+ case . finished:
93
+ if includeFinished {
94
+ object [ keyPath: keyPath] . send ( completion: $0)
95
+ }
96
+ }
75
97
} receiveValue: {
76
98
object [ keyPath: keyPath] . send ( $0)
77
99
}
@@ -81,32 +103,57 @@ public extension Publisher {
81
103
func forward< Root1: AnyObject , Root2: AnyObject , S1: Subject , S2: Subject > (
82
104
to keyPath1: KeyPath < Root1 , S1 > , on object1: Root1 ,
83
105
and keyPath2: KeyPath < Root2 , S2 > , on object2: Root2 ,
84
- ownership: ObjectOwnership
106
+ ownership: ObjectOwnership ,
107
+ includeFinished: Bool
85
108
) -> AnyCancellable
86
109
where S1. Output == Output , S1. Failure == Failure ,
87
110
S2. Output == Output , S2. Failure == Failure
88
111
{
89
112
switch ownership {
90
113
case . strong:
91
114
return sink {
92
- object1 [ keyPath: keyPath1] . send ( completion: $0)
93
- object2 [ keyPath: keyPath2] . send ( completion: $0)
115
+ switch $0 {
116
+ case . failure:
117
+ object1 [ keyPath: keyPath1] . send ( completion: $0)
118
+ object2 [ keyPath: keyPath2] . send ( completion: $0)
119
+ case . finished:
120
+ if includeFinished {
121
+ object1 [ keyPath: keyPath1] . send ( completion: $0)
122
+ object2 [ keyPath: keyPath2] . send ( completion: $0)
123
+ }
124
+ }
94
125
} receiveValue: {
95
126
object1 [ keyPath: keyPath1] . send ( $0)
96
127
object2 [ keyPath: keyPath2] . send ( $0)
97
128
}
98
129
case . weak:
99
130
return sink { [ weak object1, weak object2] in
100
- object1 ? [ keyPath: keyPath1] . send ( completion: $0)
101
- object2 ? [ keyPath: keyPath2] . send ( completion: $0)
131
+ switch $0 {
132
+ case . failure:
133
+ object1 ? [ keyPath: keyPath1] . send ( completion: $0)
134
+ object2 ? [ keyPath: keyPath2] . send ( completion: $0)
135
+ case . finished:
136
+ if includeFinished {
137
+ object1 ? [ keyPath: keyPath1] . send ( completion: $0)
138
+ object2 ? [ keyPath: keyPath2] . send ( completion: $0)
139
+ }
140
+ }
102
141
} receiveValue: { [ weak object1, weak object2] in
103
142
object1 ? [ keyPath: keyPath1] . send ( $0)
104
143
object2 ? [ keyPath: keyPath2] . send ( $0)
105
144
}
106
145
case . unowned:
107
146
return sink { [ unowned object1, unowned object2] in
108
- object1 [ keyPath: keyPath1] . send ( completion: $0)
109
- object2 [ keyPath: keyPath2] . send ( completion: $0)
147
+ switch $0 {
148
+ case . failure:
149
+ object1 [ keyPath: keyPath1] . send ( completion: $0)
150
+ object2 [ keyPath: keyPath2] . send ( completion: $0)
151
+ case . finished:
152
+ if includeFinished {
153
+ object1 [ keyPath: keyPath1] . send ( completion: $0)
154
+ object2 [ keyPath: keyPath2] . send ( completion: $0)
155
+ }
156
+ }
110
157
} receiveValue: { [ unowned object1, unowned object2] in
111
158
object1 [ keyPath: keyPath1] . send ( $0)
112
159
object2 [ keyPath: keyPath2] . send ( $0)
@@ -118,7 +165,8 @@ public extension Publisher {
118
165
to keyPath1: KeyPath < Root1 , S1 > , on object1: Root1 ,
119
166
and keyPath2: KeyPath < Root2 , S2 > , on object2: Root2 ,
120
167
and keyPath3: KeyPath < Root3 , S3 > , on object3: Root3 ,
121
- ownership: ObjectOwnership
168
+ ownership: ObjectOwnership ,
169
+ includeFinished: Bool
122
170
) -> AnyCancellable
123
171
where S1. Output == Output , S1. Failure == Failure ,
124
172
S2. Output == Output , S2. Failure == Failure ,
@@ -127,29 +175,56 @@ public extension Publisher {
127
175
switch ownership {
128
176
case . strong:
129
177
return sink {
130
- object1 [ keyPath: keyPath1] . send ( completion: $0)
131
- object2 [ keyPath: keyPath2] . send ( completion: $0)
132
- object3 [ keyPath: keyPath3] . send ( completion: $0)
178
+ switch $0 {
179
+ case . failure:
180
+ object1 [ keyPath: keyPath1] . send ( completion: $0)
181
+ object2 [ keyPath: keyPath2] . send ( completion: $0)
182
+ object3 [ keyPath: keyPath3] . send ( completion: $0)
183
+ case . finished:
184
+ if includeFinished {
185
+ object1 [ keyPath: keyPath1] . send ( completion: $0)
186
+ object2 [ keyPath: keyPath2] . send ( completion: $0)
187
+ object3 [ keyPath: keyPath3] . send ( completion: $0)
188
+ }
189
+ }
133
190
} receiveValue: {
134
191
object1 [ keyPath: keyPath1] . send ( $0)
135
192
object2 [ keyPath: keyPath2] . send ( $0)
136
193
object3 [ keyPath: keyPath3] . send ( $0)
137
194
}
138
195
case . weak:
139
196
return sink { [ weak object1, weak object2, weak object3] in
140
- object1 ? [ keyPath: keyPath1] . send ( completion: $0)
141
- object2 ? [ keyPath: keyPath2] . send ( completion: $0)
142
- object3 ? [ keyPath: keyPath3] . send ( completion: $0)
197
+ switch $0 {
198
+ case . failure:
199
+ object1 ? [ keyPath: keyPath1] . send ( completion: $0)
200
+ object2 ? [ keyPath: keyPath2] . send ( completion: $0)
201
+ object3 ? [ keyPath: keyPath3] . send ( completion: $0)
202
+ case . finished:
203
+ if includeFinished {
204
+ object1 ? [ keyPath: keyPath1] . send ( completion: $0)
205
+ object2 ? [ keyPath: keyPath2] . send ( completion: $0)
206
+ object3 ? [ keyPath: keyPath3] . send ( completion: $0)
207
+ }
208
+ }
143
209
} receiveValue: { [ weak object1, weak object2, weak object3] in
144
210
object1 ? [ keyPath: keyPath1] . send ( $0)
145
211
object2 ? [ keyPath: keyPath2] . send ( $0)
146
212
object3 ? [ keyPath: keyPath3] . send ( $0)
147
213
}
148
214
case . unowned:
149
215
return sink { [ unowned object1, unowned object2, unowned object3] in
150
- object1 [ keyPath: keyPath1] . send ( completion: $0)
151
- object2 [ keyPath: keyPath2] . send ( completion: $0)
152
- object3 [ keyPath: keyPath3] . send ( completion: $0)
216
+ switch $0 {
217
+ case . failure:
218
+ object1 [ keyPath: keyPath1] . send ( completion: $0)
219
+ object2 [ keyPath: keyPath2] . send ( completion: $0)
220
+ object3 [ keyPath: keyPath3] . send ( completion: $0)
221
+ case . finished:
222
+ if includeFinished {
223
+ object1 [ keyPath: keyPath1] . send ( completion: $0)
224
+ object2 [ keyPath: keyPath2] . send ( completion: $0)
225
+ object3 [ keyPath: keyPath3] . send ( completion: $0)
226
+ }
227
+ }
153
228
} receiveValue: { [ unowned object1, unowned object2] in
154
229
object1 [ keyPath: keyPath1] . send ( $0)
155
230
object2 [ keyPath: keyPath2] . send ( $0)
0 commit comments