Comments (4)
Yes, I think we can have this. I don't love the options we have for the signature though:
modify(f, optic, objs...) # clashes with existing modify(f, obj, optic)
modify(f, obj1, optic, objs...) # a bit ugly to have the optic in between
modify(f, objs..., optic) # a bit cumbersome for dispatch
Alternative we could use a new function for this.
from accessors.jl.
Note that obj1
and objs
are not fully symmetric in such a function, they cannot in general be swapped.
In particular, obj1
should always define the resulting type. For Properties()
, it defines what property names are used (others in objs
should be ignored). For Recursive
, obj1
should define the whole resulting structure. Etc.
So there's probably nothing too wrong with the modify(f, obj1, optic, objs...)
signature: it highlights the special role of obj1
. Basically, it's regular 1-obj modify(), plus extra objects added at the end.
Another bonus is that it's easy to support 1-arg and multi-arg modify with exact same code in many cases. Like, in https://gitlab.com/aplavin/AccessorsExtra.jl/-/blob/master/src/modifymany.jl#L16-19 we can replace B
and b
with B...
and b...
, getting both 1- and multi-arg modify() as one method.
from accessors.jl.
That is a good point, now I am more happy with the signature modify(f, obj, optic, objs...)
.
from accessors.jl.
After some usage I quite like it, and may make a PR here soon :)
The one inconvenience I noticed is:
julia> obj = (name="A", values=(red=1, blue=2))
julia> sensitivities = (red=2, green=4, blue=3)
# want to modify obj.values according to sensitivities
# seems straightforward?..
julia> modify(/, obj.values, ∗ₚ, sensitivities)
(red = 0.5, blue = 0.6666666666666666)
# ... but if I want the full obj back, I need manually nested modify calls:
julia> @modify(obj.values) do values
modify(/, values, ∗ₚ, sensitivities)
end
(name = "A", values = (red = 0.5, blue = 0.6666666666666666))
Some kind of "focusing" optic would seem useful here, but I'm curious what you think about this.
from accessors.jl.
Related Issues (20)
- "Concat lens": combine multiple lenses side by side HOT 7
- Assemble an object from optics HOT 7
- `hasproperty()` analogue for optics HOT 3
- IndexLens and changing the container size HOT 3
- `Base.show` ambiguity
- @reset naming convention HOT 4
- fate of insert and delete after these functions get into Base
- How to @reset when the field is known only by its equivalent symbol. HOT 2
- Only a single function argument can be the optic target HOT 3
- [Feature request] Set multiple fields at once HOT 6
- Errors in extensions during precompilation HOT 5
- `set` for `StructArray`
- Bad idea, would avoid using this pkg HOT 14
- To be or not to be HOT 3
- Traversal order of `Recursive` HOT 11
- `==` not defined for `IndexLens` HOT 4
- String properties not supported HOT 3
- Tests fail on 1.11 HOT 2
- `@(re)set` very slow when a parametric inner constructor is defined? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from accessors.jl.