示例#1
0
 /**
  * @param $value
  * @param null $reject
  * @return Option
  */
 public static function wrap($value, $reject = null)
 {
     if ($value === $reject) {
         return None::instance();
     }
     return new Some($value);
 }
示例#2
0
 function filter($callable)
 {
     if (is_callable($callable)) {
         return $callable($this->get()) ? $this : None::instance();
     } elseif (is_array($callable)) {
         return in_array($this->get(), $callable) ? $this : None::instance();
     }
     throw new \InvalidArgumentException("Expected only callable or array type of argument.");
 }
示例#3
0
 /**
  * @return Option
  */
 public static function None()
 {
     return None::instance();
 }
示例#4
0
 public function selectInstance($object)
 {
     return $this->get() instanceof $object ? $this : None::instance();
 }
示例#5
0
 /**
  * @param $filePath
  * @return Option
  */
 public static function ofFile($filePath)
 {
     return file_exists($filePath) ? new Some($filePath) : None::instance();
 }
示例#6
0
 /**
  * @param $method
  * @param $args
  * @return $this
  */
 public function call($method, ...$args)
 {
     return is_object($this->get()) && method_exists($this->get(), $method) ? Option::Some($this->get()->{$method}(...$args)) : None::instance();
 }