/** * {@inheritDoc} */ public function flatMapBy($mapper) { Contracts::ensureCallable($mapper); // Grecefully handle not Option return value. if (!($option = call_user_func($mapper, $this->data)) instanceof Option) { $option = Option::from($option); } return $option; }
/** * @param object|string $value Object or class name. * @param string $methodName * * @return \Colada\Option */ private static function getMethodFrom($value, $methodName) { if (is_object($value) && !$value instanceof \ReflectionClass) { $class = new \ReflectionObject($value); } elseif (is_string($value)) { $class = new \ReflectionClass($value); } $method = null; if ($class->hasMethod($methodName)) { $method = $class->getMethod($methodName); } return Option::from($method); }
/** * Converts this result to an option * * If this is a success, it returns an Option::just * If this is an error, it returns Option::none */ public function toOption() { return Option::from($this->value); }