_filter specification
This is the engineering specification for the MotionObservable
operator: _filter
.
Overview
_filter
only forwards values that pass a test. ReactiveX documentation.
Example usage
stream._filter { state in
return state == .ended
}
upstream | downstream
{ state: .began, rotation: 3 } |
{ state: .changed, rotation: 5 } |
{ state: .ended, rotation: 7 } | { state: .ended, rotation: 3 }
{ state: .possible, rotation: 0 } |
MVP
Expose _filter API
Should delegate to _nextOperator
.
class MotionObservable<T> {
public func _filter(predicate: (T) -> Bool) -> MotionObservable<T> {
return _nextOperator { value, next in
if predicate(value) {
next(value)
}
}
}