Closed RPallas92 closed 6 years ago
Thank you for the PR! I didn't rule out lenses, optics or something like that for prelude, but so far I couldn't think of a simple way to implement something like that that seemed to be worth being bundled in (as compared to encouraging to use an external solution) while being small.
immutablejs recently added something allowing to solve similar problems than optics -- this is very small and it's also useful, but I think it's not type-safe (though it could possibly be made type-safe I guess) and for now I didn't think this makes sense in prelude.ts.
Looking at your PR, it seems what you implemented so far is a little part of what is needed for it to be useful in the end. It will grow and in the end maybe it would better be suited to a separate library, not sure how much it'll grow, it's hard to assess the scope right now. For instance I'm not sure whether it'll be possible to compose optics.
Currently with ES6 we have object spreads, which solves the problem at the level of a single value, but the problem we still have are nested updates. Currently I don't see clearly how your DSL handles that (presumably it will through optics composition).
But in the end, even if you solve composition & object nesting, I would have to review existing solutions to decide whether it makes sense to include your work in prelude.ts or whether it makes more sense in an external library.
Thanks for the response. I will try to solve composition and object nesting and then I will create a separate lib from now. Then you can decide if it makes sense to include it in prelude or not.
Thanks!
Good plan, I wish you the best of luck with this project!
Following the library's philosophy of simplicity, I have added a Optics DSL without the overhead that is type-safe and easy to use.
Please check tests/Optics.ts to see how it works.
I will add a
set
function that returns a new object with the property modified.Does this PR make sense? @emmanueltouzery