This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-07
Channels
- # aleph (11)
- # aws (8)
- # bangalore-clj (4)
- # beginners (32)
- # boot (48)
- # cider (2)
- # cljs-dev (57)
- # cljsrn (4)
- # clojars (22)
- # clojure (67)
- # clojure-argentina (2)
- # clojure-austin (9)
- # clojure-berlin (1)
- # clojure-brasil (15)
- # clojure-france (1)
- # clojure-italy (10)
- # clojure-russia (23)
- # clojure-spec (6)
- # clojure-uk (48)
- # clojurescript (143)
- # cursive (15)
- # datomic (30)
- # emacs (18)
- # hoplon (26)
- # instaparse (1)
- # leiningen (1)
- # om (21)
- # om-next (9)
- # parinfer (3)
- # pedestal (3)
- # planck (2)
- # re-frame (53)
- # reagent (4)
- # ring (5)
- # spacemacs (1)
- # specter (10)
- # sql (16)
- # untangled (19)
- # vim (11)
- # yada (2)
Hi, I'm new to specter, I'm very exciting about specter. And I'm trying to use it, does specter ship some features like threading macros? I want to use specter to do something following:
(->> {"20161106020" {:3010 {}
:3006 {:3 "3.10"
:1 "3.55"
:0 "18.00"}}
"20161106021" {:3010 {:3 "3.00"}
:3006 {:3 "2.00"}}}
(map (fn [kv]
(->> (peek kv)
(map (fn [kv1]
(count (peek kv1))))
(reduce +))))
(reduce *))
what I want is simplify this piece of code with specter. wonder if someone could give me an example.
appreciate for any help, thanks!@doglooksgood here's one way to do it with specter:
(defn sum [args] (reduce + args))
(reduce * (traverse [MAP-VALS (subselect MAP-VALS (view count)) (view sum)] data))
if there were a traversed
navigator builder along the lines of transformed
, you could do it like this:
(reduce * (traverse [MAP-VALS (traversed [MAP-VALS (view count)] +)] data))
the former (which currently works) does materialize some intermediate subsequences, while the latter would not, so the latter would be close to optimal efficiency
(defdynamicnav traversed
"Navigates to a view of the current value by transforming with a reduction over
the specified traversal."
[path reduce-fn]
(late-bound-nav [late (late-path path)
late-fn reduce-fn]
(select* [this structure next-fn]
(next-fn (reduce late-fn (compiled-traverse late structure))))
(transform* [this structure next-fn]
(next-fn (reduce late-fn (compiled-traverse late structure)))
)))
I'll add that to the next version
@nathanmarz is this you? http://rpl.com/
I haven't put up a website yet