Skip to content

Commit b32a0f0

Browse files
committed
Adds tuple versions of operators for SharedSequence.zip (collection), SharedSequence.zip, SharedSequence.combineLatest (collection), SharedSequence.combineLatest.
1 parent a6d508a commit b32a0f0

File tree

10 files changed

+558
-148
lines changed

10 files changed

+558
-148
lines changed

RxCocoa/Traits/SharedSequence/SharedSequence+Operators+arity.swift

Lines changed: 371 additions & 63 deletions
Large diffs are not rendered by default.

RxCocoa/Traits/SharedSequence/SharedSequence+Operators+arity.tt

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,30 @@ extension SharedSequence {
2323
*/
2424
public static func zip<<%= (Array(1...i).map { "O\($0): SharedSequenceConvertibleType" }).joined(separator: ", ") %>>
2525
(<%= (Array(1...i).map { "_ source\($0): O\($0)" }).joined(separator: ", ") %>, resultSelector: @escaping (<%= (Array(1...i).map { "O\($0).E" }).joined(separator: ", ") %>) throws -> E)
26-
-> SharedSequence<O1.SharingStrategy, E> where <%= (Array(2...i).map { "O1.SharingStrategy == O\($0).SharingStrategy" }).joined(separator: ",\n ") %> {
26+
-> SharedSequence<O1.SharingStrategy, E> where <%= (Array(1...i).map { "SharingStrategy == O\($0).SharingStrategy" }).joined(separator: ",\n ") %> {
2727
let source = Observable.zip(
2828
<%= (Array(1...i).map { "source\($0).asSharedSequence().asObservable()" }).joined(separator: ", ") %>,
2929
resultSelector: resultSelector
3030
)
3131

32-
return SharedSequence<O1.SharingStrategy, E>(source)
32+
return SharedSequence<SharingStrategy, E>(source)
33+
}
34+
}
35+
36+
extension SharedSequence where Element == Any {
37+
/**
38+
Merges the specified observable sequences into one observable sequence of element tuples whenever all of the observable sequences have produced an element at a corresponding index.
39+
40+
- returns: An observable sequence containing the result of combining elements of the sources.
41+
*/
42+
public static func zip<<%= (Array(1...i).map { "O\($0): SharedSequenceConvertibleType" }).joined(separator: ", ") %>>
43+
(<%= (Array(1...i).map { "_ source\($0): O\($0)" }).joined(separator: ", ") %>)
44+
-> SharedSequence<O1.SharingStrategy, (<%= (Array(1...i).map { "O\($0).E" }).joined(separator: ", ") %>)> where <%= (Array(1...i).map { "SharingStrategy == O\($0).SharingStrategy" }).joined(separator: ",\n ") %> {
45+
let source = Observable.zip(
46+
<%= (Array(1...i).map { "source\($0).asSharedSequence().asObservable()" }).joined(separator: ", ") %>
47+
)
48+
49+
return SharedSequence<SharingStrategy, (<%= (Array(1...i).map { "O\($0).E" }).joined(separator: ", ") %>)>(source)
3350
}
3451
}
3552

@@ -42,7 +59,7 @@ extension SharedSequence {
4259
*/
4360
public static func combineLatest<<%= (Array(1...i).map { "O\($0): SharedSequenceConvertibleType" }).joined(separator: ", ") %>>
4461
(<%= (Array(1...i).map { "_ source\($0): O\($0)" }).joined(separator: ", ") %>, resultSelector: @escaping (<%= (Array(1...i).map { "O\($0).E" }).joined(separator: ", ") %>) throws -> E)
45-
-> SharedSequence<O1.SharingStrategy, E> where <%= (Array(2...i).map { "O1.SharingStrategy == O\($0).SharingStrategy" }).joined(separator: ",\n ") %> {
62+
-> SharedSequence<SharingStrategy, E> where <%= (Array(1...i).map { "SharingStrategy == O\($0).SharingStrategy" }).joined(separator: ",\n ") %> {
4663
let source = Observable.combineLatest(
4764
<%= (Array(1...i).map { "source\($0).asSharedSequence().asObservable()" }).joined(separator: ", ") %>,
4865
resultSelector: resultSelector
@@ -52,4 +69,21 @@ extension SharedSequence {
5269
}
5370
}
5471

72+
extension SharedSequence where Element == Any {
73+
/**
74+
Merges the specified observable sequences into one observable sequence of element tuples whenever any of the observable sequences produces an element.
75+
76+
- returns: An observable sequence containing the result of combining elements of the sources.
77+
*/
78+
public static func combineLatest<<%= (Array(1...i).map { "O\($0): SharedSequenceConvertibleType" }).joined(separator: ", ") %>>
79+
(<%= (Array(1...i).map { "_ source\($0): O\($0)" }).joined(separator: ", ") %>)
80+
-> SharedSequence<SharingStrategy, (<%= (Array(1...i).map { "O\($0).E" }).joined(separator: ", ") %>)> where <%= (Array(1...i).map { "SharingStrategy == O\($0).SharingStrategy" }).joined(separator: ",\n ") %> {
81+
let source = Observable.combineLatest(
82+
<%= (Array(1...i).map { "source\($0).asSharedSequence().asObservable()" }).joined(separator: ", ") %>
83+
)
84+
85+
return SharedSequence<O1.SharingStrategy, (<%= (Array(1...i).map { "O\($0).E" }).joined(separator: ", ") %>)>(source)
86+
}
87+
}
88+
5589
<% } %>

RxCocoa/Traits/SharedSequence/SharedSequence+Operators.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,17 @@ extension SharedSequence {
384384
let source = Observable.zip(collection.map { $0.asSharedSequence().asObservable() }, resultSelector)
385385
return SharedSequence<SharingStrategy, R>(source)
386386
}
387+
388+
/**
389+
Merges the specified observable sequences into one observable sequence all of the observable sequences have produced an element at a corresponding index.
390+
391+
- returns: An observable sequence containing the result of combining elements of the sources.
392+
*/
393+
public static func zip<C: Collection>(_ collection: C) -> SharedSequence<SharingStrategy, [Element]>
394+
where C.Iterator.Element == SharedSequence<SharingStrategy, Element> {
395+
let source = Observable.zip(collection.map { $0.asSharedSequence().asObservable() })
396+
return SharedSequence<SharingStrategy, [Element]>(source)
397+
}
387398
}
388399

389400
// MARK: combineLatest
@@ -400,6 +411,17 @@ extension SharedSequence {
400411
let source = Observable.combineLatest(collection.map { $0.asObservable() }, resultSelector)
401412
return SharedSequence<SharingStrategy, R>(source)
402413
}
414+
415+
/**
416+
Merges the specified observable sequences into one observable sequence whenever any of the observable sequences produces an element.
417+
418+
- returns: An observable sequence containing the result of combining elements of the sources.
419+
*/
420+
public static func combineLatest<C: Collection>(_ collection: C) -> SharedSequence<SharingStrategy, [Element]>
421+
where C.Iterator.Element == SharedSequence<SharingStrategy, Element> {
422+
let source = Observable.combineLatest(collection.map { $0.asObservable() })
423+
return SharedSequence<SharingStrategy, [Element]>(source)
424+
}
403425
}
404426

405427
// MARK: withLatestFrom

RxSwift/Observables/CombineLatest+Collection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension Observable {
2525

2626
- seealso: [combinelatest operator on reactivex.io](http://reactivex.io/documentation/operators/combinelatest.html)
2727

28-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
28+
- returns: An observable sequence containing the result of combining elements of the sources.
2929
*/
3030
public static func combineLatest<C: Collection>(_ collection: C) -> Observable<[Element]>
3131
where C.Iterator.Element: ObservableType, C.Iterator.Element.E == Element {

RxSwift/Observables/CombineLatest+arity.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extension ObservableType where E == Any {
3636

3737
- seealso: [combineLatest operator on reactivex.io](http://reactivex.io/documentation/operators/combinelatest.html)
3838

39-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
39+
- returns: An observable sequence containing the result of combining elements of the sources.
4040
*/
4141
public static func combineLatest<O1: ObservableType, O2: ObservableType>
4242
(_ source1: O1, _ source2: O2)
@@ -134,7 +134,7 @@ extension ObservableType where E == Any {
134134

135135
- seealso: [combineLatest operator on reactivex.io](http://reactivex.io/documentation/operators/combinelatest.html)
136136

137-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
137+
- returns: An observable sequence containing the result of combining elements of the sources.
138138
*/
139139
public static func combineLatest<O1: ObservableType, O2: ObservableType, O3: ObservableType>
140140
(_ source1: O1, _ source2: O2, _ source3: O3)
@@ -239,7 +239,7 @@ extension ObservableType where E == Any {
239239

240240
- seealso: [combineLatest operator on reactivex.io](http://reactivex.io/documentation/operators/combinelatest.html)
241241

242-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
242+
- returns: An observable sequence containing the result of combining elements of the sources.
243243
*/
244244
public static func combineLatest<O1: ObservableType, O2: ObservableType, O3: ObservableType, O4: ObservableType>
245245
(_ source1: O1, _ source2: O2, _ source3: O3, _ source4: O4)
@@ -351,7 +351,7 @@ extension ObservableType where E == Any {
351351

352352
- seealso: [combineLatest operator on reactivex.io](http://reactivex.io/documentation/operators/combinelatest.html)
353353

354-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
354+
- returns: An observable sequence containing the result of combining elements of the sources.
355355
*/
356356
public static func combineLatest<O1: ObservableType, O2: ObservableType, O3: ObservableType, O4: ObservableType, O5: ObservableType>
357357
(_ source1: O1, _ source2: O2, _ source3: O3, _ source4: O4, _ source5: O5)
@@ -470,7 +470,7 @@ extension ObservableType where E == Any {
470470

471471
- seealso: [combineLatest operator on reactivex.io](http://reactivex.io/documentation/operators/combinelatest.html)
472472

473-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
473+
- returns: An observable sequence containing the result of combining elements of the sources.
474474
*/
475475
public static func combineLatest<O1: ObservableType, O2: ObservableType, O3: ObservableType, O4: ObservableType, O5: ObservableType, O6: ObservableType>
476476
(_ source1: O1, _ source2: O2, _ source3: O3, _ source4: O4, _ source5: O5, _ source6: O6)
@@ -596,7 +596,7 @@ extension ObservableType where E == Any {
596596

597597
- seealso: [combineLatest operator on reactivex.io](http://reactivex.io/documentation/operators/combinelatest.html)
598598

599-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
599+
- returns: An observable sequence containing the result of combining elements of the sources.
600600
*/
601601
public static func combineLatest<O1: ObservableType, O2: ObservableType, O3: ObservableType, O4: ObservableType, O5: ObservableType, O6: ObservableType, O7: ObservableType>
602602
(_ source1: O1, _ source2: O2, _ source3: O3, _ source4: O4, _ source5: O5, _ source6: O6, _ source7: O7)
@@ -729,7 +729,7 @@ extension ObservableType where E == Any {
729729

730730
- seealso: [combineLatest operator on reactivex.io](http://reactivex.io/documentation/operators/combinelatest.html)
731731

732-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
732+
- returns: An observable sequence containing the result of combining elements of the sources.
733733
*/
734734
public static func combineLatest<O1: ObservableType, O2: ObservableType, O3: ObservableType, O4: ObservableType, O5: ObservableType, O6: ObservableType, O7: ObservableType, O8: ObservableType>
735735
(_ source1: O1, _ source2: O2, _ source3: O3, _ source4: O4, _ source5: O5, _ source6: O6, _ source7: O7, _ source8: O8)

RxSwift/Observables/CombineLatest+arity.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension ObservableType where E == Any {
3535

3636
- seealso: [combineLatest operator on reactivex.io](http://reactivex.io/documentation/operators/combinelatest.html)
3737

38-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
38+
- returns: An observable sequence containing the result of combining elements of the sources.
3939
*/
4040
public static func combineLatest<<%= (Array(1...i).map { "O\($0): ObservableType" }).joined(separator: ", ") %>>
4141
(<%= (Array(1...i).map { "_ source\($0): O\($0)" }).joined(separator: ", ") %>)

RxSwift/Observables/Zip+Collection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension Observable {
2525

2626
- seealso: [zip operator on reactivex.io](http://reactivex.io/documentation/operators/zip.html)
2727

28-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
28+
- returns: An observable sequence containing the result of combining elements of the sources.
2929
*/
3030
public static func zip<C: Collection>(_ collection: C) -> Observable<[Element]>
3131
where C.Iterator.Element: ObservableType, C.Iterator.Element.E == Element {

RxSwift/Observables/Zip+arity.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extension ObservableType where E == Any {
3636

3737
- seealso: [zip operator on reactivex.io](http://reactivex.io/documentation/operators/zip.html)
3838

39-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
39+
- returns: An observable sequence containing the result of combining elements of the sources.
4040
*/
4141
public static func zip<O1: ObservableType, O2: ObservableType>
4242
(_ source1: O1, _ source2: O2)
@@ -146,7 +146,7 @@ extension ObservableType where E == Any {
146146

147147
- seealso: [zip operator on reactivex.io](http://reactivex.io/documentation/operators/zip.html)
148148

149-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
149+
- returns: An observable sequence containing the result of combining elements of the sources.
150150
*/
151151
public static func zip<O1: ObservableType, O2: ObservableType, O3: ObservableType>
152152
(_ source1: O1, _ source2: O2, _ source3: O3)
@@ -264,7 +264,7 @@ extension ObservableType where E == Any {
264264

265265
- seealso: [zip operator on reactivex.io](http://reactivex.io/documentation/operators/zip.html)
266266

267-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
267+
- returns: An observable sequence containing the result of combining elements of the sources.
268268
*/
269269
public static func zip<O1: ObservableType, O2: ObservableType, O3: ObservableType, O4: ObservableType>
270270
(_ source1: O1, _ source2: O2, _ source3: O3, _ source4: O4)
@@ -390,7 +390,7 @@ extension ObservableType where E == Any {
390390

391391
- seealso: [zip operator on reactivex.io](http://reactivex.io/documentation/operators/zip.html)
392392

393-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
393+
- returns: An observable sequence containing the result of combining elements of the sources.
394394
*/
395395
public static func zip<O1: ObservableType, O2: ObservableType, O3: ObservableType, O4: ObservableType, O5: ObservableType>
396396
(_ source1: O1, _ source2: O2, _ source3: O3, _ source4: O4, _ source5: O5)
@@ -524,7 +524,7 @@ extension ObservableType where E == Any {
524524

525525
- seealso: [zip operator on reactivex.io](http://reactivex.io/documentation/operators/zip.html)
526526

527-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
527+
- returns: An observable sequence containing the result of combining elements of the sources.
528528
*/
529529
public static func zip<O1: ObservableType, O2: ObservableType, O3: ObservableType, O4: ObservableType, O5: ObservableType, O6: ObservableType>
530530
(_ source1: O1, _ source2: O2, _ source3: O3, _ source4: O4, _ source5: O5, _ source6: O6)
@@ -666,7 +666,7 @@ extension ObservableType where E == Any {
666666

667667
- seealso: [zip operator on reactivex.io](http://reactivex.io/documentation/operators/zip.html)
668668

669-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
669+
- returns: An observable sequence containing the result of combining elements of the sources.
670670
*/
671671
public static func zip<O1: ObservableType, O2: ObservableType, O3: ObservableType, O4: ObservableType, O5: ObservableType, O6: ObservableType, O7: ObservableType>
672672
(_ source1: O1, _ source2: O2, _ source3: O3, _ source4: O4, _ source5: O5, _ source6: O6, _ source7: O7)
@@ -816,7 +816,7 @@ extension ObservableType where E == Any {
816816

817817
- seealso: [zip operator on reactivex.io](http://reactivex.io/documentation/operators/zip.html)
818818

819-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
819+
- returns: An observable sequence containing the result of combining elements of the sources.
820820
*/
821821
public static func zip<O1: ObservableType, O2: ObservableType, O3: ObservableType, O4: ObservableType, O5: ObservableType, O6: ObservableType, O7: ObservableType, O8: ObservableType>
822822
(_ source1: O1, _ source2: O2, _ source3: O3, _ source4: O4, _ source5: O5, _ source6: O6, _ source7: O7, _ source8: O8)

RxSwift/Observables/Zip+arity.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension ObservableType where E == Any {
3535

3636
- seealso: [zip operator on reactivex.io](http://reactivex.io/documentation/operators/zip.html)
3737

38-
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function.
38+
- returns: An observable sequence containing the result of combining elements of the sources.
3939
*/
4040
public static func zip<<%= (Array(1...i).map { "O\($0): ObservableType" }).joined(separator: ", ") %>>
4141
(<%= (Array(1...i).map { "_ source\($0): O\($0)" }).joined(separator: ", ") %>)

0 commit comments

Comments
 (0)