Ejemplo n.º 1
0
 /**
  * {@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;
 }
Ejemplo n.º 2
0
 /**
  * @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);
 }
Ejemplo n.º 3
0
 /**
  * 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);
 }