{@inheritdoc}

@param callable $func {@inheritdoc}

@return $this
173722
public function filter(callable $func)
    {
        if (!$this->pipeline) {
            // No-op: either an empty array or null.
            return $this;
        }

        // We got an array, that's what we need. Moving along.
        if (\is_array($this->pipeline)) {
            $this->pipeline = \array_filter($this->pipeline, $func);

            return $this;
        }

        // CallbackFilterIterator needs a plain Iterator
        if (!$this->pipeline instanceof \Iterator) {
            $this->pipeline = new \IteratorIterator($this->pipeline);
        }

        $this->pipeline = new \CallbackFilterIterator($this->pipeline, $func);

        return $this;
    }
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);
    }
510131
public function exists(callable $func)
    {
        $isExists = false;

        foreach ($this->elements as $key => $value) {
            if ($func($key, $value)) {
                $isExists = true;
                break;
            }
        }

        return $isExists;
    }
707937
public function fold(callable $func, $acc) : self
    {
        $list = $this->list;

        foreach ($list as $val) {
            $acc = $func($acc, $val);
        }

        return new static($acc);
    }
230386
public function map(callable $func)
    {
        $containers = array_slice(func_get_args(), 1); // remove `$func`
        $haystack = $this->toHArray();

        if (empty($containers)) {
            return new static((new HArray((new HaystackMap($haystack))->map($func)))->toHString());
        }

        return new static((new HArray((new HaystackMap($haystack))->map($func, $containers)))->toHString());
    }
1344937
public function setFunc($func)
    {
        if ($func === null) {
            $this->func = $func;
            return $this;
        }

        if (!is_string($func)) {
            throw new InvalidArgumentException(
                'Function name should be a string.'
            );
        }

        $func = strtoupper($func);
        if (!in_array($func, $this->validFunc())) {
            throw new InvalidArgumentException(sprintf(
                'Function "%s" not allowed in this context.',
                $func
            ));
        }

        $this->func = $func;
        return $this;
    }
557919
public function reduce(callable $func, $initial = null)
    {
        $answer = new HaystackReduce($this->toArray());
        return $answer->reduce($func, $initial);
    }
659595
public function calls(callable ...$callbacks): self
    {
        foreach ($callbacks as $callback) {
            $this->callsWith($callback);
        }

        return $this;
    }
181784
public function resetCallBack(callable $callBack = null)
    {
        $this->callBack = null;
        $this->callBack = $callBack;
        return $this;
    }
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);
    }
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;
    }
71111
public function keyFilter($func) {
		
		$filtered = array_filter($this->keys(), $func);
		
		return new static(array_intersect_key($this->_data, array_flip($filtered)));
	}
1253268
public function each(callable $callback): CollectionInterface
    {
        if ($callback instanceof Closure) {
            $callback = $this->bindCallback($callback);
        }

        foreach ($this->generator() as $key => $value) {
            call_user_func($callback, $key, $value);
        }

        return $this;
    }
626167
public function map(callable $fn) : self
    {
        $validate = $fn instanceof Closure;

        $b = [];

        foreach ($this->a as $row) {
            $b[] = array_map($fn, $row);
        }

        return new self($b, $validate);
    }
396273
public function map(callable $func)
    {
        // That's the standard case for any next stages
        if (\is_iterable($this->pipeline)) {
            $this->pipeline = self::apply($this->pipeline, $func);

            return $this;
        }

        // Let's check what we got for a start
        $this->pipeline = $func();

        // Generator is a generator, moving along
        if ($this->pipeline instanceof \Generator) {
            return $this;
        }

        // Not a generator means we were given a simple value to be treated as an array
        // We do not cast to an array here because casting a null to an array results in
        // an empty array; that's surprising and not how map() works for other values
        $this->pipeline = [
            $this->pipeline,
        ];

        return $this;
    }
977925
public function each(callable $callback)
    {
        if ($this->isCollection()) {
            foreach ($this->data as $val) {
                $callback($this->box($val));
            }
        } else {
            $callback($this->box($this->data));
        }

        return $this;
    }
341089
public function find(callable $func)
    {
        $found = null;

        foreach ($this->elements as $key => $value) {
            if($func($value, $key)) {
                $found = $value;
                break;
            }
        }

        return $found;
    }