public function testGroupInverseRule() { $a = ListLike::unit(1, 2, 3); $b = clone $a; $b->inverse(); $result = ListLike::add($a, $b); $this->assertEquals(ListLike::unit(), $result); }
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); }