Transforms the values in a collection by running each value through the iterator

@param array    $array   array of values
@param \Closure $closure closure to map the values

@return array
9105
public static function mapValues(array $array, Closure $closure = null): array
    {
        if (is_null($closure)) {
            $closure = '__::identity';
        }
        $resultArray = [];
        foreach ($array as $key => $value) {
            $resultArray[$key] = call_user_func_array($closure, [$value, $key, $array]);
        }

        return $resultArray;
    }
1274251
public function map(array $collection, Closure $iterator)
    {
        foreach ($collection as $key => $node)
        {
            $collection[$key] = $iterator($key, $node);
        }

        return $collection;
    }
918394
public function each(array $collection, Closure $iterator)
    {
        foreach ($collection as $key => $node)
        {
            $iterator($key, $node);
        }
    }
761093
private function describeClosure(\Closure $closure): array
    {
        try {
            $r = new \ReflectionFunction($closure);
        } catch (\ReflectionException $e) {
            return ['closure' => 'unable to resolve'];
        }

        return [
            'name' => $r->getName() . " (lines {$r->getStartLine()}:{$r->getEndLine()})",
            'file' => $r->getFileName(),
            'this' => $r->getClosureThis()
        ];
    }
291889
public function toFlatArray(\Closure $prepare = null, array &$tree = null)
    {
        if (null === $prepare) {
            $prepare = function(NodeInterface $node) {
                $pre = $node->getNodeLevel() > 1 ? implode('', array_fill(0, $node->getNodeLevel(), '--')) : '';

                return $pre.(string) $node;
            };
        }
        if (null === $tree) {
            $tree = array($this->getNodeId() => $prepare($this));
        }

        foreach ($this->getChildNodes() as $node) {
            $tree[$node->getNodeId()] = $prepare($node);
            $node->toFlatArray($prepare, $tree);
        }

        return $tree;
    }
287484
public function mapArray( $array, bool $recursive = false) {
        $handler = $this->_getMapValueHandler();
        $mapper = $recursive ? new RecursiveCallbackMapper($handler) : new CallbackMapper($handler);
        $mapping = new CollectionMapping($mapper);
        return $mapping->mapCollection($array);
    }
1084637
public function each(\Closure $closure): self
    {
        // init
        $array = [];

        foreach ($this->getGenerator() as $key => $value) {
            $array[$key] = $closure($value, $key);
        }

        return static::create(
            $array,
            $this->iteratorClass,
            false
        );
    }
400456
public function map(\Closure $callback)
    {
        $result = [];
        foreach ($this->value as $entity) {
            $result[] = $callback($entity);
        }

        return $result;
    }
147626
public function at(\Closure $closure): self
    {
        $arrayy = clone $this;

        foreach ($arrayy->getGenerator() as $key => $value) {
            $closure($value, $key);
        }

        return static::create(
            $arrayy->toArray(),
            $this->iteratorClass,
            false
        );
    }
1075241
public function iterateClosure($Closure, $Glue = false)
    {
        if (!is_callable($Closure) || empty($this->Input)) {
            return;
        }
        if (!$Glue) {
            foreach ($this->Working as &$Segment) {
                $Segment = $Closure($Segment);
            }
            return;
        }
        foreach ($this->Markers as &$Segment) {
            if (isset($Segment[0][0]) && !is_array($Segment[0][0])) {
                $Segment[0][0] = $Closure($Segment[0][0]);
            }
        }
    }
115063
public function map(Closure $func)
    {
        $clone = clone $this;

        $clone->data = array_map($func, $this->data);
        $clone->updateBody();

        return $clone;
    }
250319
protected function filterOutArrayValues($values = null, \Closure $filter = null, $preserveKeys = false)
    {
        $data = [];

        if (is_array($values) && count($values))
        {
            foreach ($values as $key => $value)
            {
                $value = trim($value);

                if (!empty($value))
                {
                    if (is_callable($filter) && $filter($value))
                    {
                        $data[$key] = $value;
                    }
                }
            }

            if (!$preserveKeys)
            {
                $data = array_values($data);
            }
        }

        return $data;
    }
1354602
public static function getOrSet($key, \Closure $closure)
    {
        $key = Cache::key($key);
        if (!isset(self::$cache[$key])) {
            self::$cache[$key] = $closure();
        }
        return self::$cache[$key];
    }
1321626
public static function where($array, \Closure $callback)
        {
            $filtered = array();

            foreach ($array as $key => $value) {
                if (call_user_func($callback, $key, $value)) {
                    $filtered[$key] = $value;
                }
            }

            return $filtered;
        }
113478
public function all(array $collection, Closure $iterator)
    {
        foreach ($collection as $node)
        {
            if ( ! $iterator($node))
            {
                return false;
            }
        }

        return true;
    }
415062
public function filter(Closure $closure): self
    {
        $filter = new Iterator\CustomFilterIterator($this->getIterator(), [$closure]);

        return new self(iterator_to_array($filter));
    }
835244
public function cache(Closure $closure)
    {
        $hash = spl_object_hash((object) $closure);

        if ( ! isset ($this->cached[$hash]))
        {
            $this->cached[$hash] = $closure();
        }

        return $this->cached[$hash];
    }