Combine all the elements in the traversable using a combining operation.

@param callable $closure
@param mixed $initial

@return mixed
966206
public function foldr(callable $closure, $initial)
    {
        return $this->reverse()->foldl(
            function ($acc, $x) use ($closure) {
                return $closure($x, $acc);
            },
            $initial
        );
    }
415062
public function filter(Closure $closure): self
    {
        $filter = new Iterator\CustomFilterIterator($this->getIterator(), [$closure]);

        return new self(iterator_to_array($filter));
    }
455323
public function join($table, Closure $closure)
    {
        $this->sql->addJoinClause('INNER', $table, $closure);
        return $this;
    }
760274
public function group(array $options, \Closure $closure)
	{
		$group = new static(null, $options);

		$closure->bindTo($group)->__invoke($group);

		$this->getCollection()->addAll($group->getCollection());

		return $this;

	}
652767
public function apply($closure)
    {
        foreach ($this->_data as $key => $val) {
            $this->_data[$key] = $closure($val, $key, $this);
        }
        return $this;
    }
902673
protected static function getOrInit($id, Closure $closure)
  {
    if (!self::has($id)) {
      self::set($id, $closure());
    }

    return self::get($id);
  }
643602
public function foldlWithKey(callable $closure, $initial)
    {
        $accumulator = $initial;

        foreach ($this->value as $key => $value) {
            $accumulator = Std::call($closure, $accumulator, $value, $key);
        }

        return $accumulator;
    }
392590
public function extend($abstract, Closure $closure)
    {
        $abstract = $this->getAlias($abstract);

        if (isset($this->instances[$abstract])) {
            $this->instances[$abstract] = $closure($this->instances[$abstract], $this);

            $this->rebound($abstract);
        } else {
            $this->extenders[$abstract][] = $closure;

            if ($this->resolved($abstract)) {
                $this->rebound($abstract);
            }
        }
    }
233588
public function parallel($closure, $options = array(), $start = true)
    {
        // Check auto_start
        if (is_bool($options)) {
            $start = $options;
            $options = array();
        }

        // Check if process set
        if ($closure instanceof Process) {
            $child = $closure;
            $closure = $child->runner;
            $options = $child->options;
        } else {
            // Build new child
            $child = new Process($this, null, $this->pid);

            // Get options
            $options = $this->getOptions($options);
        }

        // Auto start
        if (!$start) {
            $child->register($closure, $options);
            if (!in_array($child, $this->prepared_children)) {
                $this->prepared_children[] = $child;
            }
            return $child;
        }

        // Process init
        if ($options['init'] instanceof \Closure) {
            $options['init']($child);
        }

        // Fork
        $pid = pcntl_fork();

        // Save child process and return
        $this->children[$pid] = $child;
        // Remove from prepared children
        if (($index = array_search($child, $this->prepared_children)) !== false) {
            unset($this->prepared_children[$index]);
        }

        // Parallel works
        if ($pid === -1) {
            throw new \RuntimeException('Unable to fork child process.');
        } else if ($pid) {
            // Save child process and return
            $child->init($pid);
            $child->emit('fork');
            return $child;
        } else {
            // Child initialize
            $this->childInitialize($options);

            // Support callable
            call_user_func($closure, $this->process);
            exit;
        }
    }
283709
public function byClosure(Closure $closure)
    {
        $this->controller = new Controller();
        if ($this->hasContainer() && method_exists($this->controller, 'raikiri'))
            $this->controller->setContainer($this->raikiri());

        $this->action = $closure->bindTo($this->controller);
    }
250373
public function reduce(\Closure $p, $initialValue = null)
    {
        return array_reduce($this->toArray(), $p, $initialValue);
    }
943614
protected function resolveClosure($closure)
    {
        $scenario = $closure();

        if ($interfaces = class_implements($scenario)) {
            if (in_array('Keios\Apparatus\Contracts\Runnable', $interfaces)) {
                return is_object($scenario) ? $scenario : new $scenario();
            }
        }

        throw new InvalidScenarioException(
            sprintf('Closure return value is not a valid scenario object or scenario class name.')
        );
    }
958051
public function aggregate(\Closure $closure)
    {
        $builder = new AggregationBuilder($this->query);

        $closure($builder);

        return $this;
    }
687429
public function apply($closure)
    {
        foreach ($this as $key => $val) {
            $this->offsetSet($key, $closure($val, $key, $this));
        }
        return $this;
    }
187537
public function foldRight(callable $function, $initial = null)
    {
        if ($this->isEmpty()) {
            return $initial;
        }

        return array_reduce(array_reverse($this->data, true), $function, $initial);
    }
614060
public function share(Closure $closure)
		{
			return function($Eventable) use ($closure) {
				// We'll simply declare a static variable within the Closures and if it has
				// not been set we will execute the given Closures to resolve this value
				// and return it back to these consumers of the method as an instance.
				static $object;
				if (is_null($object)) {
					$object = $closure($Eventable);
				}
				return $object;
			};
		}
1178071
public function compose(array $closures, array $arguments = [])
    {
        $result = call_user_func_array(array_shift($closures), $arguments);

        foreach ($closures as $closure)
        {
            $result = $closure($result);
        }

        return $result;
    }