/** * 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(); }
/** * Wrap the provided value inside a ReadMap. * * @param array|ArrayObject|ArrayAccess|Traversable|ReadMapInterface $input * * @return ArrayAccessMap|ArrayList|TraversableLeftFoldable * @throws CoreException * @throws InvalidArgumentException */ public static function toReadMap($input) { Arguments::define(Boa::readMap())->check($input); if ($input instanceof ReadMapInterface) { return $input; } if (is_array($input) || $input instanceof ArrayObject || $input instanceof ArrayAccess) { return static::toMap($input); } if ($input instanceof Traversable) { return new TraversableLeftFoldable($input); } throw new CoreException('Unable to build ReadMap'); }