3 ms·
Like SQL for nested maps in Clojureland. Neat. The DSL [ALL :a even?] does feel a tiny bit un-clojurey to me as well, maybe making it look like [:all :a even?
by sova 6y ago
Like SQL for nested maps in Clojureland. Neat. The DSL [ALL :a even?] does feel a tiny bit un-clojurey to me as well, maybe making it look like [:all :a even?] would make it clearer.
- escherize 6y agoWell, not sure about that exactly. Consider a map like: {:all {:a 2} :foo {:a 4}} Maybe namespaced keys would fit that usecase
- boxed 6y agoIn instar it's [* :a even?] which I think is prettier... being the author of instar :)
- tekacs 6y agoWell there’s a reason it’s like that — ALL is actually a value, not just a sentinel or keyword. It’s found at com.rpl.specter/ALL. Keywords don’t form a DSL in Specter, they just do keyword navigation into maps, the same way ‘0’ navigates into the first element of a list. This touches upon a really nice element of Specter, which is its pattern for reuse. Here’s a very real but deliberately simple example of using it: (def chat-threads {[“sova” “tekacs”] [{:text [“hey” “you there?”]} {:text [“line 1” “line 2”]}]}) (def ALL-TEXT [sr/ALL :text sr/ALL]) (defn text-for [chat] (sr/select [chat ALL-TEXT])) (def ALL-CHAT-TEXT [sr/MAP-VALS ALL-TEXT]) (text-for [“sova” “tekacs”]) ;=> [...] Here the navigator into a list, then the :text field and then the list is bottled simply by putting several navigators in a vector. Then, it can be used alongside other navigators in a first class fashion — [chat ALL-TEXT] is just a nested vector. :)