improvement
This commit is contained in:
parent
1fe367dfea
commit
5b4acf917a
1 changed files with 10 additions and 5 deletions
|
|
@ -689,6 +689,14 @@
|
||||||
([f] `(clojure.spec.alpha/spec-impl '(conformer ~(res f)) ~f nil true))
|
([f] `(clojure.spec.alpha/spec-impl '(conformer ~(res f)) ~f nil true))
|
||||||
([f unf] `(clojure.spec.alpha/spec-impl '(conformer ~(res f) ~(res unf)) ~f nil true ~unf)))
|
([f unf] `(clojure.spec.alpha/spec-impl '(conformer ~(res f) ~(res unf)) ~f nil true ~unf)))
|
||||||
|
|
||||||
|
(defmacro internal-conformer
|
||||||
|
"takes a predicate function with the semantics of conform i.e. it should return either a
|
||||||
|
(possibly converted) value or :clojure.spec.alpha/invalid, and returns a
|
||||||
|
spec that uses it as a predicate/conformer. Optionally takes a
|
||||||
|
second fn that does unform of result of first"
|
||||||
|
([f] `(babashka.impl.clojure.spec.alpha/spec-impl '(conformer ~(res f)) ~f nil true))
|
||||||
|
([f unf] `(babashka.impl.clojure.spec.alpha/spec-impl '(conformer ~(res f) ~(res unf)) ~f nil true ~unf)))
|
||||||
|
|
||||||
(defmacro fspec
|
(defmacro fspec
|
||||||
"takes :args :ret and (optional) :fn kwargs whose values are preds
|
"takes :args :ret and (optional) :fn kwargs whose values are preds
|
||||||
and returns a spec whose conform/explain take a fn and validates it
|
and returns a spec whose conform/explain take a fn and validates it
|
||||||
|
|
@ -944,10 +952,7 @@
|
||||||
(specize* [s _] s)
|
(specize* [s _] s)
|
||||||
|
|
||||||
Spec
|
Spec
|
||||||
(conform* [_ x] (let [;; _ (prn :pred pred :descr (describe pred) :x x)
|
(conform* [_ x] (let [ret (pred x)]
|
||||||
ret (pred x)
|
|
||||||
;; _ (prn :ret ret)
|
|
||||||
]
|
|
||||||
(if cpred?
|
(if cpred?
|
||||||
ret
|
ret
|
||||||
(if ret x :clojure.spec.alpha/invalid))))
|
(if ret x :clojure.spec.alpha/invalid))))
|
||||||
|
|
@ -1815,7 +1820,7 @@
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; non-primitives ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; non-primitives ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
(internal-def
|
(internal-def
|
||||||
:clojure.spec.alpha/kvs->map
|
:clojure.spec.alpha/kvs->map
|
||||||
(conformer #(zipmap (map :clojure.spec.alpha/k %) (map :clojure.spec.alpha/v %)) #(map (fn [[k v]] {:clojure.spec.alpha/k k :clojure.spec.alpha/v v}) %)))
|
(internal-conformer #(zipmap (map :clojure.spec.alpha/k %) (map :clojure.spec.alpha/v %)) #(map (fn [[k v]] {:clojure.spec.alpha/k k :clojure.spec.alpha/v v}) %)))
|
||||||
|
|
||||||
(defmacro keys*
|
(defmacro keys*
|
||||||
"takes the same arguments as spec/keys and returns a regex op that matches sequences of key/values,
|
"takes the same arguments as spec/keys and returns a regex op that matches sequences of key/values,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue