|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Innmind\Immutable; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Set of unique elements in a non deterministic order |
|
8
|
|
|
*/ |
|
9
|
|
|
interface SetInterface extends SizeableInterface, PrimitiveInterface, \Countable, \Iterator |
|
10
|
|
|
{ |
|
11
|
|
|
public function __construct(string $type); |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Return the type of this set |
|
15
|
|
|
* |
|
16
|
|
|
* @return StringPrimitive |
|
17
|
|
|
*/ |
|
18
|
|
|
public function type(): StringPrimitive; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Intersect this set with the given one |
|
22
|
|
|
* |
|
23
|
|
|
* @param self $set |
|
24
|
|
|
* |
|
25
|
|
|
* @throws InvalidArgumentException If the sets are not of the same type |
|
26
|
|
|
* |
|
27
|
|
|
* @return self |
|
28
|
|
|
*/ |
|
29
|
|
|
public function intersect(self $set): self; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Add a element to the set |
|
33
|
|
|
* |
|
34
|
|
|
* @param mixed $element |
|
35
|
|
|
* |
|
36
|
|
|
* @return self |
|
37
|
|
|
*/ |
|
38
|
|
|
public function add($element): self; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Check if the set contains the given element |
|
42
|
|
|
* |
|
43
|
|
|
* @param mixed $element |
|
44
|
|
|
* |
|
45
|
|
|
* @return bool |
|
46
|
|
|
*/ |
|
47
|
|
|
public function contains($element): bool; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Remove the element from the set |
|
51
|
|
|
* |
|
52
|
|
|
* @param mixed $element |
|
53
|
|
|
* |
|
54
|
|
|
* @return self |
|
55
|
|
|
*/ |
|
56
|
|
|
public function remove($element): self; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Return the diff between this set and the given one |
|
60
|
|
|
* |
|
61
|
|
|
* @param self $set |
|
62
|
|
|
* |
|
63
|
|
|
* @return self |
|
64
|
|
|
*/ |
|
65
|
|
|
public function diff(self $set): self; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Check if the given set is identical to this one |
|
69
|
|
|
* |
|
70
|
|
|
* @param self $set |
|
71
|
|
|
* |
|
72
|
|
|
* @return bool |
|
73
|
|
|
*/ |
|
74
|
|
|
public function equals(self $set): bool; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Return all elements that satisfy the given predicate |
|
78
|
|
|
* |
|
79
|
|
|
* @param \Closure $predicate |
|
80
|
|
|
* |
|
81
|
|
|
* @return self |
|
82
|
|
|
*/ |
|
83
|
|
|
public function filter(\Closure $predicate): self; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Apply the given function to all elements of the set |
|
87
|
|
|
* |
|
88
|
|
|
* @param \Closure $function |
|
89
|
|
|
* |
|
90
|
|
|
* @return self |
|
91
|
|
|
*/ |
|
92
|
|
|
public function foreach(\Closure $function): self; |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Return a new map of pairs grouped by keys determined with the given |
|
96
|
|
|
* discriminator function |
|
97
|
|
|
* |
|
98
|
|
|
* @param \Closure $discriminator |
|
99
|
|
|
* |
|
100
|
|
|
* @return MapInterface |
|
101
|
|
|
*/ |
|
102
|
|
|
public function groupBy(\Closure $discriminator): MapInterface; |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Return a new set by applying the given function to all elements |
|
106
|
|
|
* |
|
107
|
|
|
* @param \Closure $function |
|
108
|
|
|
* |
|
109
|
|
|
* @return self |
|
110
|
|
|
*/ |
|
111
|
|
|
public function map(\Closure $function): self; |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Return a sequence of 2 sets partitioned according to the given predicate |
|
115
|
|
|
* |
|
116
|
|
|
* @param \Closure $predicate |
|
117
|
|
|
* |
|
118
|
|
|
* @return MapInterface<bool, self> |
|
|
|
|
|
|
119
|
|
|
*/ |
|
120
|
|
|
public function partition(\Closure $predicate): MapInterface; |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Concatenate all elements with the given separator |
|
124
|
|
|
* |
|
125
|
|
|
* @param string $separator |
|
126
|
|
|
* |
|
127
|
|
|
* @return StringPrimitive |
|
128
|
|
|
*/ |
|
129
|
|
|
public function join(string $separator): StringPrimitive; |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Return a sequence sorted with the given function |
|
133
|
|
|
* |
|
134
|
|
|
* @param \Closure $function |
|
135
|
|
|
* |
|
136
|
|
|
* @return SequenceInterface |
|
137
|
|
|
*/ |
|
138
|
|
|
public function sort(\Closure $function): SequenceInterface; |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Create a new set with elements of both sets |
|
142
|
|
|
* |
|
143
|
|
|
* @param self $set |
|
144
|
|
|
* |
|
145
|
|
|
* @return self |
|
146
|
|
|
*/ |
|
147
|
|
|
public function merge(self $set): self; |
|
148
|
|
|
} |
|
149
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.