This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-07
Channels
- # aleph (15)
- # beginners (18)
- # boot (18)
- # business (1)
- # cider (11)
- # cljs-dev (13)
- # cljsrn (19)
- # clojure (14)
- # clojure-austin (8)
- # clojure-dusseldorf (1)
- # clojure-finland (1)
- # clojure-greece (118)
- # clojure-poland (3)
- # clojure-russia (46)
- # clojure-spec (65)
- # clojure-uk (18)
- # clojurebridge (3)
- # clojurescript (16)
- # cloverage (7)
- # core-async (8)
- # cursive (74)
- # datomic (28)
- # editors (3)
- # emacs (3)
- # ethereum (5)
- # hoplon (19)
- # jobs-rus (18)
- # lein-figwheel (1)
- # off-topic (2)
- # om (107)
- # om-next (4)
- # onyx (23)
- # pedestal (23)
- # proton (3)
- # protorepl (1)
- # re-frame (108)
- # reagent (10)
- # ring-swagger (15)
- # spacemacs (2)
- # specter (11)
- # testing (7)
- # untangled (79)
- # vim (4)
- # yada (53)
@nlessa what do you mean by "most profound"?
hi @nathanmarz. I mean: navigating continuously in the hierarchy by the :c key, get the last :c you navigated and the get the value of :a 3 examples:
{:a 1 :b: 1 :c {:a 2 :d 2 :c {:a 3 :b 3 :c {:a 4 :h 4}}}} => 4
{:a 1 :b 1 :c: {:a 2 :d 2 :f {:a 3 :b 3 :c {:a 4 :h 4} }}}} => 2
{:a 1 :b: 1 :j {:a 2 :d 2 :c {:a 3 :b 3 :c {:a 4 :h 4}}}} => 1
Is it clear?@nlessa you can do something like this with 0.12.0
(declarepath LastCMap)
(providepath LastCMap
(if-path (must :c)
[:c LastCMap]
STAY
))
(select-any [LastCMap :a] data)
though I really recommend using 0.13.0, which is much better at things like this
in 0.13.0 you can do it like this:
(def LastMap
(recursive-path [k] p
(if-path (must k)
[(keypath k) p]
STAY)))
(select-any [(LastMap :c) :a] data)
Thank you very much, @nathanmarz. Specter is really great, very elegant! When we see the solution it seems obvious. 🙂 I am yet struggling to dominate all the navigators logic and solve some problems in the specter-way.
you'll get there, it just takes practice
and a certain amount of retraining on how you think about data structures
is a transformation from [[:a :b] [:a :c] [:b :d] [:c :d]]
to {:a [:b :c], :b [:d], :c [:d]}
something that Specter is designed for? Not sure if that should be a transform
or a setval
or something else...
@aaelony the target object doesn't really share any structure with the source, so I would just do that with regular clojure functions
perfect, thanks @nathanmarz