Call a function on every item in a list and return the resulting list.

@param callable $function
@param array|Traversable $traversable

@return array
4477
public static function map(callable $function, $traversable)
    {
        $aggregation = [];

        foreach ($traversable as $key => $value) {
            $aggregation[$key] = $function($value, $key);
        }

        return $aggregation;
    }
920533
public static function call($key, callable $func)
    {
        $trace = debug_backtrace();
        if ($function = $trace[1]["function"]) {
            $key = $function . "_" . $key;
            if ($class = $trace[1]["class"]) {
                $key = str_replace("\\", "_", $class) . "_" . $key;
            }
        }

        if (static::check($key)) {
            return static::get($key);
        }

        $return = $func();

        static::set($key, $return);

        return $return;
    }
816770
protected function parseArgs($callable)
    {
        $args = [];

        if (strpos($callable, ':') !== false) {
            list($callable, $argsString) = explode(':', $callable);

            $args = explode(',', $argsString);
        }

        return [$callable, $args];
    }
751931
public function each(callable $callback)
    {
        foreach ($this->items as $key => $item) {
            $result = $callback($item, $key);

            if (false === $result) {
                break;
            }

            if (!is_object($item)) {
                $this->items[$key] = $result;
            }
        }

        return $this;
    }
840950
public static function lift(callable $fn) : callable
    {
        return function () use ($fn) {
            if (
                array_reduce(
                    func_get_args($fn),
                    function ($status, Maybe $val) {
                        return $val->isNothing() ? false : $status;
                    },
                    true
                )
            ) {
                $args = array_map(
                    function (Maybe $maybe) {
                        return $maybe->getOrElse(null);
                    },
                    func_get_args($fn)
                );

                return self::just(call_user_func($fn, ...$args));
            }

            return self::nothing();
        };
    }
979905
public function each(\Closure $function, array $args = [])
    {
        $content = $this->getArrayCopy();
        
        return new static(
            \array_combine(
                \array_keys($content),
                \array_map(
                    function ($value) use ($function, $args) {
                        return $this->callFunction($function, $value, $args);
                    },
                    \array_values($content)
                )
            )
        );
    }
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;
        });
    }
1120542
protected function getAllFromProviders(callable $callable)
    {
        $values = array_filter(array_map($callable, $this->providers));
        $all = [];

        foreach ($values as $value) {
            foreach ($value as $v) {
                if (!in_array($v, $all, true)) {
                    $all[] = $v;
                }
            }
        }

        return $all;
    }
141205
public function each(callable $callback)
    {
        foreach ($this->nodes as $index => $node) {
            $return_value = \call_user_func($callback, $node, $index);

            if ($return_value === false) {
                break;
            }
        }

        return $this;
    }
168958
public static function mapResult(callable $f)
    {
        return function (callable $handler) use ($f) {
            return function (
                CommandInterface $command,
                RequestInterface $request = null
            ) use ($handler, $f) {
                return $handler($command, $request)->then($f);
            };
        };
    }
579231
public function each(callable $closure)
    {
        $results = [];
        foreach ($this->rows as $row) {
            $results[] = $closure(...array_values($row));
        }

        return $results;
    }
1049950
public function groupBy(callable $callback)
    {
        $results = [];

        foreach ($this->items as $key => $value) {
            $groupKey = $callback($value, $key, $this->items);

            if (! isset($results[$groupKey])) {
                $results[$groupKey] = [];
            }

            $results[$groupKey][$key] = $value;
        }

        return new static($results);
    }
360944
public static function curryArgs(callable $function, $args)
    {
        Arguments::define(Boa::func(), Boa::arr())->check($function, $args);

        // Counts required parameters.
        $required = function () use ($function) {
            return (new ReflectionFunction($function))
                ->getNumberOfRequiredParameters();
        };

        $isFulfilled = function (callable $function, $args) use ($required) {
            return count($args) >= $required($function);
        };

        if ($isFulfilled($function, $args)) {
            return static::apply($function, $args);
        }

        return function (...$funcArgs) use (
            $function,
            $args,
            $required,
            $isFulfilled
        ) {
            $newArgs = ArrayList::of($args)
                ->append(ArrayList::of($funcArgs))
                ->toArray();

            if ($isFulfilled($function, $newArgs)) {
                return static::apply($function, $newArgs);
            }

            return static::curryArgs($function, $newArgs);
        };
    }
869932
function chain($funcs,$args=NULL) {
		$out=[];
		foreach (is_array($funcs)?$funcs:$this->split($funcs) as $func)
			$out[]=$this->call($func,$args);
		return $out;
	}
941554
public static function call($function, \Closure $callback = null)
    {
        $result = null;
        if (is_array($function)) {
            $result = self::methodDI($function, $callback);
        } elseif (is_callable($function, true)) {
            $result = self::functionDI($function, $callback);
        }
        return $result;
    }
585478
public static function arrayWalkRecursive(array $data, callable $function)
    {
        if (!is_array($data)) {
            return call_user_func($function, $data);
        }

        foreach ($data as $k => &$item) {
            $item = self::arrayWalkRecursive($data[$k], $function);
        }

        return $data;
    }
979224
public static function each(callable $function, $input)
    {
        if ($input instanceof FoldableInterface) {
            $input->foldl(function ($acc, $x) use ($function) {
                $function($x);
            }, null);

            return;
        } elseif ($input instanceof LeftFoldableInterface) {
            $input->foldl(function ($x) use ($function) {
                $function($x);
            }, null);

            return;
        }

        static::map($function, $input);
    }