This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-02
Channels
- # admin-announcements (1)
- # aws-lambda (9)
- # beginners (161)
- # boot (1)
- # cider (3)
- # cljsrn (36)
- # clojure (245)
- # clojure-austin (2)
- # clojure-denmark (3)
- # clojure-dev (11)
- # clojure-greece (6)
- # clojure-italy (25)
- # clojure-russia (5)
- # clojure-serbia (1)
- # clojure-spec (76)
- # clojure-uk (78)
- # clojurescript (168)
- # clojurex (4)
- # community-development (7)
- # core-async (11)
- # core-logic (5)
- # css (6)
- # cursive (8)
- # data-science (6)
- # datomic (5)
- # devops (4)
- # duct (17)
- # emacs (1)
- # figwheel (8)
- # fulcro (51)
- # hoplon (4)
- # instaparse (3)
- # kekkonen (6)
- # klipse (3)
- # lein-figwheel (9)
- # luminus (2)
- # lumo (3)
- # midje (4)
- # off-topic (11)
- # om (4)
- # onyx (62)
- # other-languages (60)
- # re-frame (21)
- # reagent (63)
- # rum (1)
- # shadow-cljs (22)
- # spacemacs (22)
- # specter (23)
- # test-check (2)
- # vim (2)
- # yada (6)
Hmm, why does this print tuples instead of single values?
(setval
[ALL
#_(multi-path :target/source )
:target/neighbours ALL first (fn [v]
(println “is this the first?” v)
v)
(pred #{“medline”})]
NONE
[{:target/source “not” :target/neighbours [[“medline” 1] [“not 2”]]}
{:target/source “medline” :target/neighbours [[“medline” 1] [“not 2"]]}
{:target/source “medline” :target/neighbours [[“medline” 1] [“not 2”]]}
])
ALL
(every map value), :target/neighbours
(vector of tuples), ALL
(every tuple), first
… oh I see
I have trouble writing this in specter:
;; only x and y are allowed
[{:name "x" :rels ["x" "y"]} ;=> fine, keep as is
{:name "y" :rels ["x" "y" "z"]} ;=> keep only allowed rels: {:name "y" :rels ["x" "y"]}
{:name "y" :rels ["z"]} ;=> no allowed rels, remove map completely
{:name "z" :rels ["x" "y"]}] ;=> disallowed name, remove completely
;;=>
[{:name "x" :rels ["x" "y"]}
{:name "y" :rels ["x" "y"]}]
as a single setval
using multi-path
and not-selected?
. I know it must be possible…(setval [ALL
(transformed [:rels ALL (pred (complement #{"x" "y"}))] (fn [_] NONE))
(selected?
(multi-path
(not-selected? :name #{"x" "y"})
(not-selected? :rels ALL #{"x" "y"})))
]
NONE
data)
you can also do
(setval [ALL
(transformed [:rels ALL (pred (complement #{"x" "y"}))] (fn [_] NONE))
(selected?
(multi-path
(not-selected? :name #{"x" "y"})
[:rels empty?]))
]
NONE
data)
@borkdude looking at it again you don't need the transformed
:
(setval [ALL
(multi-path
[:rels ALL (pred (complement #{"x" "y"}))]
(selected?
(multi-path
(not-selected? :name #{"x" "y"})
[:rels empty?])))]
NONE
data)
transformed
has same semantics as view
, useful when doing multiple distinct transforms in one traversal
or for manipulating the results of a select
in one go
@nathanmarz Does this make sense? I mean the pred
thing in the let
. I’m not really sure when to wrap a function in pred
.
(defn keep-allowed-relations [user-profile relations]
(let [disallowed? (pred #(not (allowed-source? user-profile %)))]
(setval
[ALL
(multi-path
[:target/neighbours ALL
(selected? FIRST
disallowed?)]
(selected?
(multi-path
[:target/neighbours empty?]
(selected? :target/source disallowed?)
)))]
NONE
relations)))
little simplification:
(setval
[ALL
(multi-path
[:target/neighbours ALL
(selected? FIRST
disallowed?)]
(selected?
(multi-path
[:target/neighbours empty?]
[:target/source disallowed?]
)))]
NONE
relations)))
@borkdude that's fine though it will be slightly more efficient to use pred
in the path declaration rather than outside it
that way specter knows statically it's a compiled navigator and doesn't have to do an instance?
check at runtime
but that's not a big deal
wrapping with pred
in the let
is much better than not, in which case specter would have to do a protocol invocation to convert function -> navigator every time that callsite is invoked