This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-04
Channels
- # architecture (13)
- # bangalore-clj (1)
- # beginners (174)
- # boot (25)
- # cider (65)
- # cljs-dev (10)
- # cljsjs (4)
- # cljsrn (3)
- # clojure (169)
- # clojure-berlin (27)
- # clojure-brasil (32)
- # clojure-greece (3)
- # clojure-russia (31)
- # clojure-sg (4)
- # clojure-spec (6)
- # clojure-uk (74)
- # clojurescript (186)
- # code-reviews (5)
- # css (12)
- # cursive (17)
- # datascript (1)
- # datomic (45)
- # dirac (33)
- # funcool (42)
- # hoplon (25)
- # jobs (6)
- # jobs-discuss (114)
- # lambdaisland (6)
- # leiningen (1)
- # luminus (24)
- # off-topic (86)
- # om (13)
- # om-next (14)
- # onyx (75)
- # perun (2)
- # protorepl (19)
- # re-frame (2)
- # reagent (17)
- # ring-swagger (2)
- # rum (1)
- # slack-help (2)
- # specter (31)
- # test-check (5)
- # timbre (1)
- # untangled (34)
- # vim (8)
when you have a bunch of maps and you want to make all of the maps agree on a unit of measure you have to convert the value for one key to another and remove the old key like, [{:place "here" :degrees-celsius 32} {:place "there" :degrees-faren 100}]
you have to do something like (dissoc (assoc mymap :degrees-celsius (f->c (:degrees-faren mymap)) :degrees-faren))
you could split that out into a general function that takes a key and a conversion function and my implementation probably isn't very idiomatic, but I'm sure there is a way to do this in specter I just can't seem to quite get it
so something like
(= (depth-counter [:a [:b [:d] [:e]] [:c [:f]]])
[{:val :a :depth 0}
[{:val :b :depth 1}
[{:val :d :depth 2}]
[{:val :e :depth 2}]]
[{:val :c :depth 1}
[{:val :c :depth 2}]]])
looking at the readme I don’t see any immediate way to carry state when navigating, but I’m sure I just haven’t figured out how yet 🙂
@gdeer81 you could make a navigator that navigates to the k/v pair and replaces it with a new k/v pair
so something like (transform (kvpair :degrees-faren) (fn [[_ v]] [:degrees-celsius (k->c v)]))
@schmee yea you should be able to just collect nodes as you go, and then use the count of the collected values list to annotate the depth
(def data [:a [:b [:d] [:e]] [:c [:f]]])
(def TreeWalker
(recursive-path [] p
(stay-then-continue
VAL
(if-path vector?
[ALL p]))))
(transform [TreeWalker (complement vector?)]
(fn [& vals]
{:depth (- (count vals) 2)
:val (last vals)})
data)
so the naming convention is unparameterized navigators are in all caps else it follows regular function naming conventions?
I’m just trying out Specter for the first time and this stuff is blowing my mind already!
thanks
zippers are still useful but not for the majority of use cases
(zippers are integrated with specter in com.rpl.specter.zipper)
am I correct in thinking that recursive-path
is just a shorthand for declarepath + providepath?
https://github.com/nathanmarz/specter/blob/master/src/clj/com/rpl/specter.cljc#L80
local-declarepath
+ providepath
@nathanmarz if I write this kvpair navigator do you think it would be useful to add to specter or is it too specific to this one use case? I remember you saying in your talk that most of the functionality that is in specter is from your specific needs so
@gdeer81 doesn't seem common enough to add to the core
okay then I guess it will just end up in a gist and if someone needs it, it will show up in their google results 😆
Okay, so specter is good for ETL, but what about analytics? like {:usa-census [{:state "Texas" :population 20000000} {:state "California" :population 40000000} ...}] :mexico-census [{:state "Coahuila" :population 200000} {:state "Mexico City" :population 20000000} ...]}
transformed into {:us-total-pop 3241118787 :mexico-total-pop 128632004 ...}
that's outside the scope of specter