Skip to content
This repository was archived by the owner on Dec 5, 2019. It is now read-only.

Commit b6d37d1

Browse files
committed
Add combineLatest and zip over multiple HotSignals
1 parent 8ee30ec commit b6d37d1

File tree

3 files changed

+166
-0
lines changed

3 files changed

+166
-0
lines changed

ReactiveCocoa.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/* Begin PBXBuildFile section */
1010
270DE4451A1EAB4600151031 /* ObservablePropertySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277F6A951A1EAA10003E0EC9 /* ObservablePropertySpec.swift */; };
1111
270DE4461A1EACA200151031 /* ObservablePropertySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277F6A951A1EAA10003E0EC9 /* ObservablePropertySpec.swift */; };
12+
D00004091A46864E000E7D41 /* TupleExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00004081A46864E000E7D41 /* TupleExtensions.swift */; };
13+
D000040A1A46864E000E7D41 /* TupleExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00004081A46864E000E7D41 /* TupleExtensions.swift */; };
1214
D01792021A34D79100A7B229 /* ColdSignalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01792011A34D79100A7B229 /* ColdSignalSpec.swift */; };
1315
D01792031A34D79100A7B229 /* ColdSignalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01792011A34D79100A7B229 /* ColdSignalSpec.swift */; };
1416
D01B7B6219EDD8FE00D26E01 /* Nimble.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = D05E662419EDD82000904ACA /* Nimble.framework */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
@@ -474,6 +476,7 @@
474476

475477
/* Begin PBXFileReference section */
476478
277F6A951A1EAA10003E0EC9 /* ObservablePropertySpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObservablePropertySpec.swift; sourceTree = "<group>"; };
479+
D00004081A46864E000E7D41 /* TupleExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TupleExtensions.swift; sourceTree = "<group>"; };
477480
D01792011A34D79100A7B229 /* ColdSignalSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColdSignalSpec.swift; sourceTree = "<group>"; };
478481
D037642A19EDA41200A782A9 /* NSArray+RACSequenceAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+RACSequenceAdditions.h"; sourceTree = "<group>"; };
479482
D037642B19EDA41200A782A9 /* NSArray+RACSequenceAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+RACSequenceAdditions.m"; sourceTree = "<group>"; };
@@ -1116,6 +1119,7 @@
11161119
D0C312BB19EF2A5800984962 /* Atomic.swift */,
11171120
D0C312BC19EF2A5800984962 /* Bag.swift */,
11181121
D0C312C519EF2A5800984962 /* OptionalExtensions.swift */,
1122+
D00004081A46864E000E7D41 /* TupleExtensions.swift */,
11191123
);
11201124
name = "Internal Utilities";
11211125
sourceTree = "<group>";
@@ -1588,6 +1592,7 @@
15881592
D03765C819EDA41200A782A9 /* RACScopedDisposable.m in Sources */,
15891593
D03764FE19EDA41200A782A9 /* NSEnumerator+RACSequenceAdditions.m in Sources */,
15901594
D03764EA19EDA41200A782A9 /* NSArray+RACSequenceAdditions.m in Sources */,
1595+
D00004091A46864E000E7D41 /* TupleExtensions.swift in Sources */,
15911596
D0C312E119EF2A5800984962 /* OptionalExtensions.swift in Sources */,
15921597
D03765C019EDA41200A782A9 /* RACScheduler.m in Sources */,
15931598
D0C312D519EF2A5800984962 /* Errors.swift in Sources */,
@@ -1792,6 +1797,7 @@
17921797
D03B4A3E19F4C39A009E02AC /* FoundationExtensions.swift in Sources */,
17931798
D037657519EDA41200A782A9 /* RACDynamicSequence.m in Sources */,
17941799
D037657119EDA41200A782A9 /* RACDisposable.m in Sources */,
1800+
D000040A1A46864E000E7D41 /* TupleExtensions.swift in Sources */,
17951801
D03765DB19EDA41200A782A9 /* RACSignalProvider.d in Sources */,
17961802
D037653319EDA41200A782A9 /* NSSet+RACSequenceAdditions.m in Sources */,
17971803
D037665319EDA41200A782A9 /* UISwitch+RACSignalSupport.m in Sources */,

ReactiveCocoa/Swift/HotSignal.swift

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,114 @@ extension HotSignal {
592592
}
593593
}
594594

595+
/// An overloaded function that combines the values of up to 10 signals, in the
596+
/// manner described by HotSignal.combineLatestWith().
597+
public func combineLatest<A, B>(a: HotSignal<A>, b: HotSignal<B>) -> HotSignal<(A, B)> {
598+
return a.combineLatestWith(b)
599+
}
600+
601+
public func combineLatest<A, B, C>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>) -> HotSignal<(A, B, C)> {
602+
return combineLatest(a, b)
603+
.combineLatestWith(c)
604+
.map(repack)
605+
}
606+
607+
public func combineLatest<A, B, C, D>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>, d: HotSignal<D>) -> HotSignal<(A, B, C, D)> {
608+
return combineLatest(a, b, c)
609+
.combineLatestWith(d)
610+
.map(repack)
611+
}
612+
613+
public func combineLatest<A, B, C, D, E>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>, d: HotSignal<D>, e: HotSignal<E>) -> HotSignal<(A, B, C, D, E)> {
614+
return combineLatest(a, b, c, d)
615+
.combineLatestWith(e)
616+
.map(repack)
617+
}
618+
619+
public func combineLatest<A, B, C, D, E, F>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>, d: HotSignal<D>, e: HotSignal<E>, f: HotSignal<F>) -> HotSignal<(A, B, C, D, E, F)> {
620+
return combineLatest(a, b, c, d, e)
621+
.combineLatestWith(f)
622+
.map(repack)
623+
}
624+
625+
public func combineLatest<A, B, C, D, E, F, G>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>, d: HotSignal<D>, e: HotSignal<E>, f: HotSignal<F>, g: HotSignal<G>) -> HotSignal<(A, B, C, D, E, F, G)> {
626+
return combineLatest(a, b, c, d, e, f)
627+
.combineLatestWith(g)
628+
.map(repack)
629+
}
630+
631+
public func combineLatest<A, B, C, D, E, F, G, H>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>, d: HotSignal<D>, e: HotSignal<E>, f: HotSignal<F>, g: HotSignal<G>, h: HotSignal<H>) -> HotSignal<(A, B, C, D, E, F, G, H)> {
632+
return combineLatest(a, b, c, d, e, f, g)
633+
.combineLatestWith(h)
634+
.map(repack)
635+
}
636+
637+
public func combineLatest<A, B, C, D, E, F, G, H, I>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>, d: HotSignal<D>, e: HotSignal<E>, f: HotSignal<F>, g: HotSignal<G>, h: HotSignal<H>, i: HotSignal<I>) -> HotSignal<(A, B, C, D, E, F, G, H, I)> {
638+
return combineLatest(a, b, c, d, e, f, g, h)
639+
.combineLatestWith(i)
640+
.map(repack)
641+
}
642+
643+
public func combineLatest<A, B, C, D, E, F, G, H, I, J>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>, d: HotSignal<D>, e: HotSignal<E>, f: HotSignal<F>, g: HotSignal<G>, h: HotSignal<H>, i: HotSignal<I>, j: HotSignal<J>) -> HotSignal<(A, B, C, D, E, F, G, H, I, J)> {
644+
return combineLatest(a, b, c, d, e, f, g, h, i)
645+
.combineLatestWith(j)
646+
.map(repack)
647+
}
648+
649+
/// An overloaded function that zips the values of up to 10 signals, in the
650+
/// manner described by HotSignal.zipWith().
651+
public func zip<A, B>(a: HotSignal<A>, b: HotSignal<B>) -> HotSignal<(A, B)> {
652+
return a.zipWith(b)
653+
}
654+
655+
public func zip<A, B, C>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>) -> HotSignal<(A, B, C)> {
656+
return zip(a, b)
657+
.zipWith(c)
658+
.map(repack)
659+
}
660+
661+
public func zip<A, B, C, D>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>, d: HotSignal<D>) -> HotSignal<(A, B, C, D)> {
662+
return zip(a, b, c)
663+
.zipWith(d)
664+
.map(repack)
665+
}
666+
667+
public func zip<A, B, C, D, E>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>, d: HotSignal<D>, e: HotSignal<E>) -> HotSignal<(A, B, C, D, E)> {
668+
return zip(a, b, c, d)
669+
.zipWith(e)
670+
.map(repack)
671+
}
672+
673+
public func zip<A, B, C, D, E, F>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>, d: HotSignal<D>, e: HotSignal<E>, f: HotSignal<F>) -> HotSignal<(A, B, C, D, E, F)> {
674+
return zip(a, b, c, d, e)
675+
.zipWith(f)
676+
.map(repack)
677+
}
678+
679+
public func zip<A, B, C, D, E, F, G>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>, d: HotSignal<D>, e: HotSignal<E>, f: HotSignal<F>, g: HotSignal<G>) -> HotSignal<(A, B, C, D, E, F, G)> {
680+
return zip(a, b, c, d, e, f)
681+
.zipWith(g)
682+
.map(repack)
683+
}
684+
685+
public func zip<A, B, C, D, E, F, G, H>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>, d: HotSignal<D>, e: HotSignal<E>, f: HotSignal<F>, g: HotSignal<G>, h: HotSignal<H>) -> HotSignal<(A, B, C, D, E, F, G, H)> {
686+
return zip(a, b, c, d, e, f, g)
687+
.zipWith(h)
688+
.map(repack)
689+
}
690+
691+
public func zip<A, B, C, D, E, F, G, H, I>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>, d: HotSignal<D>, e: HotSignal<E>, f: HotSignal<F>, g: HotSignal<G>, h: HotSignal<H>, i: HotSignal<I>) -> HotSignal<(A, B, C, D, E, F, G, H, I)> {
692+
return zip(a, b, c, d, e, f, g, h)
693+
.zipWith(i)
694+
.map(repack)
695+
}
696+
697+
public func zip<A, B, C, D, E, F, G, H, I, J>(a: HotSignal<A>, b: HotSignal<B>, c: HotSignal<C>, d: HotSignal<D>, e: HotSignal<E>, f: HotSignal<F>, g: HotSignal<G>, h: HotSignal<H>, i: HotSignal<I>, j: HotSignal<J>) -> HotSignal<(A, B, C, D, E, F, G, H, I, J)> {
698+
return zip(a, b, c, d, e, f, g, h, i)
699+
.zipWith(j)
700+
.map(repack)
701+
}
702+
595703
/// Conversions from HotSignal to ColdSignal.
596704
extension HotSignal {
597705
/// Buffers `count` values, starting at the time of the method invocation.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// TupleExtensions.swift
3+
// ReactiveCocoa
4+
//
5+
// Created by Justin Spahr-Summers on 2014-12-20.
6+
// Copyright (c) 2014 GitHub. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
/// Adds a value into an N-tuple, returning an (N+1)-tuple.
12+
///
13+
/// Supports creating tuples up to 10 elements long.
14+
internal func repack<A>(t: (), value: A) -> (A) {
15+
return (value)
16+
}
17+
18+
internal func repack<A, B>(t: (A), value: B) -> (A, B) {
19+
return (t.0, value)
20+
}
21+
22+
internal func repack<A, B, C>(t: (A, B), value: C) -> (A, B, C) {
23+
return (t.0, t.1, value)
24+
}
25+
26+
internal func repack<A, B, C, D>(t: (A, B, C), value: D) -> (A, B, C, D) {
27+
return (t.0, t.1, t.2, value)
28+
}
29+
30+
internal func repack<A, B, C, D, E>(t: (A, B, C, D), value: E) -> (A, B, C, D, E) {
31+
return (t.0, t.1, t.2, t.3, value)
32+
}
33+
34+
internal func repack<A, B, C, D, E, F>(t: (A, B, C, D, E), value: F) -> (A, B, C, D, E, F) {
35+
return (t.0, t.1, t.2, t.3, t.4, value)
36+
}
37+
38+
internal func repack<A, B, C, D, E, F, G>(t: (A, B, C, D, E, F), value: G) -> (A, B, C, D, E, F, G) {
39+
return (t.0, t.1, t.2, t.3, t.4, t.5, value)
40+
}
41+
42+
internal func repack<A, B, C, D, E, F, G, H>(t: (A, B, C, D, E, F, G), value: H) -> (A, B, C, D, E, F, G, H) {
43+
return (t.0, t.1, t.2, t.3, t.4, t.5, t.6, value)
44+
}
45+
46+
internal func repack<A, B, C, D, E, F, G, H, I>(t: (A, B, C, D, E, F, G, H), value: I) -> (A, B, C, D, E, F, G, H, I) {
47+
return (t.0, t.1, t.2, t.3, t.4, t.5, t.6, t.7, value)
48+
}
49+
50+
internal func repack<A, B, C, D, E, F, G, H, I, J>(t: (A, B, C, D, E, F, G, H, I), value: J) -> (A, B, C, D, E, F, G, H, I, J) {
51+
return (t.0, t.1, t.2, t.3, t.4, t.5, t.6, t.7, t.8, value)
52+
}

0 commit comments

Comments
 (0)