Esempio n. 1
0
 /**
  * Провайдер данных для теста getOrElse
  * @return array
  */
 public function getOrElseDataProvider()
 {
     return [['option' => Option::apply(1), 'else' => 2, 'result' => 1], ['option' => Option::apply(null), 'else' => 2, 'result' => 2], ['option' => Option::apply(null), 'else' => function () {
         return 3;
     }, 'result' => 3]];
 }
Esempio n. 2
0
 /**
  * @param \Closure $f
  * @return Option
  */
 public function find($f)
 {
     /**@var \Iterator $iterator */
     $iterator = $this->getIterator();
     while ($iterator->valid()) {
         if ($f($iterator->current())) {
             return Option::apply($iterator->current());
         }
         $iterator->next();
     }
     return new None();
 }
Esempio n. 3
0
 /**
  * (PHP 5 &gt;= 5.0.0)<br/>
  * Offset to retrieve
  * @link http://php.net/manual/en/arrayaccess.offsetget.php
  * @param mixed $offset <p>
  * The offset to retrieve.
  * </p>
  * @return Option Can return all value types.
  */
 public function offsetGet($offset)
 {
     return Option::apply(array_key_exists($offset, $this->data) ? $this->data[$offset] : null);
 }
Esempio n. 4
0
 /**
  * Проверка создания конкретного типа данных из Option::apply()
  *
  * @dataProvider valuesDataProvider
  *
  * @param string $class
  * @param mixed $value
  * @param boolean $useEmpty
  * @return void
  */
 public function testApply($class, $value, $useEmpty)
 {
     self::assertInstanceOf($class, Option::apply($value, $useEmpty));
 }