vvvvalvalval / supdate

Clojure's update with superpowers.
https://vvvvalvalval.github.io/supdate/
MIT License
204 stars 4 forks source link

Consider: Transformation is open for extension #5

Open ohpauleez opened 5 years ago

ohpauleez commented 5 years ago

Currently, transformation is closed for extension, with all the rules for transformation being captured in a cond. Consider introducing a protocol with a single protocol-function (-transform [this source-obj args]) which gets called in place of the exception within the else or in a clause before checking for satisfies?. This would allow users to define new forms of transformation which may be domain specific or are more optimized for their source-obj.

vvvvalvalval commented 5 years ago

Yeah I've considered it, I'm just not sure it's worthwhile and I'm being conservative in what features I add.

Consider that:

  1. when you reach this point, maybe it's time you reach out for a more expressive transformation lib like Specter;
  2. any 1-argument function is a valid transformation, and transformations can be combined, so you always have that escape hatch.
  3. opening for extension also means more cases to consider when programmatically manipulating transforms.

I might reconsider at some point, so feel free to post examples of use cases justifying the suggested approach.