-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSet.php
More file actions
46 lines (42 loc) · 918 Bytes
/
Set.php
File metadata and controls
46 lines (42 loc) · 918 Bytes
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
<?php declare(strict_types=1);
/**
* This file is part of the Phootwork package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
* @copyright Thomas Gossmann
*/
namespace phootwork\collection;
use Iterator;
/**
* Represents a Set
*
* @author Thomas Gossmann
*/
class Set extends AbstractList {
/**
* Creates a new Set
*
* @param array|Iterator $collection
*/
public function __construct(array|Iterator $collection = []) {
$this->add(...$collection);
}
/**
* Adds an element to that set
*
* @param mixed ...$elements
*
* @return $this
*/
public function add(mixed ...$elements): self {
/** @var mixed $element */
foreach ($elements as $element) {
if (!in_array($element, $this->array, true)) {
$this->array[$this->size()] = $element;
}
}
return $this;
}
}