This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-03
Channels
- # admin-announcements (2)
- # arachne (1)
- # architecture (6)
- # boot (316)
- # cider (7)
- # cljsrn (7)
- # clojure (169)
- # clojure-argentina (3)
- # clojure-belgium (1)
- # clojure-canada (4)
- # clojure-india (1)
- # clojure-russia (39)
- # clojure-spec (27)
- # clojure-uk (55)
- # clojurescript (213)
- # css (1)
- # cursive (20)
- # datavis (2)
- # datomic (52)
- # devcards (3)
- # dirac (78)
- # emacs (20)
- # events (1)
- # funcool (3)
- # hoplon (15)
- # jobs-rus (2)
- # om (57)
- # onyx (82)
- # overtone (1)
- # re-frame (10)
- # reagent (1)
- # ring-swagger (46)
- # spacemacs (7)
- # specter (31)
- # spirituality-ethics (1)
- # sql (43)
- # test-check (1)
- # testing (4)
- # untangled (30)
(defnav KW-NS []
(select* [this kw next-fn]
(next-fn (namespace kw)))
(transform* [this kw next-fn]
(let [kw-name (name kw)
new-ns (next-fn (namespace kw))]
(keyword new-ns kw-name)
)))
(setval [ALL FIRST KW-NS] "user" {:a 1 :b 2 :c 3})
;; => {:user/a 1, :user/b 2, :user/c 3}
so KW-NS navigates to the namespace portion of a keyword
is it the defnav portion that you're asking about in particular?
there's two code paths, one for select and one for transform
select must call next-fn on the "navigated to value(s)"
in this case, it's just (next-fn (namespace kw))
@nathanmarz: what is next-fn in the example with setval?
it's the rest of the navigation + final transformation
so in this case next-fn will be (fn [v] "user")
if there was more navigation after KW-NS, it would be the transform* code paths for the subsequent navigators
@nathanmarz: specter takes constants and interprets it as a function?
setval is a thin wrapper around transform
(setval [ALL FIRST KW-NS] "user" {:a 1 :b 2 :c 3})
== (transform [ALL FIRST KW-NS] (fn [_] "user") {:a 1 :b 2 :c 3})
here's how two navigators get composed into one navigator: https://github.com/nathanmarz/specter/blob/master/src/clj/com/rpl/specter/impl.cljx#L345
that's the core of how specter works
your linear path of navigators becomes a single nested function
I think I'm getting it, but you could also have written: (transform [ALL FIRST] (fn [kw] (keyword "user" (name kw))))
right? but your example is more abstract
correct
much more reusable and composable
though finally dropping support for 1.6 as of specter 0.12.0
just need to do the work now of porting to cljc