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

Commit d7890e4

Browse files
committed
remove merge for ColdSignal of HotSignals; instead use HotSignal.pipe() and .merge() in the new merge(SequenceType)
1 parent ec3759c commit d7890e4

2 files changed

Lines changed: 10 additions & 31 deletions

File tree

ReactiveCocoa/Swift/ColdSignal.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -847,33 +847,6 @@ extension ColdSignal {
847847
}
848848
}
849849

850-
/// Merges a ColdSignal of HotSignals down into a single HotSignal, biased toward the
851-
/// signals added earlier.
852-
///
853-
/// evidence - Used to prove to the typechecker that the receiver is
854-
/// a signal of signals. Simply pass in the `identity` function.
855-
///
856-
/// Returns a signal that will forward events from the original signals
857-
/// as they arrive.
858-
public func merge<U>(evidence: ColdSignal -> ColdSignal<HotSignal<U>>) -> HotSignal<U> {
859-
return HotSignal<U>.weak { sink in
860-
let disposable = CompositeDisposable()
861-
862-
evidence(self).startWithSink { selfDisposable in
863-
disposable.addDisposable(selfDisposable)
864-
865-
return Event.sink(next: { signal in
866-
let innerDisposable = signal.observe(sink)
867-
disposable.addDisposable(innerDisposable)
868-
869-
return ()
870-
})
871-
}
872-
873-
return disposable
874-
}
875-
}
876-
877850
/// Maps each value that the receiver sends to a new signal, then merges the
878851
/// resulting signals together.
879852
///

ReactiveCocoa/Swift/HotSignal.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,16 +562,22 @@ extension HotSignal {
562562
}
563563

564564
/// Merges a SequenceType of HotSignals down into a single HotSignal, biased toward the
565-
/// signals added earlier.
565+
/// signals appearing earlier in the sequence.
566566
///
567567
/// The returned signal will automatically be destroyed when there are no
568568
/// more strong references to it, and no Disposables returned from observe()
569569
/// are still around.
570570
///
571571
/// Returns a HotSignal that will forward changes from the original signals
572-
/// as they arrive, starting with earlier ones.
573-
public class func merge<S: SequenceType where S.Generator.Element == HotSignal<T>>(values: S) -> HotSignal<T> {
574-
return ColdSignal.fromValues(values).merge(identity)
572+
/// in the sequence, starting with earlier ones.
573+
public class func merge<S: SequenceType where S.Generator.Element == HotSignal<T>>(signals: S) -> HotSignal<T> {
574+
let (signal, sink) = HotSignal<HotSignal<T>>.pipe()
575+
let merged = signal.merge(identity)
576+
var generator = signals.generate()
577+
while let signal: HotSignal<T> = generator.next() {
578+
sink.put(signal)
579+
}
580+
return merged
575581
}
576582

577583
/// Maps each value that the receiver sends to a new signal, then merges the

0 commit comments

Comments
 (0)