Wrap a block of code in the autoloader and get a list of loaded classes.

@param callable $func

@return \ClassPreloader\Config
320725
public static function getIncludes($func)
    {
        $loader = new static();
        call_user_func($func, $loader);
        $loader->unregister();

        $config = new Config();
        foreach ($loader->getFilenames() as $file) {
            $config->addFile($file);
        }

        return $config;
    }
76038
private function deferCall(string $func, array $params)
    {
        $profileKey = $this->interface . '->' . $func;
        $fallback   = $this->getFallbackHandler($func);

        try {
            $connectPool    = $this->getPool();
            $circuitBreaker = $this->getBreaker();

            /* @var ConnectionInterface $connection */
            $connection = $connectPool->getConnection();

            $packer   = service_packer();
            $type     = $this->getPackerName();
            $data     = $packer->formatData($this->interface, $this->version, $func, $params);
            $packData = $packer->pack($data, $type);

            $result = $circuitBreaker->call([$connection, 'send'], [$packData], $fallback);

            if ($result === null || $result === false) {
                $connection->release(true);
                return null;
            }
        } catch (\Throwable $throwable) {
            if (empty($fallback)) {
                throw $throwable;
            }

            $connection = null;
            $result     = PhpHelper::call($fallback, $params);
        }

        return $this->getResult($connection, $profileKey, $result);
    }
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);
    }
505093
public function filter(callable $func = null, $flag = null)
    {
        $answer = new Filter($this->toHArray());
        return new static((new HArray($answer->filter($func, $flag)))->toHString());
    }
523134
protected function getMacroFunction($macro_func)
    {
        if (is_array($macro_func) && is_callable($macro_func)) {
            return new \ReflectionMethod($macro_func[0], $macro_func[1]);
        }

        if (is_object($macro_func) && is_callable($macro_func) && !$macro_func instanceof Closure) {
            return new \ReflectionMethod($macro_func, '__invoke');
        }

        return new \ReflectionFunction($macro_func);
    }
419153
public static function combine(/* $func1, $func2, ... */)
    {
        $functions = func_get_args();

        foreach ($functions as $function) {
            static::validate($function);
        }

        return function() use ($functions) {
            $result = array();
            $args = func_get_args();

            foreach ($functions as $function) {
                $result[] = call_user_func_array($function, $args);
            }

            return $result;
        };
    }
1364914
public function bind(callable $function) : Monadic
    {
        list($result, $output) = $function($this->result)->run();

        return self::of($result, flatten(extend($this->output, $output)));
    }
381912
public function annotate(callable $callable) {
		$fn = null;
		$invoke = function () {};

		// TODO can this be *any* cleaner?
		if(is_array($callable)) {
			// support shorthand array callable form
			// callable arrays will always have 2 elements--otherwise they don't pass the typehint
			$cls = new ReflectionClass($callable[0]);
			$fn = $cls->getMethod($callable[1]);
			$invoke = function ($args) use($fn, $callable) {
				return function () use($fn, $callable, $args) {
					return $fn->invokeArgs($callable[0], $args);
				};
			};
		} else if(!($callable instanceof \Closure)) {
			// support magic __invoke method form
			$cls = new ReflectionClass($callable);
			$fn = $cls->getMethod('__invoke');
			$invoke = function ($args) use($fn, $callable) {
				return function () use($fn, $callable, $args) {
					return $fn->invokeArgs($callable, $args);
				};
			};
		} else {
			// support all other callables
			$fn = new ReflectionFunction($callable);
			$invoke = function ($args) use($fn) {
				return function () use($fn, $args) {
					return $fn->invokeArgs($args);
				};
			};
		}

		$cacheId = sha1($fn->__toString());
		if(array_key_exists($cacheId, $this->fnCache)) {
			return $this->fnCache[$cacheId];
		}

		$args = $this->getArgs($fn);
		$annotated = $invoke($args);
		$this->fnCache[$cacheId] = $annotated;
		return $annotated;
	}
44978
public function bind(callable $function)
    {
        // Theoretical here should be call like this:
        //  call_user_func($function, $this->run())
        // But this do not make things lazy, to cheat little bit
        // IO monad is returned and inside of it is little switch
        return static::of(function () use ($function) {
            $m = $function($this->run());

            return $m instanceof IO
                ? $m->run()
                : $m;
        });
    }
673663
public static function call($func, array $args)
    {
        switch ($func) {
            case 'map':
                if (count($args) != 2) throw new \BadMethodCallException("Wrong parameter count for method Func::map");
                return self::map($args[0], $args[1]);
            case 'premap':
                if (count($args) != 2) throw new \BadMethodCallException("Wrong parameter count for method Func::premap");
                return self::premap($args[0], $args[1]);
            case 'to_data':
                if (count($args) != 1) throw new \BadMethodCallException("Wrong parameter count for method Func::to_data");
                return self::to_data($args[0]);
            case 'manipulate':
                if (count($args) != 2) throw new \BadMethodCallException("Wrong parameter count for method Func::manipulate");
                return self::manipulate($args[0], $args[1]);
            default:
                throw new \InvalidArgumentException(sprintf('Unknown function name provided: %s', (string)$func));
        }
    }
1066550
protected function _renderFunc(Func $func)
    {
        if($func->getName() != 'CONCAT') return parent::_renderFunc($func);

        $args = $func->getArgs();
        array_walk($args, function(&$arg){
            $arg = $this->_renderValue($arg);
        });

        return implode(' + ', $args);
    }
139166
public static function add(callable $func) {
		self::$_lPool[] = $func;
		if (!self::$_bHook) {
			self::$_bHook = TRUE;
			Page::doDelay();
		}
	}
263186
public function bind(callable $function) : Monadic
    {
        $concat = compose(
            function (array $list) use ($function) {
                return fold(
                    function ($acc, $item) use ($function) {
                        $acc[] = $function($item)->extract();

                        return $acc;
                    },
                    $list,
                    []
                );
            },
            partialLeft('array_merge', $this->collection)
        );

        return self::of(flatten($concat($this->collection)));
    }
1037776
public function setApplyFilterFunction(callable $function)
    {
        $validator = $this->getCallableValidatorApplyFilters();
        $validator->setCallableFunction($function);

        if ($validator->isValid() === false) {
            throw $validator->getException();
        }

        $this->applyFilterFunction = $function;

        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;
    }
942734
public function setCallbackWrapper(?callable $callbackWrapper): callable
    {
        $previousWrapper = $this->callbackWrapper;
        $this->callbackWrapper = $callbackWrapper ?? function (callable $callback, ItemInterface $item, bool &$save, CacheInterface $pool, \Closure $setMetadata, ?LoggerInterface $logger) {
            return $callback($item, $save);
        };

        return $previousWrapper;
    }
47067
public function reduce(callable $func = null, $initial = null)
    {
        if (null === $func) {
            return parent::reduce(static function ($carry, $item) {
                $carry += $item;

                return $carry;
            }, $initial ?? 0);
        }

        return parent::reduce($func, $initial);
    }