Material Motion Exploring solutions that will empower creators with the tools needed to describe and implement rich, interactive motion on any platform. Edit this page · History
$._nextOperator _filter
$._map
dedupe · ignoreUntil · whenRecognitionStateIs · whenRecognitionStateIsAnyOf
Status Interface level Implementation level Library
Stable as of December 13, 2016 L3: Stream creator L4: Runtime engineering material-motion
platformsrctests
Android View View
iOS (Swift) View View
JavaScript View View
_filter
upstream (T)
(T) downstream

_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)
      }
    }
  }