Idiomatic clojure map lookup by keyword

后端 未结 4 883
忘了有多久
忘了有多久 2020-11-29 08:09

Say I have a clojure map that uses keywords as its keys:

(def my-car {:color \"candy-apple red\" :horsepower 450})

I know that I can look u

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 08:39

    From the library coding standards:

    • Use keyword-first syntax to access properties on objects:

      (:property object-like-map)
      
    • Use collection-first syntax to extract values from a collection (or use get if the collection might be nil).

      (collection-like-map key)
      (get collection-like-map key)
      

提交回复
热议问题