This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-16
Channels
- # atlanta-clojurians (8)
- # beginners (103)
- # boot (22)
- # boot-dev (1)
- # cider (36)
- # cljs-dev (55)
- # cljsrn (3)
- # clojars (25)
- # clojure (104)
- # clojure-brasil (1)
- # clojure-dusseldorf (2)
- # clojure-italy (8)
- # clojure-norway (9)
- # clojure-russia (15)
- # clojure-spec (6)
- # clojure-uk (26)
- # clojurescript (246)
- # cursive (26)
- # data-science (1)
- # datomic (22)
- # dirac (11)
- # editors (1)
- # emacs (8)
- # fulcro (50)
- # graphql (11)
- # hoplon (1)
- # jobs-discuss (27)
- # leiningen (44)
- # luminus (33)
- # lumo (2)
- # mount (1)
- # off-topic (8)
- # onyx (5)
- # parinfer (4)
- # reagent (94)
- # ring-swagger (14)
- # shadow-cljs (37)
- # spacemacs (10)
- # specter (3)
- # tools-deps (4)
- # unrepl (14)
- # yada (5)
Toyed more with spec coercion, with idea that coercion functions could be defined in spec meta-data so that the specs could remain self-contained . Currently requires spec-tools to work.
(require '[spec-tools.core :as st])
(require '[spec-tools.conform :as conform])
(def spec
(st/spec
{:spec string?
:description "a string spec"
::conform/json #(str %2 "-json")
::conform/string #(str %2 "-string")}))
(st/conform spec "kikka")
; "kikka"
(st/conform spec "kikka" st/json-conforming)
; "kikka-json"
(st/conform spec "kikka" st/string-conforming)
; "kikka-string"
Anyone know why my function doesnt-work
throws a java.lang.AssertionError
:
(s/def ::bar (fn [x] true))
(defn return-true [_] true)
(defn doesnt-work [something & bar]
{:pre [(s/assert ::bar bar)]}
true)
(defn works [something & bar]
{:pre [(return-true bar)]}
true)
(deftest failing-test
(is (works 1))
(is (thrown? AssertionError (doesnt-work 1))))
This didn't seems spec-specific at first but this test shows I'm probably misunderstanding something about s/def