For each item in the collection apply the function and return a new collection

@param callable|\Closure $function
@param array $args

@return Collection
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)
                )
            )
        );
    }
909618
function(func,args) {
    var type = lib.type.typeOf(func);
    if (type === "string") {
      var fargs = [];
      if (args instanceof Array) {
        fargs.push.apply(fargs,args);
      }
      fargs.push(func);
      func = Function.constructor.apply(Function,fargs);
    } else if (type === "error") {
      func = function() { throw func };
    } else if (type === "object") {
      func = new Method(null,func).toFunction();
    } else if (type === "undefined") {
      func = function() {};
    }
    var index = this.functions.length;
    this.functions.push(func);
    return index;
  }
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);
        };
    }
85331
public function functions(\Closure $search, \Closure $closure, $parameters = [])
    {
        $builder = new self($this->connection, new $this->query());
        $search($builder);

        $builder = new FunctionScoreBuilder($builder, $parameters);

        $closure($builder);

        $this->append($builder->getQuery());

        return $this;
    }
827158
public function invoke(Callable $callable, array $args = [])
    {
        // object/class method
        if (is_string($callable) && false !== strpos($callable, '::')) {
            $callable = explode('::', $callable);
        }
        if (is_array($callable)) {
            $reflection = new \ReflectionMethod($callable[0], $callable[1]);
        }

        // closures, functions and any other callable
        if (!isset($reflection)) {
            $reflection = new \ReflectionFunction($callable);
        }

        // inject arguments
        $arguments = $this->inject($reflection, $args);
        return $callable(...$arguments);
    }
39861
private static function apply(/* iterable */ $previous, callable $func): \Generator
    {
        foreach ($previous as $value) {
            $result = $func($value);
            if ($result instanceof \Generator) {
                yield from $result;
            } else {
                // Case of a plain old mapping function
                yield $result;
            }
        }
    }
1279273
public function parseJSON($method, array $args)
    {
        $http = $this->getHttp();

        $contents = $http->parseJSON(call_user_func_array([$http, $method], $args));

        $this->checkAndThrow($contents);

        return new Collection($contents);
    }
43968
public function apply(\Closure $function)
    {
        foreach ($this->model->countCaches() as $key => $cache) {
            $function($this->config($key, $cache));
        }
    }
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;
    }
596315
protected function executeCallback($callback, $args)
    {
        if (is_string($callback)) {
            return $this->callStringCallback($callback, $args);
        } elseif ($callback instanceof Closure) {
            return call_user_func_array($callback, $args);
        }

        return '';
    }
809371
public function save(...$args) : Collection
    {
        $collection = new Collection();

        foreach ($this->added as $current) {
            $return = $current->insert(...$args);
            $collection->add(new ModelSaved($current, $current->getChangedProperties(), $return));
        }

        foreach ($this->removed as $current) {
            $return = $current->delete(...$args);
            $collection->add(new ModelSaved($current, $current->getChangedProperties(), $return));
        }

        foreach ($this->elements as $current) {
            if (in_array($current, $this->added, true)) {
                continue;
            }

            $return = null;
            if (sizeof($current->getChangedProperties()) > 0) {
                $return = $current->update(...$args);
            }
            $collection->add(new ModelSaved($current, $current->getChangedProperties(), $return));
        }

        $this->clearHistory();

        return $collection;
    }
661824
protected function decorate($function, $args, $quotes = '\'')
	{
		if ( ! is_null( $args ) ) {
			$args = $this->argsToString($args, $quotes);
			return $function . '(' . $args . ')';
		} else {
			return $function;
		}
	}
1153479
public function map(callable $callback): Collection
    {
        $keys = array_keys($this->items);
        $items = array_map($callback, $this->items, $keys);

        return new static(array_combine($keys, $items));
    }
47576
public static function callArgs($callback, array $args = [])
    {
        try {
            $callback = static::evaluateCallback($callback);

            return \call_user_func_array($callback, $args);
        } catch (\Exception $e) {
            $message = $e->getMessage();
        }

        if (\is_array($callback) && \is_object($callback[0])) {
            $callback[0] = \get_class($callback[0]);
        }

        throw new DcGeneralRuntimeException(
            \sprintf(
                'Execute callback %s failed - Exception message: %s',
                (\is_array($callback)
                    ? \implode('::', $callback)
                    : (\is_string($callback)
                        ? $callback
                        : \get_class(
                            $callback
                        ))),
                $message
            ),
            0,
            $e
        );
    }
1059643
private function send(callable $function, ...$args): \Generator
    {
        while ($this->deferred) {
            try {
                yield $this->deferred->promise();
            } catch (\Throwable $exception) {
                // Ignore failure from another operation.
            }
        }

        if (!\is_resource($this->handle)) {
            throw new ConnectionException("The connection to the database has been closed");
        }

        $result = $function($this->handle, ...$args);

        if ($result === false) {
            throw new FailureException(\pg_last_error($this->handle));
        }

        $this->deferred = new Deferred;

        Loop::enable($this->poll);
        if (0 === $result) {
            Loop::enable($this->await);
        }

        try {
            $result = yield $this->deferred->promise();
        } finally {
            $this->deferred = null;
        }

        return $result;
    }
1341398
public function attr(...$args)
    {
        $this->each(function ($item) use ($args) {
            $item->attr(...$args);
        });

        return $this;
    }
564215
public static function multiply(callable ...$args): callable
    {
        $product = function ($x, ... $args) {
            $function = 1;
            foreach ($args as $arg) {
                $function *= $arg($x);
            }
            return $function;
        };

        return function ($x) use ($args, $product) {
            return $product(...array_merge([$x], $args));
        };
    }