-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need a way get a dereferenced copy from a reference #2803
Comments
An example use-case is |
Important to prevent regressions + Quality-of life improvement for Stable Cadence |
I think this is only needed when accession container types (or structs) inside container types. Maybe adding a let elementRef = dictionaryRef[key]
let elementCopy = elementRef.copy() |
I personally prefer a different name other than But a good point on that this could be a method on the value ( |
yeah copy/clone has that meaning, you are right @SupunS . My concern was if we make it global, people will try to use it on all kind of references. ( maybe |
That would be no harm, correct? e.g: dereferencing an |
Yeah I was more thinking in line with dereferencing resources etc. That's why I think some generic |
oh yes, you are correct, it definitely has to be supported only for the subtypes of |
Issue to be solved
Sometimes it is useful to be able to get a dereferenced-copy from a reference.
For e.g. assume a large dictionary is in storage, and one would need to get a copy of just one entry of that dictionary. In the latest released version, this is possible by:
dictionaryRef
)dictionaryRef[key]
, which would return a copy of the value at thekey
.However, with stable cadence, given the index syntax
dictionaryRef[key]
also returns another reference, the above approach no longer works. Instead, they would need todictionaryCopy
)dictionaryCopy[key]
.The downside of this is now they would need to copy the entire outer dictionary which could be a very expensive operation.
Suggested Solution
It would be nice to have a way to get a dereferenced copy from a reference (say a built-in method
dereference()
), so that they can get a copy from the reference itself.i.e:
Some suggestions for the name of the built-in method:
dereference()
dereferenceCopy()
*
), but I personally prefer one of the above, because they are verbose.The text was updated successfully, but these errors were encountered: