Copy a set.
If a deep value higher than 0
(default) is used, then this function will create copies of the things within the set.
This function does not generate a change.
set.copy([deep]])
Argument | Type | Description |
---|---|---|
deep | int (optional) | How deep to copy things withing the set. Default is 0 (only a copy of the set, not the things within the set). |
A new set.
This code shows an example using copy():
x = {x: 123};
a = set(x);
b = a.copy();
// both `a` and `b` have thing `x`
assert ( a.has(x) );
assert ( b.has(x) );
// `b` is a copy, so when changing `a`, set `b` remains unaffected.
a.clear();
b;
Return value in JSON format
[
{
"x": 123
}
]
Note that a copy with a deep value can create copies of things but the Type information will be lost:
set_type('Person', {
name: 'str'
});
p = Person{
name: 'Foo'
};
s = set(p);
// deep 1 will not only copy the set, but also the things within the set
o = s.copy(1);
// the new set `o` does not have `p` since a copy of `p` is created
assert ( o.has(p) == false );
// copy does not preserve the Type information, the Type for each member is now a normal thing:
o.map(|t| type(t));
Return value in JSON format
[
"thing"
]