-
Notifications
You must be signed in to change notification settings - Fork 20
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
Use with mutable arrays? #18
Comments
Personally I usually do v1 = v[1]
v[1] = @set v1.x = 5 Alternatives would be to use Persistent Arrays for efficient immutable updates of arrays. It should be easy to support FunctionalCollections with Accessors but it is not yet implemented I think. Or defining a custom lens that is allowed to do mutation. If you want to work on one of these, I am happy to help. |
Thank you for the response and tip. Right now I'm working on some other personal projects so unfortunately it's unlikely I'll open a PR. |
Sure no problem! |
Try the julia> @set v |> view(_, 1)[].x = 5
2-element Vector{MyT}:
MyT(5)
MyT(2)
julia> v
2-element Vector{MyT}:
MyT(5)
MyT(2) Suggestions for a cleaner approach that doesn't introduce new structs (for the user to learn) are welcome! |
If one has a mutable array of immutable objects, is it possible to use Accessors.jl to update just one object in the array without copying the whole array?
Looks like
@set
is returning a whole copy ofv
, not just updatingv[1]
. Is that right? Is there a way around this?The text was updated successfully, but these errors were encountered: