The window() operator
The window()
operator belongs among the more advanced higher-order Observables. We've seen the switchLatest()
operator in Chapter 6, PHP Streams API and Higher-Order Observables, and we know that it automatically subscribes to the latest Observable emitted from its source Observable.
The exact opposite is the window()
operator that takes a so called "window boundary" Observable as an argument and splits the source emissions into separate Observables based on emission from the "window boundary" Observable.
An example will definitely make this more obvious:
// window_01.php $source = Observable::range(1, 10)->publish(); $windowBoundary = $source->bufferWithCount(3); $source->window($windowBoundary) ->doOnNext(function() { echo "emitting new window Observable\n"; }) ->switchLatest() ->subscribe(new CallbackObserver(function($value) { echo "$value\n"; })); $source...