예제 #1
0
 public function testGroupInverseRule()
 {
     $a = ListLike::unit(1, 2, 3);
     $b = clone $a;
     $b->inverse();
     $result = ListLike::add($a, $b);
     $this->assertEquals(ListLike::unit(), $result);
 }
예제 #2
0
 public static function add($a, $b)
 {
     if ($a->isInverse($b)) {
         return ListLike::unit();
     }
     $flatten = array();
     foreach ($a as $elem) {
         array_push($flatten, $elem);
     }
     $a->rewind();
     foreach ($b as $elem) {
         array_push($flatten, $elem);
     }
     $b->rewind();
     return (new \ReflectionClass("Monadic\\Type\\ListLike"))->newInstanceArgs($flatten);
 }