Reputation: 71
Please someone who worked with ref and vector could help-me ?
This vector in each line there is a (ref {:desc "text" :amount double})
:
[#<Ref@1cda773e: {:desc "DESC1", :amount 100}
#<Ref@468dd81: {:desc "DESC2", :amount 200}
#<Ref@1e95e716: {:desc "DESC3",:amount -50}>]
Is it possible take all amounts above and put it in a new vector like this : [100, 200, -50]
.
Working with refs is quite difficult and I don't know to to access them.
Upvotes: 1
Views: 110
Reputation: 6088
Here's one way to do it:
user=> (def data [{:desc "DESC1", :amount 100} {:desc "DESC2", :amount 200} {:desc "DESC3",:amount -50}])
#'user/data
user=> (def my-refs (map #(ref %) data))
#'user/my-refs
user=> (vec (map #(-> % deref :amount) my-refs))
[100 200 -50]
Upvotes: 1