Exemple #1
0
 public function step($result, $input)
 {
     if (call_user_func($this->pred, $input)) {
         return $this->xf->step($result, $input);
     } else {
         return $result;
     }
 }
Exemple #2
0
 public function step($result, $input)
 {
     if (call_user_func($this->pred, $input)) {
         return $this->xf->step($result, $input);
     } else {
         return Transducers::reduced($result);
     }
 }
 public function step($result, $input)
 {
     $ret = $this->xf->step($result, $input);
     if (Transducers::isReduced($ret)) {
         return Transducers::reduced($ret);
     }
     return $ret;
 }
Exemple #4
0
 public function step($result, $input)
 {
     $v = call_user_func($this->f, $input);
     if ($v === null) {
         return $result;
     } else {
         return $this->xf->step($result, $v);
     }
 }
Exemple #5
0
 public function step($result, $input)
 {
     if ($this->n > 0) {
         $this->n -= 1;
         return $result;
     } else {
         return $this->xf->step($result, $input);
     }
 }
Exemple #6
0
 public function step($result, $input)
 {
     $this->i += 1;
     if ($this->i % $this->n === 0) {
         return $this->xf->step($result, $input);
     } else {
         return $result;
     }
 }
Exemple #7
0
 public function step($result, $input)
 {
     if ($this->n > 0) {
         $result = $this->xf->step($result, $input);
     } else {
         $result = Transducers::ensureReduced($result);
     }
     $this->n -= 1;
     return $result;
 }
Exemple #8
0
 public function step($result, $input)
 {
     if ($this->drop && call_user_func($this->pred, $input)) {
         return $result;
     } else {
         if ($this->drop) {
             $this->drop = false;
         }
         return $this->xf->step($result, $input);
     }
 }
Exemple #9
0
 public function step($result, $input)
 {
     $this->a[] = $input;
     if (count($this->a) === $this->n) {
         $a = $this->a;
         $this->a = [];
         return $this->xf->step($result, $a);
     } else {
         return $result;
     }
 }
 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);
 }
Exemple #11
0
 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);
 }
Exemple #12
0
 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);
 }
Exemple #13
0
 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);
 }
Exemple #14
0
 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;
 }
Exemple #15
0
 public function result($result)
 {
     return $this->xf->result($result);
 }
Exemple #16
0
 public function step($result, $input)
 {
     return $this->xf->step($result, call_user_func($this->f, $input));
 }