public function __construct(Collector $collector, FunctionValue $wrapper) { C::guardHasArity($wrapper, 2); if ($collector->isNullaryCollector()) { throw new Exception("It makes no sense to wrap around a nullary collector."); } $this->_collector = $collector; $this->_wrapper = $wrapper; }
public static function combineCollectors(Collector $l, Collector $r) { $l_empty = $l->isNullaryCollector(); $r_empty = $r->isNullaryCollector(); if ($l_empty && $r_empty) { return new NullaryCollector(); } elseif ($r_empty) { return $l; } elseif ($l_empty) { return $r; } else { return new ApplyCollector($l, $r); } }