Esempio n. 1
0
 /**
  * Construct an instance of a Flick.
  *
  * @param array|ArrayAccess|Traversable $functions
  * @param string $default
  *
  * @throws InvalidArgumentException
  * @throws LackOfCoffeeException
  */
 public function __construct($functions, $default = 'default')
 {
     parent::__construct();
     Arguments::define(Boa::lst(), Boa::either(Boa::string(), Boa::integer()))->check($functions, $default);
     $this->functions = $functions;
     $this->default = $default;
 }
Esempio n. 2
0
 /**
  * Wrap provided value inside a List.
  *
  * @param array|ArrayObject|ListInterface $input
  *
  * @return ArrayList
  * @throws InvalidArgumentException
  */
 public static function toList($input)
 {
     Arguments::define(Boa::lst())->check($input);
     if ($input instanceof ListInterface) {
         return $input;
     }
     return ArrayList::of($input);
 }
Esempio n. 3
0
 /**
  * Concatenate the two provided values.
  *
  * @param string|array|Traversable $one
  * @param string|array|Traversable $other
  *
  * @throws MismatchedArgumentTypesException
  * @throws InvalidArgumentException
  * @return mixed
  */
 public static function concat($one, $other)
 {
     Arguments::define(Boa::either(Boa::lst(), Boa::string()), Boa::either(Boa::lst(), Boa::string()))->check($one, $other);
     $oneType = TypeHound::fetch($one);
     $twoType = TypeHound::fetch($other);
     if ($oneType !== $twoType) {
         throw new MismatchedArgumentTypesException(__FUNCTION__, $one, $other);
     }
     if ($oneType === ScalarTypes::SCALAR_STRING) {
         return $one . $other;
     }
     return ArrayMap::of($one)->append(ArrayMap::of($other))->toArray();
 }