This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-24
Channels
- # admin-announcements (2)
- # beginners (46)
- # boot (8)
- # cider (29)
- # cljs-dev (45)
- # cljsjs (10)
- # cljsrn (13)
- # clojure (60)
- # clojure-dev (5)
- # clojure-greece (1)
- # clojure-ireland (4)
- # clojure-mexico (6)
- # clojure-poland (3)
- # clojure-quebec (3)
- # clojure-russia (8)
- # clojure-spec (89)
- # clojure-uk (70)
- # clojurescript (84)
- # cursive (4)
- # datomic (7)
- # devcards (1)
- # dirac (2)
- # emacs (11)
- # hispano (10)
- # jobs (13)
- # keechma (34)
- # lein-figwheel (4)
- # luminus (19)
- # off-topic (2)
- # om (78)
- # onyx (6)
- # parinfer (1)
- # planck (82)
- # proton (2)
- # re-frame (10)
- # reagent (23)
- # ring-swagger (5)
- # spacemacs (2)
- # specter (24)
- # spirituality-ethics (122)
- # untangled (13)
If want to use specter to replace the nth value in deeply nested array, is there a better way to navigate to that value than using (srange x (inc x))
Ideally I’d like to be able to transform the value there, or put in default if it doesn’t exist
@conaw: there's a custom nth-elt
navigator in the wiki at https://github.com/nathanmarz/specter/wiki/List-of-Macros#defnav
I don't know of a better way to do it, personally
under the hood it does basically what you said
if you want default element behavior, you could modify it to do that
@conaw by array do you mean vector? if so, I believe (keypath 3)
works
ok, here’s a question, it seems that I can substitute a value into a vector using setval , but if I want to use sp/END i have to have it wrapped in a seqable, so couldn’t insert it in in a flat way, is there a way I might get around that
(setval [(sp/if-path (sp/must 3) (sp/keypath 3) sp/END)] :newd [:a :b :c :dd])
=> [:a :b :c :newd]
(setval [(sp/if-path (sp/must 3) (sp/keypath 3) sp/END)] [:newd] [:a :b :c])
=> [:a :b :c :newd]
basically, in assoc, if I assoc to the size of a vector, I conj onto the end, I’m looking for a similar behavior here
@conaw: I think you can do [END (keypath 0)]
@codonnell: sorry for disappearing last night, I ran the benchmark with (sequence (comp ...) %)
substituted for (->> % ...)
and it actually came out faster, 97ms vs 110 ms
Does (comp ...)
take some time to initially build up the transducer?
@aengelberg: yes, most noticeable when operating on relatively little data
@aengelberg: the benchmarks I pasted before show a large performance difference between "precompiling" the transducer and doing it inline