This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-12
Channels
- # aleph (10)
- # beginners (79)
- # boot (81)
- # chestnut (3)
- # cider (9)
- # cljs-dev (336)
- # cljsrn (17)
- # clojure (121)
- # clojure-boston (1)
- # clojure-italy (4)
- # clojure-nl (1)
- # clojure-russia (218)
- # clojure-spec (32)
- # clojure-uk (98)
- # clojurescript (109)
- # cloverage (1)
- # core-async (5)
- # cursive (17)
- # datascript (15)
- # datomic (38)
- # editors (4)
- # emacs (6)
- # graphql (1)
- # hoplon (140)
- # instaparse (1)
- # jobs (2)
- # klipse (1)
- # leiningen (4)
- # lumo (2)
- # mount (103)
- # off-topic (3)
- # om (8)
- # onyx (19)
- # parinfer (32)
- # pedestal (3)
- # precept (32)
- # re-frame (33)
- # reagent (24)
- # remote-jobs (11)
- # rum (1)
- # spacemacs (1)
- # specter (37)
- # unrepl (4)
- # untangled (43)
- # vim (11)
@schmee looks fine to me:
(transform MAP-VALS persistent! {1 (transient []) 2 (transient [1 2 3])})
;; => {1 [], 2 [1 2 3]}
there must be another issue with your code
Two questions:
1. is it possible to return a “subpath” of a path from transform
? e.g. transform [(submap [:a :c]) MAP-VALS] inc {:a 1 :b 2 :c 3}
returns {:a 2 :b 2 :c 4}
, can you modify the path somehow to make it return {:a 2 :c 4}
?
2. can you “invert” a path? e.g. to make (some-invert-fn (submap [:a :c]))
navigate to the map without :a
and :c
@schmee you can do (view #(select-keys % [:a :c]))
for #2, that would need to be another navigator
no, it just takes a function
yes, that's right
forgot about that
user=> (s/transform [(s/transformed (s/submap [:a :c]) identity) s/MAP-VALS] inc {:a 1 :b 2 :c 3})
{:a 2 :b 3 :c 4}
no, that doesn't remove :b
(transformed (submap [:a :c]) identity)
is a no-op
(transformed (submap [:a :c]) (fn [_] nil))
would remove :a and :c
no problem, happy to help
While toying around I stumbled over something strange. When using select a MapEntry is handled as MapEntry while when using transform is a Vector. So (select [ALL (pred key)] {:a 1})
=> [[:a 1]]
while (transform [ALL (pred key)] identity {:a 1})
throws a ClassCastException
I know this path is not useful, but I'm just curious if this is "working as intended" as select and transform differs
@drowsy that's a good observation
it's because select
does a reduce
over the map, while transform
accesses the keys/vals using direct means
while it would be nice to be consistent, it's not really important
(since there would be a slight performance penalty to do a conversion somewhere)
@nathanmarz thanks for the explanation, I agree, it's not important. Are there more things where select and transform differs? maybe those can be documented somewhere?
not that i can think of
ALL on maps is a weird case
a good thing to add to https://github.com/nathanmarz/specter/issues/56