@inheritdoc

@param callable $func
@param mixed $initial
@return bool|float|int|HString|HArray
557919
public function reduce(callable $func, $initial = null)
    {
        $answer = new HaystackReduce($this->toArray());
        return $answer->reduce($func, $initial);
    }
1154040
public function subscribe(callable $func): self
    {
        $this->handle->subscribe([$this->name], $func);
        return $this;
    }
791321
public function filter(callable $func = null): self
    {
        $func = $func ?? static function ($value) {
            // Cast is unnecessary
            return $value;
        };

        // Strings usually are internal functions, which typically require exactly one parameter.
        if (\is_string($func)) {
            $func = static function ($value) use ($func) {
                return $func($value);
            };
        }

        return parent::filter($func);
    }
747877
public function first($callable = null)
    {
        if ($callable !== null) {
            $result = $this->statement->fetch(PDO::FETCH_ASSOC);
            $this->statement->closeCursor();
            if (is_array($result)) {
                $result = call_user_func_array($callable, $result);
            }
        } else {
            $result = $this->statement->fetch();
            $this->statement->closeCursor();
        }

        return $result;
    }
923511
public function unique(callable $func = null)
    {
        return new Enumerator(
            function () use ($func) {
                $exists = [];
                foreach ($this->each() as $k => $v) {
                    $comp = $func ? $func($v) : $v;
                    if (!in_array($comp, $exists, true)) {
                        $exists[] = $comp;
                        yield $k => $v;
                    }
                }
            }
        );
    }
1238907
public function map(callable $func = null): self
    {
        if (null === $func) {
            return $this;
        }

        return parent::map($func);
    }
1280478
private function createFunction($func, array $arguments = array(), $alias = null)
    {
        // Prepare function arguments
        foreach ($arguments as $index => $argument) {
            if ($argument instanceof RawSqlFragmentInterface) {
                $item = $argument->getFragment();
            } else {
                $item = $this->quote($argument);
            }

            // Update item collection
            $arguments[$index] = $item;
        }

        $fragment = sprintf(' %s(%s) ', $func, implode(', ', $arguments));

        // Generate alias if provided
        if (!is_null($alias)) {
            $fragment .= sprintf(' AS %s ', $this->quote($alias));
        }

        // Append a comma if there was a function call before
        if ($this->hasFunctionCall === true) {
            $this->append(', ');
        }

        $this->hasFunctionCall = true;
        return $fragment;
    }
533217
protected function resolveFuncArgs(Func $func)
    {
        $params = $this->reader->read($func);

        $args = array();
        foreach ($params as $param) {

            $name = $param->name;
            $inst = $this->tryService($name);

            if (!$inst && $param->hasDefault) {
                $args[$name] = $param->default;
            } else if ($inst && $param->type && $this->checker->validate($param->type, $inst)) {
                $args[$name] = $inst;
            } else if ($inst && $param->type && !$this->checker->validate($param->type, $inst)) {
                throw new ResolutionException("Parameter type is not compatible with service '$name'");
            } else if ($inst) {
                $args[$name] = $inst;
            } else {
                throw new ResolutionException("Could not resolve parameter '$name'");
            }
        }

        return $args;
    }
225643
public function foldLeft(callable $function, $initial = null)
    {
        if ($this->isEmpty()) {
            return $initial;
        }

        return array_reduce($this->data, $function, $initial);
    }
673995
function recursive($arg,$func,$stack=NULL) {
		if ($stack) {
			foreach ($stack as $node)
				if ($arg===$node)
					return $arg;
		}
		else
			$stack=array();
		switch (gettype($arg)) {
			case 'object':
				if (method_exists('ReflectionClass','iscloneable')) {
					$ref=new ReflectionClass($arg);
					if ($ref->iscloneable()) {
						$arg=clone($arg);
						$cast=is_a($arg,'IteratorAggregate')?
							iterator_to_array($arg):get_object_vars($arg);
						foreach ($cast as $key=>$val)
							$arg->$key=$this->recursive(
								$val,$func,array_merge($stack,array($arg)));
					}
				}
				return $arg;
			case 'array':
				$copy=array();
				foreach ($arg as $key=>$val)
					$copy[$key]=$this->recursive($val,$func,
						array_merge($stack,array($arg)));
				return $copy;
		}
		return $func($arg);
	}
1284643
public static function getReflection(callable $func): \ReflectionFunctionAbstract
    {
        if (is_string($func) && strpos($func, "::") !== false) {
            list($classname, $method) = explode("::", $func, 2);
            $rc = new \ReflectionClass($classname);
            return $rc->getMethod($method);
        }
        return new \ReflectionFunction($func);
    }
341296
private function _first(callable $callback = null)
    {
        $values = $this->getValues();
        if ($callback){
            foreach($values as $key => $value){
                if ($callback($value, $key)){
                    return $value;
                }
            }
        }
        else{
            return empty($values) ? null : $values[0];
        }
        return null;
    }
1094593
public function call(callable $func, ...$args): int
    {
        $memory = $this->allocateMemory();
        $pid = pcntl_fork();

        if ($pid == -1) {
            throw new Exception("Failed to fork");
        }

        # If the child process was started then return its pid
        if ($pid) {
            return $pid;
        }

        # If this is the child process, then run the requested function
        try {
            $func(...$args);
        } catch (\Throwable $e) {
            $memory->addException($e);
            exit(1);
        }

        # Then we must exit or else we will end up the child process running the parent processes code
        die();
    }
1156270
public function groupBy(callable $func)
    {
        $result = [];
        foreach ($this->each() as $k => $v) {
            $this->_groupBy($result, $k, $v, $func);
        }
        return $result;
    }
691117
protected function func($name, &$func)
    {
        $s = $this->count;

        if ($this->matchChar('(')) {
            if ($name === 'alpha' && $this->argumentList($args)) {
                $func = [Type::T_FUNCTION, $name, [Type::T_STRING, '', $args]];

                return true;
            }

            if ($name !== 'expression' && ! preg_match('/^(-[a-z]+-)?calc$/', $name)) {
                $ss = $this->count;

                if ($this->argValues($args) && $this->matchChar(')')) {
                    $func = [Type::T_FUNCTION_CALL, $name, $args];

                    return true;
                }

                $this->seek($ss);
            }

            if (($this->openString(')', $str, '(') || true) &&
                $this->matchChar(')')
            ) {
                $args = [];

                if (! empty($str)) {
                    $args[] = [null, [Type::T_STRING, '', [$str]]];
                }

                $func = [Type::T_FUNCTION_CALL, $name, $args];

                return true;
            }
        }

        $this->seek($s);

        return false;
    }
267058
public function callback($func) {
        if (!$this->_isValid) {
            return $this;
        }
        $this->_isValid = (bool) $func($this->_unsafeVar);
        return $this;
    }
57524
public function walk(callable $func, $recursively = false)
    {
        if (true === $recursively) {
            array_walk_recursive($this->elements, $func);
        } else {
            array_walk($this->elements, $func);
        }

        return $this;
    }