/** * Wrap provided value inside a Foldable. * * @param array|ArrayObject|FoldableInterface $input * * @return ArrayList * @throws CoreException * @throws InvalidArgumentException */ public static function toFoldable($input) { Arguments::define(Boa::foldable())->check($input); if ($input instanceof FoldableInterface) { return $input; } if (is_array($input) || $input instanceof ArrayObject) { return static::toList($input); } throw new CoreException('Unable to build Foldable'); }
/** * Same as foldl but it works from right to left. * * @param callable $function * @param mixed $initial * @param array|FoldableInterface $foldable * * @return mixed */ public static function foldr(callable $function, $initial, $foldable) { Arguments::define(Boa::func(), Boa::any(), Boa::foldable())->check($function, $initial, $foldable); return ComplexFactory::toFoldable($foldable)->foldr($function, $initial); }