Apply callable to all documents in cursor

@param callable $handler
@return array
764689
public function map($handler)
    {
        $result = array();

        foreach ($this as $id => $document) {
            $result[$id] = $handler($document);
        }

        return $result;
    }
1085961
protected function getReflectionParameters(callable $handler) {
        if (is_array($handler)) {
            $reflector = new ReflectionMethod($handler[0], $handler[1]);
        } else {
            $reflector = new ReflectionFunction($handler);
        }

        return $reflector->getParameters();
    }
228913
protected function callableOptions($callable)
    {
        // resolve closure
        if (is_callable($callable)) {
            return $callable;
        }

        // resolve callable "Class@method" style
        if (is_string($callable) && list($class, $method) = explode('@', $callable)) {
            return [app()->make($class), $method];
        }

        // resolve callable [$object, "method"]
        if (2 === count($callable) && array_key_exists(0, $callable) && array_key_exists(1, $callable)) {
            if (is_object($class = $callable[0]) && is_string($method = $callable[1]) && method_exists($class, $method)) {
                return [$class, $method];
            }
        }

        return false;
    }
232419
private function getNamedHandler($handler)
    {
        if (!isset($this->namedHandlers[$handler])) {
            $this->namedHandlers[$handler] = new $handler();
        }

        return $this->namedHandlers[$handler];
    }
557529
public function add(string $signal, callable $handler): self
    {
        $this->handlers[$signal] = $handler;

        return $this;
    }
790980
public function walk(callable $handler)
    {
        $cursor = static::db()->query($this->selFromDbAllQuery())->cursor();
        foreach ($cursor as $row) {
            if ($handler($this->instantiateItem($row)) === false) {
                break;
            }
        }
    }
576951
public function validateArguments($methods, $handler): array
    {
        if (!$methods || !$handler) {
            throw new \InvalidArgumentException('The method and route handler is not allow empty.');
        }

        $allow = self::ALLOWED_METHODS_STR . ',';
        $hasAny = false;

        $methods = \array_map(function ($m) use ($allow, &$hasAny) {
            $m = \strtoupper(trim($m));

            if (!$m || false === \strpos($allow, $m . ',')) {
                throw new \InvalidArgumentException("The method [$m] is not supported, Allow: " . trim($allow, ','));
            }

            if (!$hasAny && $m === self::ANY) {
                $hasAny = true;
            }

            return $m;
        }, (array)$methods);

        return $hasAny ? self::ALLOWED_METHODS : $methods;
    }
1129831
public function setHandler($handler)
    {
        if (Assert::array($handler)) {
            $this->handler = function (Event $event) use ($handler) {
                return call_user_func_array($handler, [$event]);
            };
        } elseif (Assert::instanceOf($handler, '\\Closure')) {
            $this->handler = $handler;
        } else {
            throw new InvalidArgumentException('`Listener::$handler` must be `array` or `Closure`');
        }
    }
740470
public function selectHandler($handler)
    {
        if (!is_callable($handler)) {
            Assert::string($handler, 'The selected handler must be a callable or a string. Got: %s');

            if (!isset($this->handlers[$handler])) {
                throw new InvalidArgumentException(sprintf(
                    'The handler "%s" does not exist.',
                    $handler
                ));
            }
        }

        $this->selectedHandler = $handler;
    }
1266885
protected function methodDispatcher($handler, $params)
    {
        /**
         *  call when pass closure as handler
         **/
        if (is_callable($handler)) {
            $resolving = $this->container->resolveCallback($handler, $params);

            $this->validateForm($resolving);

            return call_user_func_array($handler, $resolving);
        }

        /**
         * call when pass controller as handler
         **/
        list($controller, $method) = explode('@', $handler);

        return $this->invoke($controller, $method, $params);
    }
220458
private function getHandlerString($handler)
    {
        if (is_string($handler)) {
            return $handler;
        }

        if (is_object($handler) || $handler instanceof \Closure) {
            return spl_object_hash($handler);
        }

        if (is_array($handler) && is_callable($handler)) {
            return $this->getHandlerString($handler[0]) . '@' . $handler[1];
        }

        throw new RuntimeException('Can\'t convert handler to string.');
    }
1292661
private function ensureCallback($handler, $event)
    {
        if (!is_callable($handler)) {
            if (is_object($handler)) {
                if (!$handler instanceof \Closure) {
                    $handler = [$handler, $event];
                }
            }
            if (!is_callable($handler)) {
                throw new EventHandlerException("Handler is not callable for event {$event}");
            }
        }

        return $handler;
    }
931204
public function uriNotMatch($pattern, callable $handler)
    {
        if (!preg_match($pattern, $this->getCleanUri(), $matches)) {
            return $handler($this->getCleanUri(), $matches);
        }
    }
1279008
public function getDocuments(array $idList, $callable = null)
    {
        $idListToFindDirectly = $idList;

        // try to egt document from pool if enabled
        $documentsInDocumentPool = array();
        if ($this->isDocumentPoolEnabled() && !$callable) {
            $documentsInDocumentPool = $this->getDocumentsFromDocumentPool($idList);
            if (count($documentsInDocumentPool) === count($idList)) {
                return $documentsInDocumentPool;
            }

            // skip ids already found in pool
            $idListToFindDirectly = array_diff_key(
                array_map('strval', $idList),
                array_keys($documentsInDocumentPool)
            );
        }

        // get documents directly
        $cursor = $this->find();

        if (is_callable($callable)) {
            call_user_func($callable, $cursor);
        }

        $documentsGettingDirectly = $cursor->byIdList($idListToFindDirectly)->findAll();
        if (empty($documentsGettingDirectly)) {
            return $documentsInDocumentPool ? $documentsInDocumentPool : array();
        }

        if ($this->isDocumentPoolEnabled()) {
            $this->addDocumentsToDocumentPool($documentsGettingDirectly);
        }

        return $documentsGettingDirectly + $documentsInDocumentPool;
    }
522247
public function filter(callable $callable)
    {
        $result = [];

        foreach ($this->value as $key => $value) {
            if ($callable($value, $key, $this)) {
                $result[$key] = $value;
            }
        }

        return static::of($result);
    }
1271974
public function exportByHandle(string $handle): array
    {
        $field = Craft::$app->fields->getFieldByHandle($handle);
        return $this->export($field);
    }
1206005
private function extract($handler)
    {
        if (is_array($handler)) {
            return $this->fromClassMethodArray($handler);
        }
        if (strpos($handler, self::CHAR_AT) !== false) {
            return $this->fromAtNotation($handler);
        }
        if (strpos($handler, self::CHAR_DOT) !== false) {
            return $this->fromDotNotation($handler);
        }
        return $this->fromClassName($handler);
    }