-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathIterators.php
65 lines (54 loc) · 1.03 KB
/
Iterators.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace drupol\phpermutations;
use Countable;
abstract class Iterators extends Combinatorics implements Countable, IteratorInterface
{
/**
* A copy of the dataset at a give time.
*
* @var array<int, mixed>
*/
protected $current;
/**
* @var int
*/
protected $key = 0;
/**
* {@inheritdoc}
*/
public function current(): mixed
{
return $this->current;
}
/**
* {@inheritdoc}
*/
public function key(): int
{
return $this->key;
}
/**
* {@inheritdoc}
*
* @return void
*/
public function rewind(): void
{
$this->key = 0;
}
/**
* Convert the iterator into an array.
*
* @return array<int, mixed>
* The elements
*/
public function toArray(): array
{
$data = [];
for ($this->rewind(); $this->valid(); $this->next()) {
$data[] = $this->current();
}
return $data;
}
}