startWith specification
This is the engineering specification for the MotionObservable
operator: startWith
.
Overview
startWith
emits the provided value and then subscribes upstream and emits all subsequent values
with no modification.
Example usage
stream.startWith(0)
upstream | downstream
| 0
20 | 20
80 | 80
MVP
Expose a startWith operator API
class MotionObservable<T> {
public func startWith(initialValue: T) -> MotionObservable<T>
}
Create a MotionObservable that emits the initialValue on subscription
The stream should be _remember
‘d so that the last value emitted is cached for subsequent
subscriptions.
class MotionObservable<T> {
public func startWith(initialValue: T) -> MotionObservable<T> {
return MotionObservable { observer in
observer.next(initialValue)
let subscription = self.subscribeAndForward(to: observer)
return {
subscription.unsubscribe()
}
}._remember()
}
}