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

Commit

Permalink
remove merge for ColdSignal of HotSignals; instead use HotSignal.pipe…
Browse files Browse the repository at this point in the history
…() and .merge() in the new merge(SequenceType)
  • Loading branch information
jconst committed Dec 26, 2014
1 parent ec3759c commit d7890e4
Showing 2 changed files with 10 additions and 31 deletions.
27 changes: 0 additions & 27 deletions ReactiveCocoa/Swift/ColdSignal.swift
Original file line number Diff line number Diff line change
@@ -847,33 +847,6 @@ extension ColdSignal {
}
}

/// Merges a ColdSignal of HotSignals down into a single HotSignal, biased toward the
/// signals added earlier.
///
/// evidence - Used to prove to the typechecker that the receiver is
/// a signal of signals. Simply pass in the `identity` function.
///
/// Returns a signal that will forward events from the original signals
/// as they arrive.
public func merge<U>(evidence: ColdSignal -> ColdSignal<HotSignal<U>>) -> HotSignal<U> {
return HotSignal<U>.weak { sink in
let disposable = CompositeDisposable()

evidence(self).startWithSink { selfDisposable in
disposable.addDisposable(selfDisposable)

return Event.sink(next: { signal in
let innerDisposable = signal.observe(sink)
disposable.addDisposable(innerDisposable)

return ()
})
}

return disposable
}
}

/// Maps each value that the receiver sends to a new signal, then merges the
/// resulting signals together.
///
14 changes: 10 additions & 4 deletions ReactiveCocoa/Swift/HotSignal.swift
Original file line number Diff line number Diff line change
@@ -562,16 +562,22 @@ extension HotSignal {
}

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

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

0 comments on commit d7890e4

Please sign in to comment.