public function testMap() { $functor = Funktion(function ($value) { return $value * 2; }); $this->assertTrue(Arrays::isArray(Repeatables::map(self::getArray(), $functor))); $this->assertTrue(Traversables::isTraversable(Repeatables::map(self::getIterator(), $functor))); $this->assertTrue(Traversables::isTraversable(Repeatables::map(self::getIteratorAggregate(), $functor))); $repeatables = [self::getArray(), self::getIterator(), self::getIteratorAggregate()]; foreach ($repeatables as $repeatable) { foreach (Repeatables::map($repeatable, $functor) as $key => $value) { $this->assertEquals($repeatable[$key] * 2, $value); } } }
public static final function first($repeatable) : OptionalInterface { if (self::isRepeatable($repeatable)) { if (Arrays::isArray($repeatable)) { return Arrays::first($repeatable); } if (Traversables::isTraversable($repeatable)) { return Traversables::first($repeatable); } } throw new \InvalidArgumentException(self::$MSG_ARGUMENT1_NOT_REPATABLE); }