Esempio n. 1
0
 public static final function elementAt(array $array, $offset) : OptionalInterface
 {
     foreach ($array as $key => $value) {
         if ($key === $offset) {
             return Optional::of($value);
         }
     }
     return Optional::absent();
 }
Esempio n. 2
0
 public static final function elementAt(\Traversable $traversable, $position) : OptionalInterface
 {
     $i = 0;
     foreach ($traversable as $value) {
         if ($i == $position) {
             return Optional::of($value);
         }
     }
     return Optional::absent();
 }
Esempio n. 3
0
 public function testOfEmpty()
 {
     $o = Optional::OfEmpty(0);
     $this->assertInstanceOf(Optional::class, $o);
     $this->assertInstanceOf(OptionalInterface::class, $o);
     $this->assertTrue($o->isAbsent());
     $this->assertFalse($o->isPresent());
     $o = Optional::OfEmpty([]);
     $this->assertInstanceOf(Optional::class, $o);
     $this->assertInstanceOf(OptionalInterface::class, $o);
     $this->assertTrue($o->isAbsent());
     $this->assertFalse($o->isPresent());
 }