-
Notifications
You must be signed in to change notification settings - Fork 1
/
specs.cljc
31 lines (26 loc) · 1.12 KB
/
specs.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(ns defntly.specs
(:require [clojure.spec.alpha :as s]
[clojure.core.specs.alpha :as specs]))
;; There is a problem with this defn-args spec: unform and conform are not fully inlined (unform returns lists instead of vectors).
;; The cool thing is that we can monkey patch :defn-args so that unform and conform are fully inlined.
(s/def ::specs/binding-form
(s/or :local-symbol ::specs/local-name
:seq-destructure ::specs/seq-binding-form
:map-destructure ::specs/map-binding-form))
(s/def ::specs/seq-binding-form
(s/and vector?
(s/conformer identity vec)
(s/cat :elems (s/* ::specs/binding-form)
:rest (s/? (s/cat :amp #{'&} :form ::specs/binding-form))
:as (s/? (s/cat :as #{:as} :sym ::specs/local-name)))))
(defn arg-list-unformer [a]
(vec
(if (and (coll? (last a)) (= '& (first (last a))))
(concat (drop-last a) (last a))
a)))
(s/def ::specs/param-list
(s/and
vector?
(s/conformer identity arg-list-unformer)
(s/cat :args (s/* ::specs/binding-form)
:varargs (s/? (s/cat :amp #{'&} :form ::specs/binding-form)))))