示例#1
0
 /**
  * Get the value of the provided key.
  *
  * @param string $key
  *
  * @return Maybe
  */
 public function lookup($key)
 {
     if (!$this->member($key)) {
         return Maybe::nothing();
     }
     return Maybe::just($this->value->offsetGet($key));
 }
 /**
  * Get the value of the provided key.
  *
  * @param string $key
  *
  * @return Maybe
  * @throws CoreException
  */
 public function lookup($key)
 {
     foreach ($this->value as $innerKey => $value) {
         if ($key === $innerKey) {
             return Maybe::just($value);
         }
     }
     return Maybe::nothing();
 }
示例#3
0
 /**
  * Get the value of the provided key.
  *
  * @param string $key
  *
  * @return Maybe
  * @throws CoreException
  */
 public function lookup($key)
 {
     Arguments::define($this->getKeyType())->check($key);
     if (!$this->member($key)) {
         return Maybe::nothing();
     }
     return Maybe::just($this->value[$key]);
 }
示例#4
0
 /**
  * @param callable $predicate
  *
  * @return Maybe
  */
 public function find(callable $predicate)
 {
     $result = Maybe::nothing();
     $this->each(function ($value, $key) use($predicate, &$result) {
         if ($predicate($value, $key, $this)) {
             $result = Maybe::just($value);
             return false;
         }
         return true;
     });
     return $result;
 }
示例#5
0
 /**
  * @param mixed $key
  *
  * @return Maybe
  */
 public function lookup($key)
 {
     if ($this->member($key) === false) {
         return Maybe::nothing();
     }
     $copy = array_merge($this->value);
     return Maybe::just($copy[$key]);
 }
示例#6
0
 public function testFmap()
 {
     $just = Maybe::just('DOGE');
     $nothing = Maybe::nothing();
     $lowerCase = function ($string) {
         return Maybe::just(strtolower($string));
     };
     $result1 = $just->fmap($lowerCase);
     $result2 = $nothing->fmap($lowerCase);
     $this->assertTrue($result1->isJust());
     $this->assertTrue($result2->isNothing());
 }