• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

markrogoyski / math-php / 4071918739

pending completion
4071918739

Pull #464

github

GitHub
Merge f5a52dc70 into 7795af2a2
Pull Request #464: Set::intersectPartial() method added to the SetTheory namespace

41 of 41 new or added lines in 3 files covered. (100.0%)

7892 of 7897 relevant lines covered (99.94%)

179.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.0
/src/Util/JustifyMultipleIterator.php
1
<?php
2

3
namespace MathPHP\Util;
4

5
/**
6
 * @implements \Iterator<array<mixed>>
7
 *
8
 * Based on IterTools PHP's IteratorFactory.
9
 * @see https://github.com/markrogoyski/itertools-php
10
 * @see https://github.com/markrogoyski/itertools-php/blob/main/src/Util/JustifyMultipleIterator.php
11
 */
12
class JustifyMultipleIterator implements \Iterator
13
{
14
    /**
15
     * @var array<\Iterator<mixed>>
16
     */
17
    protected $iterators = [];
18
    /**
19
     * @var int
20
     */
21
    protected $index = 0;
22

23
    /**
24
     * @param iterable<mixed> ...$iterables
25
     */
26
    public function __construct(iterable ...$iterables)
27
    {
28
        foreach ($iterables as $iterable) {
194✔
29
            $this->iterators[] = Iter::makeIterator($iterable);
194✔
30
        }
31
    }
32

33
    /**
34
     * {@inheritDoc}
35
     *
36
     * @return array<mixed>
37
     */
38
    public function current(): array
39
    {
40
        return array_map(
167✔
41
            static function (\Iterator $iterator) {
167✔
42
                return $iterator->valid() ? $iterator->current() : NoValueMonad::getInstance();
167✔
43
            },
167✔
44
            $this->iterators
167✔
45
        );
167✔
46
    }
47

48
    /**
49
     * {@inheritDoc}
50
     */
51
    public function next(): void
52
    {
53
        foreach ($this->iterators as $iterator) {
167✔
54
            if ($iterator->valid()) {
167✔
55
                $iterator->next();
167✔
56
            }
57
        }
58
        $this->index++;
167✔
59
    }
60

61
    /**
62
     * {@inheritDoc}
63
     *
64
     * @return int
65
     */
66
    public function key(): int
67
    {
68
        return $this->index;
×
69
    }
70

71
    /**
72
     * {@inheritDoc}
73
     */
74
    public function valid(): bool
75
    {
76
        foreach ($this->iterators as $iterator) {
194✔
77
            if ($iterator->valid()) {
194✔
78
                return true;
167✔
79
            }
80
        }
81

82
        return false;
194✔
83
    }
84

85
    /**
86
     * {@inheritDoc}
87
     */
88
    public function rewind(): void
89
    {
90
        foreach ($this->iterators as $iterator) {
194✔
91
            $iterator->rewind();
194✔
92
        }
93
        $this->index = 0;
194✔
94
    }
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc