/**
  * constructor
  *
  * @param   \Traversable  $iterator     iterator to map values of
  * @param   callable      $valueMapper  optional  callable which maps the values
  * @param   callable      $keyMapper    optional  callable which maps the keys
  * @throws  \InvalidArgumentException  in case both $valueMapper and $keyMapper are null
  */
 public function __construct(\Traversable $iterator, callable $valueMapper = null, callable $keyMapper = null)
 {
     if (null === $valueMapper && null === $keyMapper) {
         throw new \InvalidArgumentException('Passed null for both valueMapper and keyMapper, but at ' . 'least one of both must not be null');
     }
     parent::__construct($iterator);
     if (null !== $valueMapper) {
         $this->valueMapper = ensureCallable($valueMapper);
         $this->description[] = 'values mapped by ' . describeCallable($valueMapper);
     }
     if (null !== $keyMapper) {
         $this->keyMapper = ensureCallable($keyMapper);
         $this->description[] = 'keys mapped by ' . describeCallable($keyMapper);
     }
 }
Example #2
0
 /**
  * returns description of this iterator
  *
  * @return  string
  */
 public function description() : string
 {
     return 'starting at ' . $this->seed . ' continued by ' . describeCallable($this->operation);
 }
Example #3
0
 public function __construct(\Iterator $iterator, callable $callback)
 {
     parent::__construct($iterator, ensureCallable($callback));
     $this->description = describeCallable($callback);
 }