This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> clj -Sdeps '{:deps {org.clojure/clojure {:mvn/version "1.10.0-alpha8"}}}' | |
Clojure 1.10.0-alpha8 | |
user=> (require '[clojure.spec.alpha :as s]) | |
nil | |
user=> ;; `explain-data` returns a description of the problem, including the `:in` path | |
user=> ;; which is the location of the invalid data within the context of the larger | |
user=> ;; data structure | |
user=> (-> (s/explain-data (s/coll-of int?) [1 "2"]) ::s/problems first) | |
{:path [], :pred int?, :val "2", :via [], :in [1]} | |
user=> (-> (s/explain-data (s/coll-of int?) [1 "2"]) ::s/problems first :in) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ ~ rlwrap clj -Srepro -Sdeps '{:deps {org.clojure/spec.alpha {:mvn/version "0.2.176"}}}' | |
Clojure 1.9.0 | |
user=> (require '[clojure.spec.alpha :as s]) | |
nil | |
user=> (s/def ::point1 (s/cat :x int? :y int?)) | |
user/point1 | |
user=> (s/def ::x int?) | |
:user/x | |
user=> (s/def ::y int?) | |
:user/y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Code is largely copied from | |
;; https://github.com/wilkerlucio/spec-coerce/blob/master/src/spec_coerce/core.cljc | |
;; with minor modifications! | |
(ns example.coercion | |
(:require [clojure.walk :as walk] | |
[clojure.spec.alpha :as s])) | |
(defonce ^:private registry-ref (atom {})) | |
;; WARNING - only works if all unqualified kw are unique!!!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Clojure 1.9.0 | |
user=> (require '[clojure.spec.alpha :as s]) | |
nil | |
user=> (require '[expound.alpha :as expound]) | |
nil | |
user=> (set! s/*explain-out* (expound/custom-printer {:theme :figwheel-theme :print-specs? false})) | |
#object[expound.alpha$custom_printer$fn__897 0x534243e4 "expound.alpha$custom_printer$fn__897@534243e4"] | |
user=> (s/check-asserts true) | |
true | |
user=> (defrecord Person [first-name last-name]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.spec.alpha :as s]) | |
(set! s/*explain-out* (fn [ed] (println "failed"))) | |
(let [x] 1) | |
;; with org.clojure/spec.alpha {:mvn/version "0.2.168"} : | |
;; CompilerException clojure.lang.ExceptionInfo: Call to clojure.core/let did not conform to spec: | |
;; failed | |
;; #:clojure.spec.alpha{:problems [{:path [:args :bindings :init-expr], :reason "Insufficient input", :pred clojure.core/any?, :val (), :via [:clojure.core.specs.alpha/bindings :clojure.core.specs.alpha/bindings], :in [0]}], :spec #object[clojure.spec.alpha$regex_spec_impl$reify__2499 0x749c877b "clojure.spec.alpha$regex_spec_impl$reify__2499@749c877b"], :value ([x] 1), :args ([x] 1)}, compiling:(NO_SOURCE_PATH:3:1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.spec.gen.alpha :as sgen]) | |
;; original | |
(defn multimethod-selector | |
"Returns a generator that picks one dispatch value from the known | |
dispatch values of a multimethod. Defers the lookup of dispatch | |
values until sampling time, so any defmethods evaluated after the | |
generator is created may still be selected." | |
[s] | |
#(sgen/bind |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.test.check.generators :as gen2]) | |
(require '[clojure.spec.alpha :as s]) | |
(s/def :aero/path (s/coll-of simple-keyword? :kind vector? :min-count 1 :max-count 3)) | |
(defn aero-map [paths vals-or-refs backups] | |
(->> (map vector paths vals-or-refs backups) | |
(reduce | |
(fn [m [p [t v] [_ backup-v]]] | |
(case t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> clj -Sdeps '{:deps {expound {:mvn/version "0.7.1"}}}' | |
Clojure 1.9.0 | |
user=> (require '[expound.alpha :as expound] '[clojure.spec.alpha :as s]) | |
nil | |
user=> ;; default printer is used | |
user=> (future (s/explain int? "a")) | |
val: "a" fails predicate: :clojure.spec.alpha/unknown | |
#object[clojure.core$future_call$reify__8097 0x99a65d3 {:status :ready, :val nil}] | |
user=> (set! s/*explain-out* expound/printer) | |
#object[expound.alpha$printer 0x4ad4936c "expound.alpha$printer@4ad4936c"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "c6b0b7cb0a30e2edbf7050c0119ef038cf0f0ac2"}}}' -m friendly | |
user=> (let [:x 5] x) | |
Call to clojure.core/let did not conform to spec: | |
-- Spec failed -------------------- | |
([:x 5] x) | |
^^ | |
should satisfy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> (require '[expound.alpha :as expound] | |
'[clojure.spec.alpha :as s]) | |
nil | |
user=> (set! s/*explain-out* (expound/custom-printer {:print-specs? false :show-valid-values? true})) | |
#object[expound.alpha$custom_printer$fn__895 0x38b972d7 "expound.alpha$custom_printer$fn__895@38b972d7"] | |
user=> (let [{:keys 4} foo] x) | |
CompilerException clojure.lang.ExceptionInfo: Call to clojure.core/let did not conform to spec: | |
-- Spec failed -------------------- | |
([{:keys 4} foo] x) |