3 ms·
I like Specter, but it doesn't quite give me the holy grail it promises. My main pain-point is that it assumes I know the route to the datapoint I want to chang
by OliverM 11y ago
I like Specter, but it doesn't quite give me the holy grail it promises. My main pain-point is that it assumes I know the route to the datapoint I want to change. What if all I know is the general shape of a subset of data, and also that that shape might appear none or more times in my client dataset?
I'd love to be able to describe features of a data structure and have all qualifying elements be transformed, without my having to tell the select function how to get to those data structures in the first place; just hand it a data structure, and have it grovel through looking for matching subsets, then transforming them as desired.
Sort of like a grammar/DSL for Clojure data structures, without having to be specified from the basic character level up.
- nathanmarz 11y agoIt sounds like you're looking for the "walk" selector, which comes with Specter: (select (walker number?) {2 [1 2 [6 7]] :a 4 :c {:a 1 :d [2 nil]}}) => [2 1 2 1 2 6 7 4] I've personally found this to be a use case that comes up infrequently.
- tel 11y agoWalk shows up quite often in the "uniplate" functionality of Haskell's `lens`. It's really, really useful for handling AST transformations, but depends a bit on laziness here.
- OliverM 11y agoI'm doing a lot of tree transformation stuff at the moment where it comes up a fair bit. Thanks for the pointer, I'll give it a try.