merge specification
This is the engineering specification for the MotionObservable
operator: merge
.
Overview
merge
emits values as it receives them, both from upstream and from the provided stream.
Example usage
stream.merge(with: otherStream)
upstream otherStream | downstream
10 | 10
20 | 20
50 | 50
70 | 70
15 | 15
MVP
Expose a merge operator API
Use MotionObservable
to implement the operator. Accept a MotionObservable of type T.
class MotionObservable<T> {
public func merge(with stream: MotionObservable<T>) -> MotionObservable<T>
Subscribe to both streams and emit their values
Use MotionObservable
to implement the operator. Accept a MotionObservable of type T.
class MotionObservable<T> {
public func merge(with stream: MotionObservable<T>) -> MotionObservable<T> {
return MotionObservable<T> { observer in
let upstreamSubscription = self.subscribe(observer: observer)
let subscription = stream.subscribe(observer: observer)
return {
subscription.unsubscribe()
upstreamSubscription.unsubscribe()
}
}
}