Reduce, or fold, a collection down to a single value

Overridden to load any data that has not yet been loaded.

@param callback $filter The filter to apply.
@param mixed $initial Initial value
@return mixed A single reduced value
769534
public function reduce($filter, $initial = false) {
		if (!$this->closed()) {
			while ($this->next()) {}
		}
		return parent::reduce($filter, $initial);
	}
330933
public static function common(string $filter, ...$value)
	{
		if (method_exists(__CLASS__, $filter)) {
			return self::$filter(...$value);
		}
		return null;
	}
1127106
protected function filter($value, $filter)
    {
        if (null !== $filter) {
            $value = Filter::_($value, $filter);
        }

        return $value;
    }
834074
public function reduce($callback)
    {
        $result = null;
        foreach ($this as $key => $value) {
            $result = $callback($value, $key);
        }

        return $result;
    }
53909
public function findOne(array $filter = [], array $options = [])
    {
        $options['typeMap'] = ['root' => 'array', 'document' => 'array', 'array' => 'array'];

        if ($originalValues = $this->collection->findOne($filter, $options)) {
            $values = $this->convertValues->convertToPHPValues($originalValues);


            $object = $this->hydrator->hydrate($values);

            $this->changesCollector->register($object, $originalValues);

            return $object;
        }
    }
586004
public function reduce(Closure $callback, $initial = 0)
    {
        $accumulator = $initial;
        foreach ($this->items as $item) {
            $accumulator = $callback($accumulator, $item);
        }
        return $accumulator;
    }
1021644
public function indexOf($filter)
    {
        foreach ($this->children as $i => $child) {
            if ($child === $filter) {
                return $i;
            }
        }

        return -1;
    }
836070
protected function getUserFunctionariesFilter(string $filter = null)
    {
        $mappingConfiguration = new PropertyMappingConfiguration();
        return $this->convertFunctionariesFilter($mappingConfiguration, $filter);
    }
625949
public function get($name = '', $default = null, $filter = null) {
        $value = $_GET;
        if ($name) {
            $value = $value[ $name ];
        }
        return $this->value($value, $default, $filter);
    }
808146
public function exportHlblocks($filter = array()) {
        $items = $this->getHlblocks($filter);

        $export = array();
        foreach ($items as $item) {
            $export[] = $this->prepareExportHlblock($item);
        }

        return $export;
    }
267681
public static function getCurrencies($filter = array())
    {
        $filter = Filter::create($filter);
        return self::getCollection('/currencies' . $filter->toQuery(), 'Currency');
    }
735760
public function getFilteredCopy(\Closure $filter)
    {
        $copy = clone $this;
        $filteredData = [];
        foreach ($this->data as $key => $item) {
            if ($filter($item)) {
                $filteredData[$key] = $item;
            }
        }

        $copy->data = $filteredData;
        return $copy;
    }
26547
public function filter( $filter, $params )
    {
        $argList = func_get_args( );

        array_shift( $argList );

        if ( isset( $this->filters[ $filter ] ) )
        {
            foreach( $this->filters[ $filter ] as $callback )
            {
                $argList[ 0 ] = call_user_func_array( $callback[ 'callback' ], $argList );

                if ( $this->debug )
                {
                    echo PHP_EOL . '->FILTER: ' . $filter . ' -> '
                            . $this->_serializeCallback( $callback[ 'callback' ] )
                            . ' + Priority: ' . $callback[ 'priority' ]
                            . PHP_EOL;
                }
            }
        }

        return $argList[ 0 ];
    }
366436
public function filter(/*Callable*/ $filter)
    {
        $result = clone $this;
        foreach ($this as $object)
        {
            if (call_user_func($filter, $object) === false) {
                $result->remove($object);
            }
        }

        return $result;
    }
475345
public function reduce(callable $reduceCallback, $initial = null)
    {
        foreach ($this->iterator as $value) {
            $initial = call_user_func($reduceCallback, $initial, $value);
        }

        return $initial;
    }
1013669
public function filter($filter)
    {
        $callback = is_array($filter) ? $this->_filterFromArray($filter) : $filter;
        $data = array_filter($this->_data, $callback);
        return new static($data);
    }
114510
private function parseFactory($filter)
    {
        // Define single tasks filter with a callback.
        $callbacks = [
            "bbcode"    => "bbcode2html",
            "clickable" => "makeClickable",
            "shortcode" => "shortCode",
            "markdown"  => "markdown",
            //"geshi"     => "syntaxHighlightGeSHi",
            "nl2br"     => "nl2br",
            "htmlentities" => "htmlentities",
            "purify"    => "purify",
            'anchor4Header' => 'createAnchor4Header',
        ];

        // Do the specific filter
        $text = $this->current->text;
        switch ($filter) {
            case "jsonfrontmatter":
                $res = $this->jsonFrontMatter($text);
                $this->current->text = $res["text"];
                $this->addToFrontmatter($res["frontmatter"]);
                break;

            case "yamlfrontmatter":
                $res = $this->yamlFrontMatter($text);
                $this->current->text = $res["text"];
                $this->addToFrontmatter($res["frontmatter"]);
                break;

            case "titlefromh1":
                $title = $this->getTitleFromFirstH1($text);
                $this->current->text = $text;
                if (!isset($this->current->frontmatter["title"])) {
                    $this->addToFrontmatter(["title" => $title]);
                }
                break;

            case "titlefromheader":
                $title = $this->getTitleFromFirstHeader($text);
                $this->current->text = $text;
                if (!isset($this->current->frontmatter["title"])) {
                    $this->addToFrontmatter(["title" => $title]);
                }
                break;

            case "bbcode":
            case "clickable":
            case "shortcode":
            case "markdown":
            //case "geshi":
            case "nl2br":
            case "htmlentities":
            case "purify":
            case "anchor4Header":
                $this->current->text = call_user_func_array(
                    [$this, $callbacks[$filter]],
                    [$text]
                );
                break;

            default:
                throw new Exception("The filter '$filter' is not a valid filter     string.");
        }
    }