Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Specter is fantastic. It makes transformations on deeply nested data structures easy. Want to transform all the "datetimes" from JSON data into actual datetimes (or vice versa)? It takes about five minutes if you have to look everything up. Works with ClojureScript too.

Some production code:

    (defn transform-tagged-values [x]
      (sp/transform (sp/walker tr/tagged-value?) tagged-value->cljs x))
Give it a predicate for which values to transform, and a function to do the transformation. Couldn't be easier.


It really does remove multiple layers of complexity that usually stand between your mental model of what your transformation function should do and the code that actually implements it. With Specter if I can clearly articulate the transformation I want to do on a data structure, then I can almost always translate that one-to-one into the code that does the transformation.

When I started using it in one of my existing projects I was able to completely eliminate a few needlessly long and complex functions that were littered with comments and calls to helper functions. In their place are functions that are about 5 lines of code that barely even need a docstring because it's readily apparent what they do just by looking at the source.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: