-
Notifications
You must be signed in to change notification settings - Fork 19
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
insert not working for stucts? #81
Comments
What would you expect it to return? For namedtuples, the result is obvious: a namedtuple with one more field added. For structs - not so much... |
Fair enough. I was thinking that it would create a modified struct... something along the lines of:
As with a named tuple, it would add in the field to the struct. |
Creating a new struct efficiently is impossible from within a function, I think. And anyway, what's the usecase for this? The new struct would bear no relation to the original one, no methods defined for original Remember, |
Right. I have a scenario where there are nested structs. Buried within the nested structs are some optional extension fields that may or not exist at time of creation. Long story short, structs are created based on known fields however additional extension fields need to be added in at a later time. I was hoping I could use Accessors to insert the optional fields into the existing struct instances. As you said, Acccessors is convenient and a potential three-liner is much more appealing than iterating/unpacking existing struct for modification. |
Yeah, thats just not possible in julia, you can't modify a struct. That's one reason julia can be fast vs e.g. Python, structs are basically C structs, not dictionaries. But if you want the flexibility of a |
Well, the point of Accessors is to update/modify immutable types? Right? It's advertised as such for NamedTupes and "arbitrary structs and nested updates" per documentation. There are examples where immutable structs are modified. In interpreting the responses, is it fair to say that Accessors can update/modify structs but not "insert" or add fields. If so, perhaps make a clarifying remark(s) in the documentation? |
While I'm able to insert using named tuples, it doesn't seem to work for structs?
The text was updated successfully, but these errors were encountered: