rewrite specification
This is the engineering specification for the MotionObservable
operator: rewrite
.
Overview
rewrite
transforms incoming values into new outgoing values using a dictionary of key-value pairs.
Example usage:
stream.rewrite([.state1: 100, .state2: 0])
upstream values | downstream
.state1 [.state1: 100, .state2: 0] | 100
.state2 [.state1: 100, .state2: 0] | 0
.state3 [.state1: 100, .state2: 0] |
MVP
Expose rewrite operator API
Return a new MotionObservable of type U.
class MotionObservable<T> {
public func rewrite<U>(values: [T: U]) -> MotionObservable<U>
Only emit when a transformation is possible
class MotionObservable<T> {
func rewrite<U>(_ values: [T: U]) -> MotionObservable<U> {
return _nextOperator { value, next in
if let rewritten = values[value] {
next(rewritten)
}
}
}