/** * Wrap the provided value inside a Functor. * * @param array|ArrayObject|Traversable|FunctorInterface $input * * @return ArrayList|TraversableLeftFoldable * @throws CoreException */ public static function toFunctor($input) { Arguments::define(Boa::leftFoldable())->check($input); if ($input instanceof FunctorInterface) { return $input; } if (is_array($input) || $input instanceof ArrayObject) { return static::toList($input); } throw new CoreException('Unable to build Functor'); }
/** * Returns a single item by iterating through the list, successively calling * the iterator function and passing it an accumulator value and the current * value from the array, and then passing the result to the next call. * (From Ramda). * * @param callable $function * @param mixed $initial * @param array|Traversable $foldable * * @throws InvalidArgumentException * @return mixed */ public static function foldl(callable $function, $initial, $foldable) { Arguments::define(Boa::func(), Boa::any(), Boa::leftFoldable())->check($function, $initial, $foldable); return ComplexFactory::toLeftFoldable($foldable)->foldl($function, $initial); }