<?php require_once __DIR__ . '/../bootstrap.php'; $observable = new Rx\Observable\ArrayObservable(array(21, 42, 84)); $observable->filter(function ($elem) { return $elem >= 42; })->subscribe($stdoutObserver);
<?php require_once __DIR__ . '/../bootstrap.php'; $observable = new Rx\Observable\ArrayObservable(array(21, 42)); $observable->map(function ($elem) { return $elem * 2; })->subscribe($stdoutObserver);
<?php require_once __DIR__ . '/../bootstrap.php'; $loop = React\EventLoop\Factory::create(); $scheduler = new Rx\Scheduler\EventLoopScheduler($loop); $observable = new Rx\Observable\ArrayObservable(range(1, 5), $scheduler); $selectManyObservable = $observable->flatMap(function ($value) { return new Rx\Observable\ArrayObservable(range(1, $value)); }, $scheduler); $disposable = $selectManyObservable->subscribe($stdoutObserver, $scheduler); $loop->run();
<?php require_once __DIR__ . '/../bootstrap.php'; $observable = new Rx\Observable\ArrayObservable(array(21, 42, 21, 42, 21, 42)); $observable->groupBy(function ($elem) { if ($elem === 42) { return 0; } return 1; }, null, function ($key) { return $key; })->subscribeCallback(function ($groupedObserver) use($createStdoutObserver) { $groupedObserver->subscribe($createStdoutObserver($groupedObserver->getKey() . ": ")); });
require_once __DIR__ . '/../bootstrap.php'; /* Without publish */ $interval = new Rx\Observable\ArrayObservable(range(0, 10)); $source = $interval->take(2)->doOnNext(function ($x) { echo "Side effect\n"; }); $source->subscribe($createStdoutObserver('SourceA ')); $source->subscribe($createStdoutObserver('SourceB ')); //Side effect //SourceA Next value: 0 //Side effect //SourceA Next value: 1 //SourceA Complete! /* With publish */ $interval = new Rx\Observable\ArrayObservable(range(0, 10)); $source = $interval->take(2)->doOnNext(function ($x) { echo "Side effect\n"; }); $published = $source->publish(); $published->subscribe($createStdoutObserver('SourceC ')); $published->subscribe($createStdoutObserver('SourceD ')); $published->connect(); //Side effect //SourceC Next value: 0 //SourceD Next value: 0 //Side effect //SourceC Next value: 1 //SourceD Next value: 1 //SourceC Complete! //SourceD Complete!
<?php require_once __DIR__ . '/../bootstrap.php'; $observable = new Rx\Observable\ArrayObservable(array(21, 42, 63)); $observable->take(2)->subscribe($stdoutObserver);
<?php require_once __DIR__ . '/../bootstrap.php'; $source = new \Rx\Observable\ArrayObservable(range(1, 3)); $subscription = $source->repeat(3)->subscribe($createStdoutObserver()); //Next value: 1 //Next value: 2 //Next value: 3 //Next value: 1 //Next value: 2 //Next value: 3 //Next value: 1 //Next value: 2 //Next value: 3 //Complete!