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()); }
/** * Get an environment variable or return the default if it is not defined. * * This avoid any post-processing, such as automatic casting. * * @param string $key * @param null|mixed|callable $default * * @return mixed|string */ public static function getRaw($key, $default = null) { $env = ArrayMap::of($_ENV); $server = ArrayMap::of($_SERVER); if ($env->member($key)) { return Maybe::fromJust($env->lookup($key)); } elseif ($server->member($key)) { return Maybe::fromJust($server->lookup($key)); } $value = getenv($key); if ($value === false) { return Std::thunk($default); } return $value; }
/** * 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(); }
protected function renderFullField($fieldName) { $fieldNodes = $this->renderField($fieldName); if (!is_array($fieldNodes)) { $nodes = ArrayList::of([$fieldNodes]); } else { $nodes = ArrayList::of($fieldNodes); } if ($this->spec->getFieldDescription($fieldName)->isJust()) { $nodes = $nodes->append(ArrayList::of([new Paragraph([], new Small(['class' => 'text-muted'], [Maybe::fromJust($this->spec->getFieldDescription($fieldName))]))])); } return $nodes->toArray(); }
/** * @return mixed */ public function last() { return Maybe::fromJust($this->lookup($this->size - 1)); }
/** * @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); }); }
public function testFromJustWithInvalid() { $this->setExpectedException(InvalidArgumentException::class); Maybe::fromJust(Maybe::nothing()); }