Beispiel #1
0
function groupJoinResultSelectorFunc(Person $person, IEnumerable $pets) : string
{
    $petList = $pets->select(function (Pet $pet) {
        return $pet->Name;
    })->toArray();
    return sprintf('Owner: %s; Pets: "%s"', $person->Name, implode('", "', $petList));
}
Beispiel #2
0
 /**
  * Initializes a new instance of that class.
  *
  * @param mixed $previousValue The value that was set via IItemContext::nextValue() in the context of
  *                             the previous item.
  *
  * @param IEnumerable $seq The underlying sequence.
  */
 public function __construct(IEnumerable $seq, $previousValue = null)
 {
     $this->_seq = $seq;
     $this->_previousValue = $previousValue;
     $this->_key = $this->_seq->key();
     $this->_item = $this->_seq->current();
 }
Beispiel #3
0
 /**
  * Checks a sequence if it has an expected list of same values (in the same order).
  *
  * @param IEnumerable $seq The sequence.
  * @param array $expected The expected values.
  * @param bool $exact Check values exactly or not.
  */
 protected function checkForExpectedValues(IEnumerable $seq, array $expected = [], bool $exact = true)
 {
     foreach ($expected as $index => $ev) {
         $seq->reset();
         $count = $index;
         while ($count-- > 0 && $seq->valid()) {
             $seq->next();
         }
         $av = $seq->current();
         if ($exact) {
             $this->assertSame($ev, $av);
         } else {
             $this->assertEquals($ev, $av);
         }
     }
 }
 /**
  * Resets that sequence.
  *
  * @param bool $resetSequence Reset inner sequence or not.
  */
 protected function resetMe(bool $resetSequence = true)
 {
     if ($resetSequence) {
         $this->_sequence->reset();
     }
     $selector = $this->_selector;
     // prepare items before ...
     $items = $this->_sequence->select(function ($x, IItemContext $ctx) use($selector) {
         $result = new \stdClass();
         $result->key = $ctx->key();
         $result->sortBy = $selector($x, $ctx);
         $result->value = $x;
         return $result;
     })->toArray();
     $comparer = $this->_comparer;
     \uasort($items, function (\stdClass $x, \stdClass $y) use($comparer) : int {
         return $comparer($x->sortBy, $y->sortBy);
     });
     $this->_i = static::createEnumerable($items)->withNewKeys('($key, $item) => $item->key')->select('$x => $x->value');
 }
 /**
  * {@inheritDoc}
  */
 public final function valid()
 {
     return $this->_seq->valid();
 }