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'))); }
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()); }
/** * 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(); }
/** * @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; }
/** * @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); }); }
/** * @return mixed */ public function last() { return Maybe::fromJust($this->lookup($this->size - 1)); }
public function testFromJustWithInvalid() { $this->setExpectedException(InvalidArgumentException::class); Maybe::fromJust(Maybe::nothing()); }