This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-08-21
Channels
- # admin-announcements (80)
- # beginners (19)
- # boot (11)
- # cider (27)
- # clojure (55)
- # clojure-berlin (2)
- # clojure-italy (9)
- # clojure-korea (3)
- # clojure-russia (3)
- # clojure-sg (5)
- # clojurescript (70)
- # cursive (9)
- # datascript (5)
- # datomic (7)
- # editors (2)
- # emacs (4)
- # jobs (11)
- # ldnclj (7)
- # off-topic (17)
- # om (6)
- # reagent (63)
- # spacemacs (8)
- # testing (2)
I feel like I must be missing something here, using Prismatic Schema:
(require '[schema.core :as s])
;==> nil
(def A-or-B (s/enum "A" "B"))
;==> #'bike-messenger.schema/A-or-B
(s/defn f [ab :- A-or-B] ab)
;=> nil
(f "C")
;=> "C"
(f :a)
;=> :a
Does this make any sense? I feel like there's something very simple that I'm missing... I've used schema like 50 times!
Any ides about where to start debugging this? Digging into the library at the moment
@escherize: Hm, I get the expected exception when trying this
Yeah - It's pretty interesting. I'm on [prismatic/schema "0.4.4"]
now, and still getting
(require '[schema.core :as s])
(s/validate s/Int "aok")
;=> "aok"
schema.core> (set-fn-validation! false)
false
schema.core> (validate Int "a")
"a"
schema.core> (set-fn-validation! true)
true
schema.core> (validate Int "a")
"a"
I'm gonna rest my brain for a little while...
schema.core> ((fn [i :- Int] i) "ok")
"ok"
$> (s/validate s/Int "this is not an int, why god?")
"this is not an int, why god?"
$> (clojure.repl/source s/Int)
(def Int
"Any integral number"
(pred integer? 'integer?))
nil
$> (clojure.repl/source s/validate)
(clojure.core/defn validate
"Throw an exception if value does not satisfy schema; otherwise, return value."
[schema value]
(when-let [error (check schema value)]
(macros/error! (utils/format* "Value does not match schema: %s" (pr-str error))
{:schema schema :value value :error error}))
value)
nil