This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-30
Channels
- # announcements (15)
- # beginners (143)
- # boot (2)
- # calva (48)
- # cider (93)
- # cljsrn (2)
- # clojure (127)
- # clojure-europe (3)
- # clojure-italy (8)
- # clojure-losangeles (8)
- # clojure-nl (10)
- # clojure-spec (67)
- # clojure-uk (51)
- # clojurescript (20)
- # cursive (9)
- # data-science (2)
- # datomic (10)
- # duct (13)
- # figwheel-main (1)
- # fulcro (74)
- # instaparse (10)
- # jobs (3)
- # joker (8)
- # juxt (4)
- # lumo (1)
- # malli (11)
- # nrepl (3)
- # off-topic (4)
- # pathom (5)
- # pedestal (6)
- # planck (5)
- # re-frame (18)
- # reagent (5)
- # reitit (17)
- # shadow-cljs (165)
- # sql (30)
- # vim (12)
- # xtdb (6)
So I have this mutation:
(pc/defmutation add-artifact [env artifact]
{::pc/sym `r9b.threat-intelligence.artifact/add-artifact
::pc/params [::note ::hash/sha-256]
::pc/output [:artifact/note]}
...)
How can I access the params? I've noticed that there can be any keys inside artifact
and I want to remove all those that are not in the ::pc/params
so that I can then reduce over artifact to do something meaningful. Is that possible?@brian.rogers hello, one way to do it is writing a ::pc/transform
, using that you can wrap the mutation fn and do anything you want (like stripping params), a example:
(defn filter-declared-params-transform
[{::pc/keys [mutate params] :as mutation}]
(cond-> mutation
(and mutate params)
(assoc
::pc/mutate
(fn [env p]
(mutate env (select-keys p params))))))
(pc/defmutation add-artifact [env artifact]
{::pc/sym `r9b.threat-intelligence.artifact/add-artifact
::pc/params [::note ::hash/sha-256]
::pc/output [:artifact/note]
::pc/transform filter-declared-params-transform}
...)
then, if you wanna use it a lot, you can create your own defmutation that always adds it, or, considering that mutations are just maps, you can do some pre-processing on them before adding to the index (or maybe change the index after its ready, the mutation code fn also lives there)