News for hackers. Stuff that matters.
Re:Functional-navigational programming in Clojure with Specter by OliverM on Tuesday September 29, 2015 @10:54AM (#10296734)
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.

Re:Functional-navigational programming in Clojure with Specter by nathanmarz on Tuesday September 29, 2015 @11:50AM (#10297158)
It 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.

Re:Functional-navigational programming in Clojure with Specter by tel on Tuesday September 29, 2015 @12:15PM (#10297356)
Walk 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.
Re:Functional-navigational programming in Clojure with Specter by OliverM on Tuesday September 29, 2015 @12:29PM (#10297448)
I'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.