@param callable $callback
@param int $depth
@param int $level

@return \Generator
495357
public function findChildren(callable $callback, $depth = null, $level = null)
    {

        $level = $level ?: 0;

        foreach ($this->children as $child) {

            /** @var NodeInterface $child */
            if ($child->is($callback))
                yield $child;

            if ($depth === null || $level < $depth) {

                if ($child instanceof NodeInterface)
                    foreach ($child->findChildren($callback, $depth, $level + 1) as $subChild)
                        yield $subChild;
            }
        }
    }
33171
public function children(callable $callback = NULL) {
    $matches = [];
    foreach ($this->nodes as $node) {
      if ($node instanceof ParentNode) {
        $matches = array_merge($matches, $node->children($callback)->nodes);
      }
    }
    return new NodeCollection($matches);
  }
1058314
private function flattenCallback($array, $depth = INF): array
    {
        $depth = (int) $depth;

        return array_reduce($array, function ($result, $item) use ($depth) {
            $item = $item instanceof self ? $item->all() : $item;

            if (! is_array($item)) {
                return array_merge($result, [$item]);
            } elseif ($depth === 1) {
                return array_merge($result, array_values($item));
            }

            return array_merge($result, self::flattenCallback($item, $depth - 1));
        }, []);
    }
723305
public function first(callable $callback = null, $default = null)
    {
        foreach ($this->generator as $item) {
            if (!$callback || $callback($item)) {
                return $item;
            }
        }

        return $default;
    }
673179
protected function appendIterator(\Closure $callback = null)
    {
        $iterator = new \AppendIterator();

        $paths = (array) parent::getArrayCopy();

        $clousre = function ($path) use ($callback, $iterator) {
            $iterator->append($callback($path));
        };

        foreach ($this as $path) {
            if ($this->isSubdir($path)) {
                continue;
            }

            $clousre($path);
        }

        return $iterator;
    }
1253531
public function callback(Closure $callback)
    {
        foreach ($this->getInnerIterator() as $key => $value) {
            yield $callback($value, $key);
        }
    }
33518
public function each($items, callable $callback = null)
    {
        if ($items instanceof \Traversable) {
            $items = iterator_to_array($items);
        }

        $total = count($items);
        if (!$total) {
            return;
        }
        $this->total($total);

        foreach ($items as $key => $item) {
            if ($callback) {
                $label = $callback($item, $key);
            } else {
                $label = null;
            }

            $this->advance(1, $label);
        }
    }
455648
public function each(callable $callback, $count = 1000)
    {
        $result = $this->getBuilder()->each($callback, $count);

        // Reset query builder
        $this->resetBuilder();

        return $result;
    }
558028
public function fill($items, callable $callback)
    {
        $menu = $this;

        foreach ($items as $key => $item) {
            $menu = $callback($menu, $item, $key) ?: $menu;
        }

        return $menu;
    }
604077
public function start_lvl( &$output, $depth = 0, $args = array() )
	{
		// depth dependent classes
		$indent = ( $depth > 0  ? str_repeat( "\t", $depth ) : '' ); // code indent
		$display_depth = ( $depth + 1); // because it counts the first submenu as 0
		$classes = array(
			'sub-menu',
			( $display_depth == 0 ? 'dropdown' : '' ),
			( $display_depth > 0 ? 'dropdown-menu' : '' ),
		);
		$class_names = implode( ' ', $classes );

		// build html
		$output .= "\n" . $indent . '<ul class="' . $class_names . '">' . "\n";
	}
665738
public function chunk($count, callable $callback)
    {
        return $this->prepareQueryBuilder()->chunk($count, function (Collection $results) use ($callback) {
            $this->hydrateIntermediateRelations($results->all());

            return $callback($results);
        });
    }
426454
function run(callable $callback = null) {
        if (isset($this->res))
            return null;
        $this->res = proc_open($this->cmd, $this->descriptor_spec, $this->pipes, $this->cwd, $this->env);
        if ($this->res) {
            $this->stdout = new TcpConnection($this->pipes[1]);
            if (is_callable($this->onMessage))
                $this->stdout->onMessage = function ($conn, $data) {
                    ($this->onMessage)($this, $data);
                };
            if (is_callable($this->onClose))
                $this->stdout->onClose = function () {
                    ($this->onClose)($this);
                };
            stream_set_blocking($this->pipes[0], false);
            if (is_callable($callback))
                $callback($this);
            return true;
        }
        unset ($this->res);
        return false;
    }
1320354
protected function anyParents($basename, $pathname, $depth, $callback)
    {
        // Check all ignored dir up the path
        while ($depth >= 0) {
            $ignored = $callback($basename, $pathname, $depth);
            if ($ignored) {
                return true;
            }
            $pathname = dirname($pathname);
            $basename = basename($pathname);
            $depth--;
        }
        return false;
    }
731715
private static function generateTab($depth)
    {
        $builder = '';

        if ($depth > 0) {
            $builder .= '  ';
        }

        for ($i = 1; $i < $depth; $i++) {
            $builder .= '|  ';
        }

        $builder .= '+--';

        return $builder;
    }
79966
public static function isFunctionGenerator(callable $callback) : bool
    {
        try{
            $func = new \ReflectionFunction($callback);

            return $func->isGenerator();
        }
        catch(\ReflectionException $e)
        {
            return false;
        }
    }
900181
public function transform(callable $callback): self
    {
        $index = 0;
        foreach ($this->items as $key => $value) {
            $this->set($key, $callback($value, $key, $index++));
        }

        return $this;
    }
1115302
public static function make(\Closure $callback = null)
    {
        self::$instance = new static();

        if ($callback instanceof \Closure) {
            return $callback(self::$instance);
        }

        return self::$instance;
    }