Rx\Operator\MapOperator::__invoke PHP Method

__invoke() public method

public __invoke ( Rx\ObservableInterface $observable, Rx\ObserverInterface $observer, Rx\SchedulerInterface $scheduler = null ) : Rx\DisposableInterface
$observable Rx\ObservableInterface
$observer Rx\ObserverInterface
$scheduler Rx\SchedulerInterface
return Rx\DisposableInterface
    public function __invoke(ObservableInterface $observable, ObserverInterface $observer, SchedulerInterface $scheduler = null)
    {
        $disposed = false;
        $disposable = new CompositeDisposable();
        $selectObserver = new CallbackObserver(function ($nextValue) use($observer, &$disposed) {
            $value = null;
            try {
                $value = call_user_func_array($this->selector, [$nextValue]);
            } catch (\Exception $e) {
                $observer->onError($e);
            }
            if (!$disposed) {
                $observer->onNext($value);
            }
        }, [$observer, 'onError'], [$observer, 'onCompleted']);
        $disposable->add(new CallbackDisposable(function () use(&$disposed) {
            $disposed = true;
        }));
        $disposable->add($observable->subscribe($selectObserver, $scheduler));
        return $disposable;
    }