예제 #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
 /**
  * Render the object into a string.
  *
  * @return mixed
  */
 public function render()
 {
     $addColon = function ($label) {
         return Maybe::just(vsprintf('%s:', [$label]));
     };
     return (new Form($this->attributes, $this->spec->getAnnotations()->map(function ($_, $key) use($addColon) {
         return new Row(['class' => 'form-group'], [new Node('label', ['class' => 'col-sm-2 form-control-label'], Maybe::fromMaybe('', $this->spec->getFieldLabel($key)->bind($addColon))), new Div(['class' => 'col-sm-8'], $this->renderFullField($key))]);
     })->append(ArrayMap::of([new Row(['class' => 'form-group'], [new Div(['class' => 'col-sm-offset-2 col-sm-10'], [new Div(['class' => 'btn-group'], [new Button(['type' => 'reset', 'class' => 'btn btn-secondary'], 'Reset'), new Button(['type' => 'submit', 'class' => 'btn btn-primary'], 'Submit')])])])]))))->render();
 }
예제 #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
 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());
 }
예제 #6
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]);
 }