Пример #1
0
 /**
  * Return one of the collected element.
  * 
  * @return Optional Any collected element or {@see Optional::absent()} if no element has been collected.
  */
 public function get()
 {
     if (empty($this->values)) {
         return Optional::absent();
     }
     return Optional::of($this->values[intval(rand(0, count($this->values) - 1))]);
 }
Пример #2
0
 public function testOptionalEquals()
 {
     $opt = Optional::absent();
     $this->assertTrue($opt->equals($opt));
     $this->assertTrue($opt->equals(Optional::absent()));
     $this->assertFalse($opt->equals(Optional::of([0, 1, 2])));
     $this->assertFalse($opt->equals([0, 1, 2]));
     $opt = Optional::of([0, 1, 2]);
     $this->assertTrue($opt->equals($opt));
     $this->assertTrue($opt->equals(Optional::of([0, 1, 2])));
     $this->assertFalse($opt->equals(Optional::absent()));
     $this->assertFalse($opt->equals(Optional::of([2, 3, 4])));
     $this->assertFalse($opt->equals([0, 1, 2]));
 }
Пример #3
0
 /**
  * Removing the collected element.
  */
 public function reset()
 {
     $this->current = Optional::absent();
 }
Пример #4
0
 /** 
  * Remove the collected element.
  */
 public function reset()
 {
     $this->optional = Optional::absent();
 }