Fork me on GitHub
#specter
<
2016-06-21
>
josh.freckleton21:06:48

@nathanmarz: Thanks for inviting me to specter, I think it's brilliant to have this sort of DSL for navigation, and I'm excited for this lib to transform my workflow! In our conversation yesterday (on #C03S1KBA2) I was talking about needing to post-order traverse a tree. I think I can see how I'd piece that together using specter, but I see talk toward the end of the readme about navigating graphs. What is the best practice if I wanted to post-order traverse a tree?

lellis21:06:08

Hello guys! I made a sort using sorted-map-by then i use into these specter:

(transform (walker (fn [v] (and (keyword? v)))) #(keyword (clojure.string/replace (subs (str %) 1) "/" "_")) sorted-map)
But because inner specter use walker and walker says "Note: "walk" supports all Clojure data structures EXCEPT maps created with sorted-map-by. There is no (obvious) way to retrieve the sorting function." Is there another way to do that with specter?

lellis21:06:27

Or is better make my sort without sorted-map-by?

nathanmarz22:06:31

@josh.freckleton: do you mean best practice if you wanted to post-order traverse a graph?

josh.freckleton22:06:06

@nathanmarz: yes, that would be awesome! I don't quite get recursion, or ordering yet in specter

nathanmarz22:06:34

so internally I have a bunch of navigators built on top of loom

nathanmarz22:06:49

so I can do things like (transform [REVERSE-TOPSORT ...] ...)

nathanmarz22:06:05

where reverse-topsort navigates to pairs of [graph, node-id] in reverse topological order

nathanmarz22:06:49

at the end of my clojure/west talk I showed a complete example of my specter/loom integration

nathanmarz22:06:08

trying to encourage someone from the community to build an open-source version

aengelberg22:06:38

That's odd that clojure.walk/walk claims to not work with sorted-map-by. I just tried it in the REPL and it seems to work fine.

nathanmarz22:06:30

hmm, didn't even know about sorted-map-by

nathanmarz22:06:44

looks like ALL and MAP-VALS are broken with that, but walker does seem to work

josh.freckleton22:06:47

@nathanmarz: ah, it wasn't clear you were using loom at the end of that talk. Fantastic talk though! Would you by chance have a gist I could study?

aengelberg22:06:02

Do priority maps work with ALL?

lellis23:06:08

I make some code for example:

(def demo-map {:a "baa" :b "aab"})

(def demo-map-sorted-by-value (into (sorted-map-by (fn [key1 key2]
                                                     (compare
                                                       [(get demo-map key1) key1]
                                                       [(get demo-map key2) key2]))) demo-map))

(def result (transform (walker (fn [v] (and (keyword? v)))) #(keyword (clojure.string/replace (subs (str %) 1) "a" "c")) demo-map-sorted-by-value))

demo-map => {:a "baa", :b "aab"}
demo-map-sorted-by-value => {:b "aab", :a "baa"}
result => {:c "baa", :b "aab”}

The question is: Why i lost my sort by value?