This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-11
Channels
- # aleph (4)
- # beginners (68)
- # boot (21)
- # chestnut (1)
- # cljs-dev (72)
- # clojure (64)
- # clojure-austin (9)
- # clojure-dusseldorf (16)
- # clojure-gamedev (2)
- # clojure-italy (32)
- # clojure-russia (80)
- # clojure-spec (9)
- # clojure-uk (20)
- # clojurescript (105)
- # cursive (5)
- # data-science (5)
- # datomic (23)
- # defnpodcast (3)
- # emacs (22)
- # fulcro (2)
- # graphql (63)
- # hoplon (7)
- # lein-figwheel (17)
- # lumo (63)
- # mount (2)
- # nrepl (4)
- # off-topic (66)
- # om (6)
- # onyx (3)
- # portkey (54)
- # re-frame (12)
- # reagent (12)
- # specter (42)
- # uncomplicate (1)
- # unrepl (38)
- # vim (9)
- # yada (3)
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
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)
reaching in via a fixed keypath [:a :x :y :z]
is okay, but how to put the *
at the beginning...
(nav/transform [nav/MAP-VALS :exits nav/ALL :available] #(not %) {:foo {:exits [{:to :bar :available true}]} :bar {:exits [{:to :foo :available false}]}})
@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}}}}
@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)
@sandbags Well I’m glad things are working for you now. 😁
i think a key problem i have (I have something called Aphantasia) is I struggle to visualise what is going on in the navigators
@sandbags ah; sounds like there is room to develop a visualization app for navigators then! 🙂
@levitanong something a bit like http://rxmarbles.com/
I like http://www.learndatalogtoday.org/ - not really visualizable but good for grokking a DSL
@sandbags I'd never heard of aphantasia before, reading about it just blew my mind
had no idea that was something that could differ between people
a visualization is a good idea, I put some thoughts here https://github.com/nathanmarz/specter/issues/56#issuecomment-328519037
do you think that visualize-path
command would be helpful?
(Even for those of us without aphantasia) 🙂
Hadn't seen that issue, subscribing in case I can help...
comments and ideas are welcome on that issue
and contributions, of course
the specter wiki is in its own repository if anyone wants to contribute https://github.com/nathanmarz/specter-wiki
I’ll try to tackle this when I have some time. It could be an interesting opportunity to write an interactive doc
@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.
looks like almost everything added since 0.13.0
nthpath
, MAP-KEYS
, BEFORE-ELEM
, AFTER-ELEM
, NONE-ELEM
, NAME
, NAMESPACE
, map-key
, set-elem
, before-index
, index-nav
, INDEXED-VALS
plus eachnav
, the improvements to keypath
/`must`, and the extension of many navigators to work with strings
@nathanmarz Can you give an example of transforming with INDEXED-VALS?
@michaelwfogleman there's some examples in the tests https://github.com/nathanmarz/specter/blob/master/test/com/rpl/specter/core_test.cljc#L1620
@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
Thanks! 🙂 I mostly adapted the tests and docstrings
@michaelwfogleman merged it in, thanks!