Fork me on GitHub
#clojure-spec
<
2018-04-19
>
xiongtx19:04:38

Is there an easy way to modify an existing s/keys spec? I often find myself needing to take an existing spec and update a few keys. It’d be nice if I could just replace a key instead of copying everything.

seancorfield19:04:31

Maybe s/merge would work for you @xiongtx? I'm not quite sure how it handles merging over existing keys tho'

xiongtx19:04:00

I managed to get around it by redefining the specs that differ

kenny23:04:24

Is it possible to instrument initial function calls? i.e. I have my dev namespace where I enable instrumentation:

(ns dev.user
  (:require
    [clojure.spec.test.alpha :as st]
    [my-project.util]))

(st/instrument)
But by the time I load my dev.user namespace, I have already ran some functions:
(ns my-project.util
  (:require
    [clojure.spec.alpha :as s]))

(defn reg-event
  [id]
  ;; do side effecting stuff
  nil)

(s/fdef reg-event
        :args (s/cat :id keyword?)
        :ret nil?)

(reg-event "my-event")
The call to reg-event is not instrumented at this point so I do not get a instrumentation error that my call to reg-event is incorrect.

dadair01:04:24

You could just (st/instrument reg-event) after it’s fdef?

kenny03:04:39

True but that doesn't scale well and requires special considerations in production.