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 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); }