Fork me on GitHub
#specter
<
2017-09-11
>
sandbags09:09:00

I'm not grokking navigators for maps. I have a map like {:a {:x {:y {:z ...}}} :b {:x {:y {:z ...}}} :c {:x {:y {:z ...}}}} and I want to transform the value of :z for all keys in the map :a, :b, :c etc... but every permutation I try gets me something along the lines of Error: Vector's key for assoc must be a number

sandbags09:09:41

i think the problem is about my root map being processed as a vector of key-pairs but i am finding it hard to understand what ids going on (it might help to understand that I do not visualise very well)

sandbags09:09:23

reaching in via a fixed keypath [:a :x :y :z] is okay, but how to put the * at the beginning...

sandbags11:09:15

hrmm... okay i'm not sure what i am doing differently now to earlier but:

sandbags11:09:31

(nav/transform [nav/MAP-VALS :exits nav/ALL :available] #(not %) {:foo {:exits [{:to :bar :available true}]} :bar {:exits [{:to :foo :available false}]}})

sandbags12:09:03

works and is, structurally, my use case

sandbags12:09:03

I will confess I am still feel quit uncertain about my use of these navigators

levitanong12:09:53

@sandbags this should work for the data structure you posted (transform [MAP-VALS :x :y :z] (fn [z] (* 2 z)) {:a {:x {:y {:z 2}}} :b {:x {:y {:z 3}}} :c {:x {:y {:z 4}}}}

sandbags12:09:53

@levitanong i may have been making some kind of transliteration mistake as that kind of approach didn't work when i tried it, but yes - thanks. And the example I posted about is my actual use case (structurally at least)

levitanong12:09:10

@sandbags Well I’m glad things are working for you now. 😁

sandbags12:09:25

yes, thanks for your help

sandbags12:09:49

i think a key problem i have (I have something called Aphantasia) is I struggle to visualise what is going on in the navigators

hmaurer12:09:14

@sandbags ah; sounds like there is room to develop a visualization app for navigators then! 🙂

sandbags12:09:34

or some kind of tutorial with some visualisations, yes

hmaurer12:09:43

yes, that’s what I meant

hmaurer12:09:51

an interactive tutorial

levitanong12:09:51

@hmaurer @sandbags Now there’s an idea. :thinking_face:

michaelwfogleman12:09:03

I like http://www.learndatalogtoday.org/ - not really visualizable but good for grokking a DSL

nathanmarz12:09:41

@sandbags I'd never heard of aphantasia before, reading about it just blew my mind

nathanmarz12:09:16

had no idea that was something that could differ between people

nathanmarz12:09:17

do you think that visualize-path command would be helpful?

michaelwfogleman12:09:41

(Even for those of us without aphantasia) 🙂

michaelwfogleman12:09:56

Hadn't seen that issue, subscribing in case I can help...

nathanmarz12:09:50

comments and ideas are welcome on that issue

nathanmarz13:09:12

and contributions, of course

nathanmarz13:09:37

the specter wiki is in its own repository if anyone wants to contribute https://github.com/nathanmarz/specter-wiki

hmaurer13:09:23

I’ll try to tackle this when I have some time. It could be an interesting opportunity to write an interactive doc

hmaurer13:09:43

good project to get my hands on ClojureScript 🙂

michaelwfogleman13:09:09

@nathanmarz Do you know off the top of your head which functions / macros etc. aren't documented or need more explanation? I'm happy to write explanations for the ones I understand.

nathanmarz13:09:45

looks like almost everything added since 0.13.0

nathanmarz13:09:45

nthpath, MAP-KEYS, BEFORE-ELEM, AFTER-ELEM, NONE-ELEM, NAME, NAMESPACE, map-key, set-elem, before-index, index-nav, INDEXED-VALS

nathanmarz13:09:28

plus eachnav, the improvements to keypath/`must`, and the extension of many navigators to work with strings

michaelwfogleman14:09:03

@nathanmarz Can you give an example of transforming with INDEXED-VALS?

michaelwfogleman15:09:13

@nathanmarz About to push a big pull request for the wiki, did almost everything you listed save for eachnav and the improvement to keypath/must, but also did pred= and co, and traversed

hmaurer17:09:22

that was fast

michaelwfogleman18:09:56

Thanks! 🙂 I mostly adapted the tests and docstrings