/** * Construct a new Reduce Collector giving the reduce function. * * @param callable|BiFunction $fn Reduce function. * * @throws \InvalidArgumentException If function is not callable or BiFunction */ public function __construct($fn) { parent::__construct(); if ($fn instanceof BiFunction) { $this->func = $fn; } else { if (is_callable($fn)) { $this->callable = $fn; } else { throw new \InvalidArgumentException('Parameter must be callable or BiFunction.'); } } }
/** * Instanciate a new MinCollector using specific comparator function. * If comparator function is not set, use default comparator. * * @param callable|Comparator $cmp Comparator method / object. * * @throws \InvalidArgumentException If parameter is not callable or instance of Comparator. */ public function __construct($cmp = null) { parent::__construct(); if ($cmp === null) { $this->callable = function ($o1, $o2) { if ($o1 == $o2) { return 0; } return $o1 < $o2 ? -1 : 1; }; } else { if ($cmp instanceof Comparator) { $this->comparator = $cmp; } else { if (is_callable($cmp)) { $this->callable = $cmp; } else { throw new \InvalidArgumentException('Parameter must be callable or Comparator.'); } } } }