This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-19
Channels
- # bangalore-clj (35)
- # beginners (42)
- # boot (89)
- # cider (9)
- # clara (2)
- # cljs-dev (29)
- # cljsjs (3)
- # cljsrn (14)
- # clojars (9)
- # clojure (332)
- # clojure-brasil (1)
- # clojure-dev (5)
- # clojure-italy (4)
- # clojure-russia (36)
- # clojure-spec (38)
- # clojure-uk (65)
- # clojurescript (114)
- # clr (11)
- # community-development (105)
- # core-async (10)
- # cursive (4)
- # datascript (1)
- # datomic (58)
- # defnpodcast (3)
- # emacs (4)
- # hoplon (7)
- # juxt (3)
- # keechma (8)
- # off-topic (7)
- # om (109)
- # om-next (8)
- # onyx (26)
- # pedestal (3)
- # planck (8)
- # re-frame (76)
- # reagent (28)
- # rum (25)
- # spacemacs (2)
- # specter (35)
- # untangled (31)
- # yada (27)
what is the idiomatic way in Specter to do the following:
(mapv (fn [x] {:name x}) (->> [[:a :b][:b :c][:c :d][:c :e]] flatten set vec ))
=> [{:name :e} {:name :c} {:name :b} {:name :d} {:name :a}]
i am trying to add to a list inside a map of maps if the if the id matches. my code looks like that: (def same-id? (specter/comp-paths (specter/paramsfn [id-key id] [item] (= id (get item id-key)))))
(specter/select [specter/ALL same-id? (:entity-id entity) (:entity-val entity)] db)
i know the actual transform is missing, but i have a feeling i missunderstood how to use specter
can you give an example of input/output?
@aaelony that's an aggregation producing a brand new data structure construction, so Specter won't be any better than transducers for that case
@aaelony but this is an efficient way to do it:
(->> [[:a :b][:b :c][:c :d][:c :e]]
(traverse [ALL ALL])
(into #{})
(into [] (map (fn [k] {:name k}))))
entity = {:entity-id :advisory-id :entity-val :"2016-1425"} db = {:advisories {:list {:advisory-id "2016-1623" :cvss {:c 1 :d 2 :e 3} :tags ({:tag-key "test-tag" :tag-value nil} {:tag-key "test-tag-2" :tag-value 12})}}}
at the moment i don't get any output because i cannot locate paramsfn
what i want to do is, append a tag to tags inside advisory inside the advisories list if the id matches
entity id
@dev-hartmann looking for expected input/output
paramsfn
was removed in 0.13.0 because it's no longer necessary
expected output is the updated db map
input is entity map like above and a tag {:tag-key "something" :tag-value "optional"}
I don't know what you mean, so I need a specific minimal example of input/output in order to help you
(transform [(filterer #( = (:entity-val entity) (:entity-id %))) ALL] #(conj (:tags %) tag) db)]
that's what i am trying at the moment, with the data from above
as a result i get the unchanged map
@dev-hartmann a specific minimal example is something like [1 2 3]
=> [2 3 4]
ah ok, sry, did not understand -.-
{:entity-id :item-id :entity-val 1}
{:tag-key "test2" :tag-value "2"}
{:items {:item-id 1 :sub-items ({:tag-key :tag "value"} {:tag-key "tag2" "value2"} {:tag-key "tag3" "value1"})}
{:item-id 2 :sub-items ({:tag-key "tag1" "value"})}}
-> {:items {:item-id 1 :sub-items ({:tag-key :tag "value"} {:tag-key :tag2 "value2"} {:tag-key :tag3 "value1"})}
{:item-id 2 :sub-items ({:tag-key "tag-test" "value"} {:tag-key "test2" :tag-value "2"})}}
like that?
do you mean for value of :items to be in a list of some sort?
oh yes, sry
it's a list
and here you have the append going to subitems of item id 2, but your input says entity-val 1
my brain is full on monday, sry again, entity-val should be 2
one way to do it: (setval [:items ALL #(= (get % (:entity-id entity)) (:entity-val entity)) :sub-items END] [tag] db)
thank you very much, seeing your answer explains how i got the way the path is created all wrong. thanks again
I would also suggest using vectors instead of lists for sub-items, as appending to a vector is much more efficient
that makes sense, thanks for the advice
thanks, @nathanmarz