This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-06
Channels
- # announcements (2)
- # beginners (110)
- # calva (4)
- # cider (2)
- # cljs-dev (3)
- # cljsrn (1)
- # clojure (83)
- # clojure-dev (56)
- # clojure-italy (2)
- # clojure-nl (6)
- # clojure-uk (19)
- # clojurescript (14)
- # core-async (1)
- # cursive (6)
- # datomic (1)
- # defnpodcast (1)
- # figwheel (1)
- # figwheel-main (87)
- # fulcro (7)
- # graphql (1)
- # luminus (3)
- # off-topic (5)
- # pedestal (6)
- # re-frame (1)
- # reagent (3)
- # shadow-cljs (22)
- # spacemacs (1)
- # specter (12)
I am trying to set values at different indexes within a flat vector in once call, e.g. [0 0 0 0] => [0 1 0 3]. I tried
(setval [(nthpath 1)(nthpath 3)] [1 3] [0 0 0 0])
but got a runtime exc….What should I use instead?
Thanks in advance..
@kingcode there's two approaches:
(setval (subselect (multi-path 1 3)) [1 3] [0 0 0 0])
or
(multi-transform
(multi-path
[1 (terminal-val 1)]
[3 (terminal-val 3)])
[0 0 0 0])
Hi Nathan, if I have a vector of vectors with index & new-values,or a vector of maps with index & new-value pairs, then how do I rewrite the above. please advise.. thank you
do you have an example input/output of what you're trying to do?
I am thinking of this data
input vec: [:a :b :c ... :m ... :z]
A map of indices and new values
{
2 :c2
12 :m2
25 :z2
}
Or a map of old value new value pairs
{
:c :c2
:m :m2
:z :z2
}
output vec: [:a :b :c2 ... :m2 ... :z2]
Essentially how to deal with the scenario when I have a lot of values to be replaced and not just a handful of indices that can be hardcoded in the multipath selector expression..
for the latter you can do (transform [ALL #(contains? replacements %)] replacements data)
for the first I would just do that with a reduce
Noted thank you
the second is more efficient
Thank you @nathanmarz!
do you have an example input/output of what you're trying to do?