public static function into($empty, $xf, $coll) { $f = function ($fileResource, $x) { fputs($fileResource, $x); return $fileResource; }; return Transducers::transduce($xf, $f, $empty, $coll); }
public function step($result, $input) { $ret = $this->xf->step($result, $input); if (Transducers::isReduced($ret)) { return Transducers::reduced($ret); } return $ret; }
public static function into($empty, $xf, $coll) { $f = function ($str, $x) { $str .= $x; return $str; }; return Transducers::transduce($xf, $f, $empty, $coll); }
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 result($result) { if (count($this->a) > 0) { $result = Transducers::unreduced($this->xf->step($result, $this->a)); $this->a = []; } return $this->xf->result($result); }
public static function reduce($coll, TransformerInterface $xf, $init) { $isAssoc = Transducers::isAssoc($coll); if ($isAssoc) { return TraversableReduce::reduce($coll, $xf, $init); } else { return self::reduceArray($coll, $xf, $init); } }
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; }
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 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 static function parse($xml) { /* @var $xml \DOMElement */ $element = [$xml->tagName]; if ($xml->hasAttributes()) { $xf = t::comp(t::map(t::value()), t::map(function (\DOMAttr $attr) { return [$attr->name, $attr->value]; })); $element[] = t::intoAssoc([], $xf, $xml->attributes); } if ($xml->hasChildNodes()) { $xf = t::comp(t::map(t::value()), t::map(['\\Phonon\\Xml\\XmlParser', 'parse'])); $element[] = t::into([], $xf, $xml->childNodes); } return $element; }
public function getElementType($element) { if (count($element) == 1) { return "tag"; } if (count($element) == 2) { if (\Phonon\Transducers\Transducers::isAssoc($element[1])) { return "tag-attr"; } else { return "tag-body"; } } if (count($element) == 3) { return "tag-attr-body"; } }
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; }
public function step($result, $input) { return Transducers::reduce($this->rxf, $result, $input); }
public function testMapCat() { $input = [[0, 1, 2], [3, 4, 5], [6]]; $expected = [0, 1, 2, 3, 4, 5, 6]; $xf = t::mapcat(t::identity()); $actual = t::into([], $xf, $input); $this->assertEquals($expected, $actual); }