Mr. Robot
Mr. Robot

Reputation: 1824

Ways of accessing nested map values in Clojure?

I am currently using the two following blocks of code to access nested values in ClojureScript:

  (def response (re-frame/subscribe [::subs/quote]))
  (def body (:body @response))
  (def value (:value body))
  (println value)
  (def result (-> @(re-frame/subscribe [::subs/quote]) :body :value))
  (println result)
 (def lol (get-in @(re-frame/subscribe [::subs/quote]) [:body :value]))
 (println lol)

Are there any better / more succinct ways of doing this?

Upvotes: 1

Views: 182

Answers (1)

Oluwafemi Sule
Oluwafemi Sule

Reputation: 38922

Keys can be used as operators to retrieve its value like so:

(def lol (:value (:body @(re-frame/subscribe [::subs/quote]))))
(println lol)

However, I prefer the verbose way using a function as get-in

Upvotes: 2

Related Questions