示例#1
0
 public function testInsert()
 {
     $instance = new ArrayAccessMap(new ArrayObject(['great' => 'job']));
     $instance2 = $instance->insert('omg', 'wow');
     $this->assertNotSame($instance, $instance2);
     $this->assertEquals('wow', Maybe::fromJust($instance2->lookup('omg')));
 }
示例#2
0
 public function testSetFieldDescription()
 {
     $spec = new FormSpec();
     $this->assertTrue($spec->getFieldDescription('wow')->isNothing());
     $final = $spec->withFieldDescription('wow', 'WOWs');
     $this->assertNotSame($spec, $final);
     $this->assertTrue($final->getFieldDescription('wow')->isJust());
     $this->assertEquals('WOWs', Maybe::fromJust($final->getFieldDescription('wow')));
     $this->assertEquals(['wow' => 'WOWs'], $final->getDescriptions()->toArray());
 }
示例#3
0
 /**
  * Run the flick on input.
  *
  * @param string|int $input
  *
  * @throws UnknownKeyException
  * @return mixed
  */
 public function go($input)
 {
     Arguments::define(Boa::readMap())->define($input);
     $map = ComplexFactory::toReadMap($this->functions);
     if ($map->member($input)) {
         /** @var callable $function */
         $function = Maybe::fromJust($map->lookup($input));
         return $function();
     } elseif ($map->member($this->default)) {
         /** @var callable $function */
         $function = Maybe::fromJust($map->lookup($this->default));
         return $function();
     }
     throw new UnknownKeyException();
 }
示例#4
0
 /**
  * @param array|Iterable $searchKeyPath
  *
  * @return bool
  * @throws MindTheGapException
  */
 public function memberIn($searchKeyPath)
 {
     $path = ArrayList::of($searchKeyPath);
     if ($path->count() === 0) {
         return false;
     }
     if ($path->count() === 1) {
         return $this->member($path->head());
     }
     if ($this->member($path->head()) === false) {
         return false;
     }
     $innerValue = Maybe::fromJust($this->lookup($path->head()));
     if ($innerValue instanceof Iterable) {
         return $innerValue->memberIn($path->tail());
     }
     return false;
 }
示例#5
0
 /**
  * @param string $name
  *
  * @return ArrayMap
  */
 public function getAnnotation($name)
 {
     return $this->annotations->map(function (ArrayMap $value) use($name) {
         return $value->lookup($name);
     })->filter(function (Maybe $value) {
         return $value->isJust();
     })->map(function (Maybe $value) {
         return Maybe::fromJust($value);
     });
 }
示例#6
0
 /**
  * @return mixed
  */
 public function last()
 {
     return Maybe::fromJust($this->lookup($this->size - 1));
 }
示例#7
0
 public function testFromJustWithInvalid()
 {
     $this->setExpectedException(InvalidArgumentException::class);
     Maybe::fromJust(Maybe::nothing());
 }