CountableIterator.php 497 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. declare(strict_types=1);
  3. namespace TestApp\Collection;
  4. use Countable;
  5. use IteratorIterator;
  6. class CountableIterator extends IteratorIterator implements Countable
  7. {
  8. /**
  9. * @param mixed $items
  10. */
  11. public function __construct($items)
  12. {
  13. $f = function () use ($items) {
  14. foreach ($items as $e) {
  15. yield $e;
  16. }
  17. };
  18. parent::__construct($f());
  19. }
  20. public function count(): int
  21. {
  22. return 6;
  23. }
  24. }