예제 #1
0
 /**
  * Run the flick on input.
  *
  * @param string|int $input
  *
  * @throws UnknownKeyException
  * @return mixed
  */
 public function go($input)
 {
     Arguments::define(Boa::readMap())->define($input);
     $map = ComplexFactory::toReadMap($this->functions);
     if ($map->member($input)) {
         /** @var callable $function */
         $function = Maybe::fromJust($map->lookup($input));
         return $function();
     } elseif ($map->member($this->default)) {
         /** @var callable $function */
         $function = Maybe::fromJust($map->lookup($this->default));
         return $function();
     }
     throw new UnknownKeyException();
 }
예제 #2
0
파일: Std.php 프로젝트: sellerlabs/nucleus
 /**
  * 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);
 }