示例#1
0
 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);
         }
     }
 }
示例#2
0
function map($repeatable, UnaryFunktionInterface $predicate)
{
    return Repeatables::map($repeatable, $predicate);
}