-
Notifications
You must be signed in to change notification settings - Fork 8
filter
richardszalay edited this page May 20, 2011
·
3 revisions
Excludes values that do not match a predicate
function filters(predicate : Function = null) : IObservable.<T>
predicate is function(value : T) : Boolean
Each value emitted by the source will be sent to predicate. If predicate returns true
, the value will be emitted; otherwise, it will be skipped.
The returned sequence completes when the source sequence completes.
The returned sequence errors when the source sequences errors or when predicate throws an error.
xs = source
ys = output
p(x) = predicate
xs ──o─────o─────o─────o────/
│ │ │ │ │
p(x) p(x) p(x) p(x) │
true false false true │
│ │ │
ys ──o─────────────────o────/
IObservable.<T>
var source : IObservable = Observable.range(0, 10)
.filter(function(v:int) : Boolean { return v > 5; });
source.subscribe(function(value : int) : void
{
trace(value);
});
// Trace output is:
// 5
// 6
// 7
// 8
// 9