public function step($result, $input) { $ret = $this->xf->step($result, $input); if (Transducers::isReduced($ret)) { return Transducers::reduced($ret); } return $ret; }
public static function reduce($coll, TransformerInterface $xf, $init) { $result = $init; foreach ($coll as $key => $value) { $result = $xf->step($result, new Pair([$key, $value])); if (Transducers::isReduced($result)) { $result = Transducers::deref($result); break; } } return $xf->result($result); }
public static function reduceArray($coll, TransformerInterface $xf, $init) { $result = array_reduce($coll, function ($result, $input) use($xf) { if (Transducers::isReduced($result)) { return $result; } return $xf->step($result, $input); }, $init); if (Transducers::isReduced($result)) { $result = Transducers::deref($result); } return $xf->result($result); }
public static function reduce($coll, TransformerInterface $xf, $init) { $result = $init; while (!feof($coll)) { $item = fgets($coll, 8196); $result = $xf->step($result, $item); if (Transducers::isReduced($result)) { $result = Transducers::deref($result); break; } } return $xf->result($result); }
public static function reduce($coll, TransformerInterface $xf, $init) { $result = $init; $length = strlen($coll); for ($i = 0; $i < $length; $i += 1) { $result = $xf->step($result, $coll[$i]); if (Transducers::isReduced($result)) { $result = Transducers::deref($result); break; } } return $xf->result($result); }
public function step($result, $input) { $pval = $this->pval; $val = call_user_func($this->f, $input); $this->pval = $val; $none = Transducers::none(); if ($pval === $none || $pval === $val) { $this->a[] = $input; return $result; } $ret = $this->xf->step($result, $this->a); $this->a = []; if (!Transducers::isReduced($ret)) { $this->a[] = $input; } return $ret; }