使用clojure.spec绘制地图

时间:2019-04-15 04:48:07

标签: clojure clojure.spec

我有以下地图:

(def gigs {:gig-01 {:id :gig-01
                    :title "Macaron"
                    :artist "Baher Khairy"
                    :desc "Sweet meringue-based rhythms with smooth and sweet injections of soul"
                    :img "https://res.cloudinary.com/schae/image/upload/f_auto,q_auto/v1519552695/giggin/baher-khairy-97645.jpg"
                    :price 1000
                    :sold-out false}
           :gig-02 {:id :gig-02
                    :title "Stairs"
                    :artist "Brentr De Ranter"
                    :desc "Stairs to the highets peaks of music."
                    :img "https://res.cloudinary.com/schae/image/upload/f_auto,q_auto/v1519552695/giggin/brent-de-ranter-426248.jpg"
                    :price 2000
                    :sold-out false}})

我想为此创建一个规范,但不确定如何定义密钥,例如“:gig-01”有指针吗?

1 个答案:

答案 0 :(得分:1)

您可以尝试:

(s/def ::gig-id
   (s/and keyword?
          (fn [x] (->> x name (re-matches #"gig-\d+")))))