/** * @param $value * @param null $reject * @return Option */ public static function wrap($value, $reject = null) { if ($value === $reject) { return None::instance(); } return new Some($value); }
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."); }
/** * @return Option */ public static function None() { return None::instance(); }
public function selectInstance($object) { return $this->get() instanceof $object ? $this : None::instance(); }
/** * @param $filePath * @return Option */ public static function ofFile($filePath) { return file_exists($filePath) ? new Some($filePath) : None::instance(); }
/** * @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(); }