2 ms·
Spec is supremely flexible, it isn't hard to enforce a map having a specific set of keys even without explicit support. (ns user (:use clojure.set) (
by roenxi 7y ago
Spec is supremely flexible, it isn't hard to enforce a map having a specific set of keys even without explicit support.
(ns user
(:use clojure.set)
(:require [clojure.spec.alpha :as s]))
(s/def ::map-closed #(-> %
keys
set
(difference #{:a :b :c})
empty?))
(s/valid? ::map-closed {:a 1, :c 2})
=> true
(s/valid? ::map-closed {:a 1, :c 2, :e 3})
=> false