https://github.com/stch-library/schema.git
git clone 'https://github.com/stch-library/schema.git'
(ql:quickload :stch-library.schema)
Forked from https://github.com/Prismatic/schema
I have my own set of unit-tests, around 120. Code coverage is pretty decent, though, not as exhaustive as Prismatic Schema.
Many thanks to Prismatic for sharing this awesome library. It really is game changing in my opinion. Please feel free to incorporate any changes into Prismatic Schema. I will add significant changes from Prismatic Schema into this code base as they occur. Most notably would be support for:
(defn' create-user
[user-id :- Int & {:keys [name email]} :- {:name String :email String}])
This code will be used in production, but currently is not.
Feedback is welcome. New features should be directed to Prismatic Schema.
Add the following to your project dependencies:
[stch-library/schema "0.3.3"]
http://stch-library.github.io/schema
(use 'stch.schema)
Functions ```clojure (defn' rest-args :- (Vector String) [name :- String, age :- Int & likes :- [String]] (vec likes))
(defn' multi-arity :- String ([url :- String] (multi-arity url true)) ([url :- String follow-redirects? :- Boolean] url))
(defn' higher-order :- (Fn Int [Int]) [f :- (Fn Int [Int])] f)
(defn' any-fn :- (Fn) [f :- (Fn)] f)
(validate (Fn Int [Int]) inc) (validate (Fn String [Map]) :name) ```
Records
clojure
(defrecord' Employee
[hired :- Date
position :- Keyword
roles :- [String]])
Built-in types ```clojure (validate String “Billy”) (validate Boolean true) (validate Symbol 'a) (validate Date #inst “2014-02-06”) (validate Atom (atom [1 2 3]))
(validate Set #{“Billy” :Bobby})
(validate Map {}) (validate Map {:name “Billy”})
(validate (Vector String) [“hi” “hello”]) (validate (Vector) [“Bob” :Billy])
(validate (List String) ‘(“hi” “hello”)) (validate (List) ’(“Bob” :Billy))
(validate Named 'Billy) (validate Named “Billy”) (validate Named :Billy)
(validate (Option String) “Billy”) (validate (Option String) nil) ```
Sequences
clojure
(validate [(One Int) Double] [1234 95.6])
(validate [(Optional Int) (Optional String)] [])
(validate [(Pair String Int)] [["David" 35]["Billy" 37]])
Predicates
clojure
(def Set (Predicate set?))
Union and Intersection
clojure
(def Named (U String Symbol Keyword))
(defn List [x] (I (Predicate list?) [x]))
Run “lein spec”