SetMut
Bases: PyoMutableSet[T]
flowchart TD
pyochain._set.SetMut[SetMut]
pyochain.abc._set.PyoMutableSet[PyoMutableSet]
pyochain.abc._set.PyoSet[PyoSet]
pyochain.abc._collection.PyoCollection[PyoCollection]
pyochain.abc._iterable.PyoIterable[PyoIterable]
pyochain.rs.Pipeable[Pipeable]
pyochain.rs.Into[Into]
pyochain.rs.Inspect[Inspect]
pyochain.rs.Checkable[Checkable]
pyochain.abc._collection.PyoContainer[PyoContainer]
pyochain.abc._collection.PyoSized[PyoSized]
pyochain.abc._set.PyoMutableSet --> pyochain._set.SetMut
pyochain.abc._set.PyoSet --> pyochain.abc._set.PyoMutableSet
pyochain.abc._collection.PyoCollection --> pyochain.abc._set.PyoSet
pyochain.abc._iterable.PyoIterable --> pyochain.abc._collection.PyoCollection
pyochain.rs.Pipeable --> pyochain.abc._iterable.PyoIterable
pyochain.rs.Into --> pyochain.rs.Pipeable
pyochain.rs.Inspect --> pyochain.rs.Pipeable
pyochain.rs.Checkable --> pyochain.abc._iterable.PyoIterable
pyochain.abc._collection.PyoContainer --> pyochain.abc._collection.PyoCollection
pyochain.abc._collection.PyoSized --> pyochain.abc._collection.PyoCollection
click pyochain._set.SetMut href "" "pyochain._set.SetMut"
click pyochain.abc._set.PyoMutableSet href "" "pyochain.abc._set.PyoMutableSet"
click pyochain.abc._set.PyoSet href "" "pyochain.abc._set.PyoSet"
click pyochain.abc._collection.PyoCollection href "" "pyochain.abc._collection.PyoCollection"
click pyochain.abc._iterable.PyoIterable href "" "pyochain.abc._iterable.PyoIterable"
click pyochain.rs.Pipeable href "" "pyochain.rs.Pipeable"
click pyochain.rs.Into href "" "pyochain.rs.Into"
click pyochain.rs.Inspect href "" "pyochain.rs.Inspect"
click pyochain.rs.Checkable href "" "pyochain.rs.Checkable"
click pyochain.abc._collection.PyoContainer href "" "pyochain.abc._collection.PyoContainer"
click pyochain.abc._collection.PyoSized href "" "pyochain.abc._collection.PyoSized"
A mutable, unordered collection of unique elements.
Unlike Set which is immutable, SetMut allows in-place modification of elements.
Implement the collections::abc::MutableSet interface, so elements can be modified in place, and passed to any function/object expecting a standard mutable set.
Underlying data structure is a set.
Tip
If you have an existing set, consider using SetMut::from_ref to avoid unnecessary copying.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[T]
|
Any |
required |
Source code in src/pyochain/_set.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
inner
property
Get the underlying set data structure.
Useful when interoperating with functions that require a standard Python set.
Returns:
| Type | Description |
|---|---|
set[T]
|
set[T]: The underlying set. |
add(value)
Add an element to self.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
The element to add. |
required |
Example
>>> from pyochain import SetMut
>>> s = SetMut(("a", "b"))
>>> s.add("c")
>>> s.iter().sort()
Vec('a', 'b', 'c')
Source code in src/pyochain/_set.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
discard(value)
Remove an element from self if it is a member.
Unlike [SetMut::remove][remove], this method does not raise an exception when an element is missing from the set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
The element to remove. |
required |
Example
>>> from pyochain import SetMut
>>> s = SetMut(("a", "b", "c"))
>>> s.discard("b")
>>> s.iter().sort()
Vec('a', 'c')
Source code in src/pyochain/_set.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
from_ref(data)
staticmethod
Create a SetMut from a reference to an existing set.
This method wraps the provided set without copying it, allowing for efficient object instanciation.
This is the recommended way to create a SetMut from foreign functions that return set objects.
Warning
Since the SetMut directly references the original set, any modifications made to the SetMut will also affect the original set, and vice versa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
set[V]
|
The |
required |
Returns:
| Type | Description |
|---|---|
SetMut[V]
|
SetMut[V]: A new |
Example
>>> from pyochain import SetMut
>>> original_set = {1, 2, 3}
>>> set_obj = SetMut.from_ref(original_set)
>>> set_obj
SetMut(1, 2, 3)
>>> original_set.add(4)
>>> set_obj
SetMut(1, 2, 3, 4)
Source code in src/pyochain/_set.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |