Folds `Seq` items to the right

@param callable $function function which will fold values
@param mixed $initial the initial fold value

@return mixed|null
187537
public function foldRight(callable $function, $initial = null)
    {
        if ($this->isEmpty()) {
            return $initial;
        }

        return array_reduce(array_reverse($this->data, true), $function, $initial);
    }
341296
private function _first(callable $callback = null)
    {
        $values = $this->getValues();
        if ($callback){
            foreach($values as $key => $value){
                if ($callback($value, $key)){
                    return $value;
                }
            }
        }
        else{
            return empty($values) ? null : $values[0];
        }
        return null;
    }
173420
private function sortableCallSpecial($function, $arguments)
    {
        $params = array_merge(
            array_slice($arguments, 0, 1),
            [$this->sortableConcreteData()],
            array_values(array_slice($arguments, 1))
        );
        return call_user_func_array($function, $params);
    }
840711
private function sortableCallByReference($function, $arguments)
    {
        $list = $this->sortableConcreteData();
        $params = array_merge([&$list], $arguments);
        $result = call_user_func_array($function, $params);
        if ($result) {
            $this->sortableResetArray($list);
        }
        return $result;
    }
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);
    }
374028
public function initial($collection=null, $n=null) {
    list($collection, $n) = self::_wrapArgs(func_get_args(), 2);
    
    $collection = (array) self::_collection($collection);
    
    if(is_null($n)) $n = 1;
    $first_index = count($collection) - $n;
    $__ = new self;
    return self::_wrap($__->first($collection, $first_index));
  }
217753
public function cacheFun($function) {
        if ($this->getConfig('debug') && !is_callable($function))
            echo "no valid function";

        $r = new ReflectionFunction($function);
        $id = null;

        foreach ($r->getStaticVariables() as $key => $var) {
            if ($key == 'key')
                $id = $var;
        }

        if (is_object($id))
            $id = $this->getIDfromOjb($id);

        if ($id == null && $this->getConfig('debug')) {
            echo "no caching key";
            return $function();
        }

        $cachefile = $this->getConfig('cacheDir') . '/' . utf8_decode($id);
        $cachetime = $this->getConfig('cacheTime');

        if (file_exists($cachefile) && time() - $cachetime < fileatime($cachefile)) {
            $ser = file_get_contents($cachefile);
            $val = bzdecompress(unserialize($ser));
            return $val;
        } else {
            $value = $function();
            $ser = serialize(bzcompress($value));
            file_put_contents($cachefile, $ser);
            return $value;
        }

        if ($this->getConfig('debug'))
            echo "no caching";
    }
597824
public static function getCached($function)
    {
        $returnValue = null;

        
		$args = func_get_args();
		array_shift($args);
        if (!is_string($function)){
            $r = new ReflectionFunction($function);
            $serial = md5(
              $r->getFileName().
              $r->getStartLine().
              serialize($args)
            );
        } else {
            $serial = md5($function.serialize($args));
        }
        if (static::singleton()->has($serial)) {
        	$returnValue = static::singleton()->has($serial);
        } else { 
	        $returnValue = call_user_func_array($fn, $args);
	        static::singleton()->put($serial, $returnValue);
        }
        

        return $returnValue;
    }
1008808
public function map(callable $function)
    {
        $output = new Dict();

        foreach ($this->data as $key => $value) {
            $output->offsetSet($key, $function($key, $value));
        }

        return $output;
    }
51799
public function foldrWithKeys(callable $closure, $initial)
    {
        return $this
            ->reverse()
            ->foldlWithKeys(
                function ($acc, $key, $x) use ($closure) {
                    return $closure($key, $x, $acc);
                },
                $initial
            );
    }
395101
public function fold(callable $f)
    {
        $fold = function (Tree $tree) use (&$fold, $f) {
            return $f($tree->node, \array_map($fold, $tree->children));
        };
        return $fold($this);
    }
1297019
public function reduce(callable $callback, $initial = null): Collection
    {
        return new Collection(array_reduce($this->items, $callback, $initial));
    }
108523
public static <T, R> Function1<T, R> memoizeFunction(final Function<T, R> fn, final Cacheable<R> cache) {
        LazyImmutable<R> nullR = LazyImmutable.def();
        return t -> t==null? nullR.computeIfAbsent(()->fn.apply(null)) : (R)cache.soften()
                         .computeIfAbsent(t, (Function) fn);
    }
427834
public static function compose(/* $function1, $function2, ... */)
    {
        $functions = func_get_args();

        if (count($functions) === 1) {
            static::validate($functions[0]);
            return $functions[0];
        }

        $firstFunction = array_shift($functions);

        static::validate($firstFunction);

        return function() use($firstFunction, $functions) {

            $partial = call_user_func_array(array('\Functionals\Functionals', 'compose'), $functions);

            return call_user_func($firstFunction, call_user_func_array($partial, func_get_args()));
        };
    }
837456
public function sort(callable $compareFunction = null)
    {
        if (is_null($compareFunction) === true) {
            $compareFunction = function ($a, $b) {
                return $a > $b;
            };
        }
        $array = $this->getArrayCopy();
        usort($array, $compareFunction);
        $this->exchangeArray($array);

        return $this;
    }
134838
public function reduce(callable $callback, $initial = null)
    {
        foreach ($this->generator as $key => $value) {
            $initial = $callback($initial, $value, $key);
        }

        return $initial;
    }
723935
function merge(iUriSequence $mergeUri)
    {
        $return = clone $this;

        if ($mergeUri->isAbsolute())
            return $return->setPath($mergeUri->getPath());
        
        // 
        
        $return = $return->mask($mergeUri)
            ->split(0, -1)
            ->append($mergeUri)
        ;

        return $return;
    }